Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in NodeType.getNodeType when validating an empty string against a schema #14

Open
jeffngo opened this issue Jan 20, 2018 · 1 comment

Comments

@jeffngo
Copy link

jeffngo commented Jan 20, 2018

In jackson-core-2.9.3, NodeType.getNodeType fails the Preconditions check with a NullPointerException if the JsonToken is not in the TOKEN_MAP:

    /**
     * Given a {@link JsonNode} as an argument, return its type. The argument
     * MUST NOT BE NULL, and MUST NOT be a {@link MissingNode}
     *
     * @param node the node to determine the type of
     * @return the type for this node
     */
    public static NodeType getNodeType(final JsonNode node)
    {
        final JsonToken token = node.asToken();
        final NodeType ret = TOKEN_MAP.get(token);

        Preconditions.checkNotNull(ret, "unhandled token type " + token);

        return ret;
    }

Here is a simple unit test I wrote to test the different versions of jackson-core.

private static final String STATUS_OUTPUT_SCHEMA =
      "{ \"enum\": [\"" + STATUS_ACTIVE_EXIT + "\", \"" + STATUS_INACTIVE_EXIT + "\"] }";

@Test
  public void testEmptyStringAgainstSchema() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode schema = mapper.readTree(STATUS_OUTPUT_SCHEMA);
    JsonSchemaUtils.isValid(mapper.readTree(""), schema);
  }

In version 2.6.4 of jackson-core, this would fail with a JsonMappingException. However, in version 2.9.3 of jackson-core, this will trigger a NPE. Here is the stacktrace:

com.delphix.appliance.node.logging.exception.ConstructingFatalThrowableException: java.lang.NullPointerException: unhandled token type NOT_AVAILABLE
	at com.delphix.appliance.server.util.ExceptionInstrumentationUtil.handleFatalThrowable(ExceptionInstrumentationUtil.java:193)
	at com.delphix.appliance.server.util.ExceptionInstrumentationUtil.access$000(ExceptionInstrumentationUtil.java:32)
	at com.delphix.appliance.server.util.ExceptionInstrumentationUtil$2.sample(ExceptionInstrumentationUtil.java:163)
	at com.delphix.appliance.server.util.ExceptionInstrumentationUtil$2.sample(ExceptionInstrumentationUtil.java:159)
	at com.google.monitoring.runtime.instrumentation.ConstructorInstrumenter.invokeSamplers(ConstructorInstrumenter.java:207)
	at java.lang.RuntimeException.<init>(RuntimeException.java:63)
	at java.lang.NullPointerException.<init>(NullPointerException.java:70)
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:787)
	at com.github.fge.jackson.NodeType.getNodeType(NodeType.java:144)
	at com.github.fge.jsonschema.processors.data.SchemaContext.<init>(SchemaContext.java:49)
	at com.github.fge.jsonschema.processors.validation.InstanceValidator.process(InstanceValidator.java:104)
	at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:56)
	at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:34)
	at com.github.fge.jsonschema.core.processing.ProcessingResult.of(ProcessingResult.java:79)
	at com.github.fge.jsonschema.main.JsonSchema.doValidate(JsonSchema.java:76)
	at com.github.fge.jsonschema.main.JsonSchema.validInstance(JsonSchema.java:182)
@jlolling
Copy link

The problem does not exists in version 2.9.2 of jackson-core. The problem appears in version 2.9.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants