Skip to content

NPE at JsonSchema.combineCurrentUriWithIds(JsonSchema.java:90) #347

@wheelerlaw

Description

@wheelerlaw

Here is my code:

    def jsonSchema = this.getClass().getClassLoader().getResource("schema/test.json").text
    JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)
    JsonSchema schema = factory.getSchema(jsonSchema)

If the schema's $id field does not start with a scheme, it will throw a null pointer exception. Here is the full stack trace:

java.lang.NullPointerException
	at com.networknt.schema.JsonSchema.combineCurrentUriWithIds(JsonSchema.java:90)
	at com.networknt.schema.JsonSchema.<init>(JsonSchema.java:72)
	at com.networknt.schema.JsonSchema.<init>(JsonSchema.java:58)
	at com.networknt.schema.JsonSchema.<init>(JsonSchema.java:53)
	at com.networknt.schema.JsonSchemaFactory.newJsonSchema(JsonSchemaFactory.java:254)
	at com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:282)
	at com.networknt.schema.JsonSchemaFactory.getSchema(JsonSchemaFactory.java:290)

Here is my test schema:

{
  "$id": "test",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "Test description",
  "properties": {
    "test": {
      "description": "Sample property",
      "examples": [
        "hello",
        "world"
      ],
      "type": "string"
    }
  },
  "required": [
    "test"
  ],
  "type": "object"
}

It should throw a JsonSchemaException instead of a NullPointerException, but in combineCurrentUriWithIds, currentUri will be null and therefore currentUri.toString() on line 90 will throw a NPE.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions