On a route created by the OpenApi spec with a required request body of content-type "application/json, a NullPointerException occurs if the request has a content-type header of "application/json" but a null body. This null pointer arises from the JsonTypeValidator class passing the request body to the validator without first checking if it is null.
Example request:
Request method: PUT
Request URI: http://localhost:4000/route-requiring-json-request
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=application/json
Content-Type=application/json; charset=UTF-8
Cookies: <none>
Multiparts: <none>
Body: <none>
causes this to occur:
[vert.x-eventloop-thread-3] WARN i.t.w.a.v.h.DefaultErrorHandler - Unexpected exception
java.lang.NullPointerException: null
at com.networknt.schema.TypeFactory.getValueNodeType(TypeFactory.java:61)
at com.networknt.schema.TypeValidator.validate(TypeValidator.java:54)
at com.networknt.schema.JsonSchema.validate(JsonSchema.java:143)
at com.networknt.schema.RefValidator.validate(RefValidator.java:85)
at com.networknt.schema.JsonSchema.validate(JsonSchema.java:143)
at com.networknt.schema.AllOfValidator.validate(AllOfValidator.java:49)
at com.networknt.schema.JsonSchema.validate(JsonSchema.java:143)
at com.networknt.schema.BaseJsonValidator.validate(BaseJsonValidator.java:79)
at io.vertx.ext.web.api.validation.impl.JsonTypeValidator.isValid(JsonTypeValidator.java:31)
at io.vertx.ext.web.api.validation.impl.BaseValidationHandler.validateEntireBody(BaseValidationHandler.java:238)
at io.vertx.ext.web.api.validation.impl.BaseValidationHandler.handle(BaseValidationHandler.java:72)
at io.vertx.ext.web.api.validation.impl.BaseValidationHandler.handle(BaseValidationHandler.java:20)
I would instead expect a ValidationException to occur.
I'm investigating!
Fixed inside branch contracts_fix
Most helpful comment
Fixed inside branch
contracts_fix