This is an automated email from the ASF dual-hosted git repository. jungm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git
The following commit(s) were added to refs/heads/master by this push: new 06caf92f [JOHNZON-407] fix NPE in JsonArrayBuilderImpl 06caf92f is described below commit 06caf92fc57e1c4a5f974079bb399e1839e70b11 Author: Markus Jung <ju...@apache.org> AuthorDate: Sun Aug 4 11:21:10 2024 +0200 [JOHNZON-407] fix NPE in JsonArrayBuilderImpl --- .../java/org/apache/johnzon/core/JsonArrayBuilderImpl.java | 2 +- .../org/apache/johnzon/core/JsonArrayBuilderImplTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java index b1ad933d..406551b1 100644 --- a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java +++ b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java @@ -58,13 +58,13 @@ class JsonArrayBuilderImpl implements JsonArrayBuilder, Serializable { 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 diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonArrayBuilderImplTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonArrayBuilderImplTest.java index 5fdf9780..b1418e1b 100644 --- a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonArrayBuilderImplTest.java +++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonArrayBuilderImplTest.java @@ -202,4 +202,17 @@ public class JsonArrayBuilderImplTest { 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(); + } }