Skip to content

NullPointerException in parser with additionalProperties: false #1437

Closed
@MartinGeisse

Description

@MartinGeisse

I'm trying to restrict properties by setting additionalProperties: false. However, this seems to crash the YAML parser with a NullPointerException. When testing, please note that the most visible error is a syntax error from the JSON parser which kicks in after the YAML parser failed.

Main.java:

public class NpeDemo {
    public static void main(String[] args) {
        Swagger swagger = new SwaggerParser().read("npe-demo.yaml", null, true);
    }
}

npe-demo.yaml:

swagger: '2.0'

definitions:
  Demo:
    type: object
    additionalProperties: false
    properties:
      foo:
        type: string

paths:
  /demo:
    get:
      responses:
        200:
          description: blah

The problem happens in PropertyDeserializer.deserialize(JsonParser jp, DeserializationContext ctxt): The propertyFromNode(node) call returns null, which causes the NPE in the next line.

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