-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Disallowing null values in ContextSnapshot #102
Conversation
A bit more context from offline conversations. When capturing Therefore chances are that a Note that we also have static methods on So all this PR does is to provide a consistent treatment of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, good changes!
- I would like to see a Javadoc updates that settles this topic more formally in writing now that we've looked at it in more detail and made concrete decisions. Starting with
ContextSnapshot
, clarify that a snapshot should not containnull
values since those are not useful for settingThreadLocal
values anyway, and that all implementations should ensure thatnull
values are ignored, and never passed intoContextAccessor
orThreadLocalAccessor
. Similar updates could be made inContextAccessor
, e.g. onreadValues
to explain that anynull
values put into theMap
will be filtered out, and likewise onsetValues
to clarify the sourceMap
will never havenull
values. Make similar updates inThreadLocalAccessor
too in thesetValue
andrestore(String)
methods. - Around this line I think it would be more clear to get the value and either check and/or assert that it is not
null
. Otherwise, ifnull
finds its way in somehow (bug?), it goes into thesetValue
method ofTLA
where it may or may not be handled well. In short, we should assert our assumption that there is nonull
value.
context-propagation/src/test/java/io/micrometer/context/DefaultContextSnapshotTests.java
Outdated
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/ThreadLocalAccessor.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the updates. Looks good, just one minor Javadoc update below.
context-propagation/src/main/java/io/micrometer/context/ContextSnapshot.java
Outdated
Show resolved
Hide resolved
…tSnapshot.java Co-authored-by: Rossen Stoyanchev <rstoyanchev@users.noreply.github.com>
@rstoyanchev thank you for the comprehensive review! |
This change takes care of guaranteeing
@NonNullApi
package annotation is in effect forThreadLocalAccessor
calls when dealing withContextSnapshot
. When a source contextObject
providednull
for a key, the API would not have held its guarantees. Now we explicitly make sure the backingMap
has no mappings tonull
.