Stream: implementers
Topic: NullPointerException JsonParser.encodeResourceToString
Tia Cummings (Feb 28 2022 at 13:32):
We have an interceptor that is trying to print out the outgoing resource on Pointcut.OUTGOING_SERVER_RESPONSE and we're getting an NPE when calling the JsonParser.encodeResourceToString() method. I did some debugging and it looks like one of the contained resources has a null id, so somewhere in the hapi code, when id.getValue() is called, id is null, BUT our server prints out the response fine to the end user, we just can't use the jsonparser to log the response. This seems to happen when we get a heavy load of calls. Is anyone aware if the IParser is thread safe?
This is the stacktrace that we're getting:
java.lang.NullPointerException: null
at ca.uhn.fhir.parser.JsonParser.encodeChildElementToStreamWriter(JsonParser.java:309)
at ca.uhn.fhir.parser.JsonParser.encodeCompositeElementChildrenToStreamWriter(JsonParser.java:399)
at ca.uhn.fhir.parser.JsonParser.encodeCompositeElementToStreamWriter(JsonParser.java:587)
at ca.uhn.fhir.parser.JsonParser.encodeResourceToJsonStreamWriter(JsonParser.java:741)
at ca.uhn.fhir.parser.JsonParser.encodeResourceToJsonStreamWriter(JsonParser.java:625)
at ca.uhn.fhir.parser.JsonParser.encodeChildElementToStreamWriter(JsonParser.java:339)
at ca.uhn.fhir.parser.JsonParser.encodeCompositeElementChildrenToStreamWriter(JsonParser.java:497)
at ca.uhn.fhir.parser.JsonParser.encodeCompositeElementToStreamWriter(JsonParser.java:587)
at ca.uhn.fhir.parser.JsonParser.encodeChildElementToStreamWriter(JsonParser.java:291)
at ca.uhn.fhir.parser.JsonParser.encodeCompositeElementChildrenToStreamWriter(JsonParser.java:501)
at ca.uhn.fhir.parser.JsonParser.encodeCompositeElementToStreamWriter(JsonParser.java:587)
at ca.uhn.fhir.parser.JsonParser.encodeResourceToJsonStreamWriter(JsonParser.java:741)
at ca.uhn.fhir.parser.JsonParser.encodeResourceToJsonStreamWriter(JsonParser.java:625)
at ca.uhn.fhir.parser.JsonParser.doEncodeResourceToJsonLikeWriter(JsonParser.java:163)
at ca.uhn.fhir.parser.JsonParser.doEncodeResourceToWriter(JsonParser.java:170)
at ca.uhn.fhir.parser.BaseParser.encodeResourceToWriter(BaseParser.java:399)
at ca.uhn.fhir.parser.BaseParser.encodeResourceToWriter(BaseParser.java:383)
at ca.uhn.fhir.parser.BaseParser.encodeResourceToString(BaseParser.java:372)
Last updated: Apr 12 2022 at 19:14 UTC