This is an automated email from the ASF dual-hosted git repository.
jlmonteiro 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 a6d46679 feat: improve error message for debugging
a6d46679 is described below
commit a6d46679c5f1840e2c390f37ec243d1d79afbfbf
Author: Jean-Louis Monteiro <[email protected]>
AuthorDate: Wed May 17 14:34:31 2023 +0200
feat: improve error message for debugging
---
.../main/java/org/apache/johnzon/core/JsonObjectBuilderImpl.java | 9 ++++++---
.../java/org/apache/johnzon/core/JsonObjectBuilderImplTest.java | 9 +++++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git
a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonObjectBuilderImpl.java
b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonObjectBuilderImpl.java
index ed0b0eaf..56383f51 100644
---
a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonObjectBuilderImpl.java
+++
b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonObjectBuilderImpl.java
@@ -182,9 +182,12 @@ class JsonObjectBuilderImpl implements JsonObjectBuilder,
Serializable {
return this;
}
- private void putValue(final String name, final JsonValue value){
- if(name == null || value == null) {
- throw new NullPointerException("name or value/builder must not be
null");
+ private void putValue(final String name, final JsonValue value) {
+ if(name == null) {
+ throw new NullPointerException("name must not be null");
+ }
+ if(value == null) {
+ throw new NullPointerException("value/builder must not be null for
name: " + name);
}
rejectDuplicateKeysMode.put().put(attributeMap, name, value);
}
diff --git
a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonObjectBuilderImplTest.java
b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonObjectBuilderImplTest.java
index 99aa39f3..c57f94f5 100644
---
a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonObjectBuilderImplTest.java
+++
b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonObjectBuilderImplTest.java
@@ -133,6 +133,15 @@ public class JsonObjectBuilderImplTest {
builder.add("a", (Integer) null);
}
+ @Test
+ public void testNullCheckValueExceptionMessage() {
+ final JsonObjectBuilder builder = Json.createObjectBuilder();
+ try {
+ builder.add("name", (JsonValue) null);
+ } catch (final NullPointerException e) {
+ assertEquals("value/builder must not be null for name: name",
e.getMessage());
+ }
+ }
@Test(expected = NullPointerException.class)
public void testNullCheckName() {
final JsonObjectBuilder builder = Json.createObjectBuilder();