prevent NPE when capturing headers#1842
Conversation
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
Trends 🧪💚 Flaky test reportTests succeeded. Expand to view the summary
Test stats 🧪
|
eyalkoren
left a comment
There was a problem hiding this comment.
Do we have any usage of null header names or keys in practice ? While the underlying maps may allow for null values, I think that it would not make any sense to try capturing those.
This code path is adding headers to span context by iterating over actual existing record headers, so I assume we should capture them as is in order to reflect metadata about the record.
null keys are not allowed in the docs, so we can guard from null even though such are not expected (because they come from the sent record, so they already passed this screening).
null values are allowed, so if the user uses them, they may have a meaning, in which case it worth reporting those.
I think the easier fix is to add "null" to the value buffer in BinaryHeaderMap#add() if the value is null.
BTW, in NoRandomAccessMap#add() (the text header map counterpart), null values are allowed and are added to the map, however they are omitted during serialization. Either way we decide, the behavior or text header and binary headers should be aligned.
|
Good point, here is my revised proposal:
|
|
The reason I suggested to serialize to |
|
Both the HTTP and message headers allow for |
|
|
||
| /** | ||
| * Values lengths, key index is provided with {@link #keys}. | ||
| * Negative length indicate a {@literal null} entry |
| if (value == null) { | ||
| int size = keys.size(); | ||
| keys.add(key); | ||
| valueLengths[size] = -1; |
There was a problem hiding this comment.
Make sure to enlargeValueLengths() if required to avoid ArrayIndexOutOfBoundsException.
Better yet, extract this code into a method to be reused with the same done below, something like:
int size = keys.size();
keys.add(key);
if (size == valueLengths.length) {
enlargeValueLengths();
}
valueLengths[size] = length;
There was a problem hiding this comment.
now properly fixed & tested.
What does this PR do?
Fixes #1840
Checklist
For reviewer:
nullheader names or keys in practice ? While the underlying maps may allow fornullvalues, I think that it would not make any sense to try capturing those.