Skip to content

NPE from BaseJsonValidator.debug while walking JSON schema #1168

Open
@chrishodgins

Description

@chrishodgins

This was found while I was creating an issue for #1167. Changing the code to look like the example below and setting Java vmargs to -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG was enough to generate the NPE.

        ...

        JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
        JsonSchema schema = factory.getSchema(schemaContents);
        ExecutionContext context = schema.createExecutionContext();
        context.getExecutionConfig().setDebugEnabled(true);
        ValidationResult result = schema.walk(context, jsonContents, InputFormat.JSON, true);
        result.getValidationMessages().forEach(m -> System.out.println(m));

NPE:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.fasterxml.jackson.databind.JsonNode.toString()" because "node" is null
        at com.networknt.schema.BaseJsonValidator.debug(BaseJsonValidator.java:138)
        at com.networknt.schema.OneOfValidator.validate(OneOfValidator.java:71)
        at com.networknt.schema.OneOfValidator.walk(OneOfValidator.java:234)
        at com.networknt.schema.JsonSchema.walk(JsonSchema.java:1278)
        at com.networknt.schema.PropertiesValidator.walkSchema(PropertiesValidator.java:197)
        at com.networknt.schema.PropertiesValidator.validate(PropertiesValidator.java:109)
        at com.networknt.schema.PropertiesValidator.walk(PropertiesValidator.java:133)
        at com.networknt.schema.JsonSchema.walk(JsonSchema.java:1278)
        at com.networknt.schema.JsonSchema.walkAtNodeInternal(JsonSchema.java:1247)
        at com.networknt.schema.JsonSchema.walk(JsonSchema.java:1098)
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions