networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
855 stars 325 forks source link

Since 1.3.0: IllegalArgumentException instead of JsonSchemaException #935

Closed itineric closed 9 months ago

itineric commented 9 months ago

When passing a bad $schema value, we now get an IllegalArgumentException, it should be a JsonSchemaException as it was before version 1.3.0.

Passing "$schema": "0" gives us

java.lang.IllegalArgumentException: URI is not absolute
    at java.base/java.net.URL.fromURI(URL.java:721) ~[na:na]
    at java.base/java.net.URI.toURL(URI.java:1139) ~[na:na]
    at com.networknt.schema.resource.UriSchemaLoader.lambda$getSchema$0(UriSchemaLoader.java:35) ~[json-schema-validator.jar:na]
    at com.networknt.schema.JsonSchemaFactory.getMappedSchema(JsonSchemaFactory.java:479) ~[json-schema-validator.jar:na]
    at com.networknt.schema.JsonSchemaFactory.lambda$getSchema$3(JsonSchemaFactory.java:454) ~[json-schema-validator.jar:na]
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
    at com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:453) ~[json-schema-validator.jar:na]
    at com.networknt.schema.JsonSchemaFactory.loadMetaSchema(JsonSchemaFactory.java:359) ~[json-schema-validator.jar:na]
    at com.networknt.schema.JsonSchemaFactory.lambda$getMetaSchema$2(JsonSchemaFactory.java:354) ~[json-schema-validator.jar:na]
    at java.base/java.util.Optional.orElseGet(Optional.java:364) ~[na:na]
    at com.networknt.schema.JsonSchemaFactory.getMetaSchema(JsonSchemaFactory.java:352) ~[json-schema-validator.jar:na]
    at com.networknt.schema.JsonSchemaFactory.lambda$getMetaSchemaOrDefault$1(JsonSchemaFactory.java:344) ~[json-schema-validator.jar:na]
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
    at com.networknt.schema.JsonSchemaFactory.getMetaSchemaOrDefault(JsonSchemaFactory.java:344) ~[json-schema-validator.jar:na]
    at com.networknt.schema.JsonSchemaFactory.createValidationContext(JsonSchemaFactory.java:326) ~[json-schema-validator.jar:na]
    at com.networknt.schema.JsonSchemaFactory.newJsonSchema(JsonSchemaFactory.java:257) ~[json-schema-validator.jar:na]
    at com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:608) ~[json-schema-validator.jar:na]
justin-tay commented 9 months ago

This is because 1.3.0 included support for loading custom meta schemas. This will be fixed to throw the appropriate exception.