Skip to content

Commit 8854403

Browse files
authored
Fixes for #138: Move null checking to end of the conditional branch (#139)
1 parent 3b95db3 commit 8854403

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

guava/src/main/java/com/fasterxml/jackson/datatype/guava/deser/GuavaImmutableCollectionDeserializer.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,17 @@ protected T _deserializeContents(JsonParser p, DeserializationContext ctxt)
6464
continue;
6565
}
6666
value = _resolveNullToValue(ctxt);
67-
if (value == null) {
68-
if (value == null) {
69-
_tryToAddNull(p, ctxt, builder);
70-
continue;
71-
}
72-
}
7367
} else if (typeDeser == null) {
7468
value = valueDes.deserialize(p, ctxt);
7569
} else {
7670
value = valueDes.deserializeWithType(p, ctxt, typeDeser);
7771
}
7872

73+
if (value == null) {
74+
_tryToAddNull(p, ctxt, builder);
75+
continue;
76+
}
77+
7978
builder.add(value);
8079
}
8180
// No class outside of the package will be able to subclass us,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fasterxml.jackson.datatype.guava.fuzz;
2+
3+
import org.junit.Assert;
4+
5+
import com.fasterxml.jackson.core.type.TypeReference;
6+
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
9+
import com.fasterxml.jackson.datatype.guava.ModuleTestBase;
10+
11+
import com.google.common.collect.ImmutableList;
12+
13+
/**
14+
* Unit tests for verifying the fixes for OSS-Fuzz issues
15+
* work as expected
16+
* (see [datatypes-collections#138]).
17+
*/
18+
public class Fuzz138_65117Test extends ModuleTestBase
19+
{
20+
private final ObjectMapper MAPPER = mapperWithModule();
21+
22+
public void testOSSFuzzIssue65117() throws Exception
23+
{
24+
final TypeReference<?> ref = new TypeReference<ImmutableList<Integer>>() {};
25+
MismatchedInputException e = Assert.assertThrows(
26+
MismatchedInputException.class,
27+
() -> MAPPER.readValue("[\"\"s(", ref));
28+
verifyException(e, "Guava `Collection` of type ");
29+
verifyException(e, "does not accept `null` values");
30+
}
31+
}

release-notes/CREDITS-2.x

+4-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ Muhammad Khalikov (@mukham12)
125125
(2.17.0)
126126

127127
Arthur Chan (@arthurscchan)
128-
* Contributed #124: Some deserializers throw unexpected `NullPointerException`
128+
* Contributed #124: (guava) Some deserializers throw unexpected `NullPointerException`
129129
when handling invalid input
130130
(2.17.0)
131-
131+
* Contributed #138: (guava) `GuavaCollectionDeserializer` still throws NPE in
132+
some circumstances
133+
(2.17.0)

release-notes/VERSION-2.x

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ Active Maintainers:
2222
(contributed by Muhammad K)
2323
#124: (guava) Some deserializers throw unexpected `NullPointerException` when
2424
handling invalid input
25-
(contibuted by Arthur C)
25+
(contributed by Arthur C)
2626
#136 (guava) Fix for failing Guava `Optional` test
2727
(contributed by Muhammad K)
28+
#138 (guava) `GuavaCollectionDeserializer` still throws NPE in some circumstances
29+
(contributed by Arthur C)
2830

2931
2.16.0 (15-Nov-2023)
3032

0 commit comments

Comments
 (0)