Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent NPE when deleting OpenTracing baggage #7637

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -641,14 +641,18 @@ public long getEndToEndStartTime() {
}

public void setBaggageItem(final String key, final String value) {
if (baggageItems == EMPTY_BAGGAGE) {
synchronized (this) {
if (baggageItems == EMPTY_BAGGAGE) {
baggageItems = new ConcurrentHashMap<>(4);
if (value == null) {
baggageItems.remove(key);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we protect the call when the baggageItems has not yet been initialized (in that case this will throw an unsupported operation exception)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be unexpected. An outside actor is not aware if something is initialized or not.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you can then just check if the baggageItems != EMPTY_BAGGAGE before calling remove

Many thanks for the contribution 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EMPTY_BAGGAGE is just an empty map, so .remove is a noop.
Would that make a difference ?

} else {
if (baggageItems == EMPTY_BAGGAGE) {
synchronized (this) {
if (baggageItems == EMPTY_BAGGAGE) {
baggageItems = new ConcurrentHashMap<>(4);
}
}
}
baggageItems.put(key, value);
}
baggageItems.put(key, value);
}

public String getBaggageItem(final String key) {
Expand Down