Skip to content

Commit c4b27b0

Browse files
authored
Fix NPE (#348)
1 parent 8e663d0 commit c4b27b0

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/main/java/com/networknt/schema/JsonSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private URI combineCurrentUriWithIds(URI currentUri, JsonNode schemaNode) {
9595
try {
9696
return this.validationContext.getURIFactory().create(currentUri, id);
9797
} catch (IllegalArgumentException e) {
98-
throw new JsonSchemaException(ValidationMessage.of(ValidatorTypeCode.ID.getValue(), ValidatorTypeCode.ID, id, currentUri.toString()));
98+
throw new JsonSchemaException(ValidationMessage.of(ValidatorTypeCode.ID.getValue(), ValidatorTypeCode.ID, id, currentUri == null ? "null" : currentUri.toString()));
9999
}
100100
}
101101
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.networknt.schema;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import org.junit.Test;
5+
import static org.junit.Assert.assertEquals;
6+
import static org.hamcrest.CoreMatchers.instanceOf;
7+
import static org.hamcrest.MatcherAssert.assertThat;
8+
9+
public class Issue347Test {
10+
11+
@Test
12+
public void failure() {
13+
ObjectMapper mapper = new ObjectMapper();
14+
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
15+
try {
16+
JsonSchema schema = factory.getSchema(Thread.currentThread().getContextClassLoader().getResourceAsStream("schema/issue347-v7.json"));
17+
} catch (Throwable e) {
18+
assertThat(e, instanceOf(JsonSchemaException.class));
19+
assertEquals("test: null is an invalid segment for URI {2}", e.getMessage());
20+
}
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$id": "test",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"description": "Test description",
5+
"properties": {
6+
"test": {
7+
"description": "Sample property",
8+
"examples": [
9+
"hello",
10+
"world"
11+
],
12+
"type": "string"
13+
}
14+
},
15+
"required": [
16+
"test"
17+
],
18+
"type": "object"
19+
}

0 commit comments

Comments
 (0)