Fix NPE on serialization with no span type (#1207)

Fix NPE on serialization with no span type
This commit is contained in:
Tyler Benson 2020-02-10 09:10:02 -08:00 committed by GitHub
commit f2d8c8e6b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 15 deletions

View File

@ -32,7 +32,11 @@ public class MsgpackFormatWriter extends FormatWriter<MessagePacker> {
public void writeString(final String key, final String value, final MessagePacker destination)
throws IOException {
destination.packString(key);
destination.packString(value);
if (value == null) {
destination.packNil();
} else {
destination.packString(value);
}
}
@Override
@ -82,6 +86,10 @@ public class MsgpackFormatWriter extends FormatWriter<MessagePacker> {
final String key, final BigInteger value, final MessagePacker destination)
throws IOException {
destination.packString(key);
destination.packBigInteger(value);
if (value == null) {
destination.packNil();
} else {
destination.packBigInteger(value);
}
}
}

View File

@ -33,7 +33,7 @@ class DDSpanSerializationTest extends DDSpecification {
parent_id: 0l,
start : 100000,
duration : 33000,
type : "type",
type : spanType,
error : 0,
metrics : metrics,
meta : [
@ -58,7 +58,7 @@ class DDSpanSerializationTest extends DDSpecification {
null,
["a-baggage": "value"],
false,
"type",
spanType,
["k1": "v1"],
new PendingTrace(tracer, 1G, [:]),
tracer)
@ -73,9 +73,9 @@ class DDSpanSerializationTest extends DDSpecification {
actualTree == expectedTree
where:
samplingPriority | _
PrioritySampling.SAMPLER_KEEP | _
PrioritySampling.UNSET | _
samplingPriority | spanType
PrioritySampling.SAMPLER_KEEP | null
PrioritySampling.UNSET | "some-type"
}
def "serialize trace/span with id #value as int"() {
@ -93,7 +93,7 @@ class DDSpanSerializationTest extends DDSpecification {
null,
Collections.emptyMap(),
false,
"fakeType",
spanType,
Collections.emptyMap(),
new PendingTrace(tracer, 1G, [:]),
tracer)
@ -122,12 +122,12 @@ class DDSpanSerializationTest extends DDSpecification {
}
where:
value | _
0G | _
1G | _
8223372036854775807G | _
BigInteger.valueOf(Long.MAX_VALUE).subtract(1G) | _
BigInteger.valueOf(Long.MAX_VALUE).add(1G) | _
2G.pow(64).subtract(1G) | _
value | spanType
0G | null
1G | "some-type"
8223372036854775807G | null
BigInteger.valueOf(Long.MAX_VALUE).subtract(1G) | "some-type"
BigInteger.valueOf(Long.MAX_VALUE).add(1G) | null
2G.pow(64).subtract(1G) | "some-type"
}
}