This is an automated email from the ASF dual-hosted git repository. bvahdat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 9b63c3eedca avoid potential NPE 9b63c3eedca is described below commit 9b63c3eedca7a18581f471cf75c17c4ea0aa1663 Author: Babak Vahdat <bvah...@apache.org> AuthorDate: Sun May 21 17:56:41 2023 +0200 avoid potential NPE --- .../camel/component/jsonvalidator/JsonValidationException.java | 3 ++- .../camel/component/jsonvalidator/JsonValidationExceptionTest.java | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidationException.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidationException.java index 0284ac1a310..0856d8205d0 100644 --- a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidationException.java +++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidationException.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.jsonvalidator; +import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; @@ -40,7 +41,7 @@ public class JsonValidationException extends ValidationException { public JsonValidationException(Exchange exchange, JsonSchema schema, Exception e) { super(e.getMessage(), exchange, e); this.schema = schema; - this.errors = null; + this.errors = Collections.EMPTY_SET; } public JsonSchema getSchema() { diff --git a/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/JsonValidationExceptionTest.java b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/JsonValidationExceptionTest.java index aa1b81225cd..06d511e0ca8 100644 --- a/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/JsonValidationExceptionTest.java +++ b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/JsonValidationExceptionTest.java @@ -17,6 +17,7 @@ package org.apache.camel.component.jsonvalidator; import java.text.MessageFormat; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; @@ -24,6 +25,7 @@ import com.networknt.schema.ValidationMessage; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; public class JsonValidationExceptionTest { @@ -37,6 +39,11 @@ public class JsonValidationExceptionTest { new JsonValidationException(null, null, errors).getMessage()); } + @Test + void testErrorsEmpty() { + assertSame(Collections.EMPTY_SET, new JsonValidationException(null, null, new Exception()).getErrors()); + } + private ValidationMessage createError(String msg) { return new ValidationMessage.Builder().format(new MessageFormat(msg)).build(); }