Skip to content

Commit

Permalink
[JOHNZON-407] fix NPE in JsonArrayBuilderImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
jungm committed Aug 4, 2024
1 parent 89492c9 commit 06caf92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public JsonArrayBuilderImpl(final Collection<?> initialData, final BufferStrateg
final RejectDuplicateKeysMode rejectDuplicateKeysMode, final JsonProviderImpl jsonProvider) {
this.bufferProvider = provider;
this.rejectDuplicateKeysMode = rejectDuplicateKeysMode;
this.jsonProvider = jsonProvider;
this.tmpList = new ArrayList<>();
if (!initialData.isEmpty()) {
for (Object initialValue : initialData) {
add(initialValue);
}
}
this.jsonProvider = jsonProvider;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,17 @@ public void testCreateArrayBuilderWithCollectionInitialData() {
JsonArray jsonArray2 = otherBuilder.build();
Assert.assertEquals("[\"a\",\"b\",\"c\",\"d\"]", jsonArray2.toString());
}

/**
* Testcase for <a href="https://issues.apache.org/jira/browse/JOHNZON-407">JOHNZON-407</a>
*/
@Test
public void issue407() {
Collection<Object> initialData = new ArrayList<>();
initialData.add(BigDecimal.ONE);
initialData.add(BigInteger.ONE);

// This must not throw an exception
Json.createArrayBuilder(initialData).build();
}
}

0 comments on commit 06caf92

Please sign in to comment.