Skip to content

Commit 52da80f

Browse files
committed
[JOHNZON-407] fix NPE in JsonArrayBuilderImpl
(cherry picked from commit 06caf92)
1 parent 664cb73 commit 52da80f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public JsonArrayBuilderImpl(final Collection<?> initialData, final BufferStrateg
5757
final RejectDuplicateKeysMode rejectDuplicateKeysMode, final JsonProviderImpl jsonProvider) {
5858
this.bufferProvider = provider;
5959
this.rejectDuplicateKeysMode = rejectDuplicateKeysMode;
60+
this.jsonProvider = jsonProvider;
6061
this.tmpList = new ArrayList<>();
6162
if (!initialData.isEmpty()) {
6263
for (Object initialValue : initialData) {
6364
add(initialValue);
6465
}
6566
}
66-
this.jsonProvider = jsonProvider;
6767
}
6868

6969
@Override

johnzon-core/src/test/java/org/apache/johnzon/core/JsonArrayBuilderImplTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,17 @@ public void testCreateArrayBuilderWithCollectionInitialData() {
202202
JsonArray jsonArray2 = otherBuilder.build();
203203
Assert.assertEquals("[\"a\",\"b\",\"c\",\"d\"]", jsonArray2.toString());
204204
}
205+
206+
/**
207+
* Testcase for <a href="https://issues.apache.org/jira/browse/JOHNZON-407">JOHNZON-407</a>
208+
*/
209+
@Test
210+
public void issue407() {
211+
Collection<Object> initialData = new ArrayList<>();
212+
initialData.add(BigDecimal.ONE);
213+
initialData.add(BigInteger.ONE);
214+
215+
// This must not throw an exception
216+
Json.createArrayBuilder(initialData).build();
217+
}
205218
}

0 commit comments

Comments
 (0)