{"record":{"id":"686985efa04d0cd3","repo":"quarkusio/quarkus","slug":"lraid-can-t-be-null-as-it-should-be-invoked-with-t","errorCode":null,"errorMessage":"lraId can't be null as it should be invoked with the context","messagePattern":"lraId can't be null as it should be invoked with the context","errorType":"http","errorClass":"NullPointerException","httpStatus":500,"severity":"error","filePath":"integration-tests/narayana-lra/src/main/java/io/quarkus/it/lra/TransactionalResource.java","lineNumber":68,"sourceCode":"    @Path(\"completions\")\n    public int completions() {\n        return completions.get();\n    }\n\n    // return the number of times the compensation callback was called\n    @GET\n    @Path(\"compensations\")\n    public int compensations() {\n        return compensations.get();\n    }\n\n    // callback to inform the participant service that the LRA is cancelling\n    @PUT\n    @Path(\"compensate\")\n    @Compensate\n    public Response compensateWork(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {\n        if (lraId == null) {\n            throw new NullPointerException(\"lraId can't be null as it should be invoked with the context\");\n        }\n\n        compensations.incrementAndGet();\n\n        return Response.ok(lraId.toASCIIString()).build();\n    }\n\n    // callback to inform the participant service that the LRA is closing\n    @PUT\n    @Path(\"complete\")\n    @Complete\n    public Response completeWork(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {\n        if (lraId == null) {\n            throw new NullPointerException(\"lraId can't be null as it should be invoked with the context\");\n        }\n\n        completions.incrementAndGet();\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/narayana-lra/src/main/java/io/quarkus/it/lra/TransactionalResource.java#L50-L86","documentation":"The @Compensate LRA participant callback throws NullPointerException when the LRA_HTTP_CONTEXT_HEADER is absent. The MicroProfile LRA spec guarantees this header is present when the coordinator invokes a compensation callback, so a null means the method was called outside an LRA context (misdirected request or coordinator misconfiguration).","triggerScenarios":"A PUT request to /compensate without the Long-Running-Action header — e.g. manual invocation, test harness calling the endpoint directly, or the coordinator cancelling an LRA without propagating context.","commonSituations":"Calling the participant endpoint by hand (curl/tests) instead of through the LRA coordinator; proxy stripping custom headers; LRA coordinator misconfigured so callbacks lack context; wrong @Compensate/@LRA wiring on the endpoint.","solutions":["Let the LRA coordinator invoke the callback rather than calling the endpoint directly","Ensure the coordinator is running and configured with the correct callback URL base (quarkus.narayana.lra.*)","Check that no proxy/load balancer strips the LRA_HTTP_CONTEXT_HEADER","Verify @LRA annotations on the triggering resource so an active LRA context exists to cancel"],"exampleFix":"// before\ncurl -X PUT http://host/lra/compensate   // missing LRA_HTTP_CONTEXT_HEADER\n// after\n# cancel the LRA via the coordinator / end the @LRA resource so the callback is invoked with the header","handlingStrategy":"validation","validationCode":"URI lraIdHeader = /* request header */ headers.getFirst(LRA_HTTP_CONTEXT_HEADER);\nif (lraIdHeader == null) {\n    return Response.status(412).entity(\"missing LRA context\").build();\n}\n// proceed with compensate","typeGuard":"static boolean hasLraContext(jakarta.ws.rs.core.HttpHeaders h) {\n    return h.getHeaderString(LRA_HTTP_CONTEXT_HEADER) != null;\n}","tryCatchPattern":"try {\n    compensateWork(lraId);\n} catch (NullPointerException e) {\n    return Response.status(412, \"LRA context header missing\").build();\n}","preventionTips":["Never invoke participant callbacks directly; let the coordinator drive them","Verify the LRA coordinator URL configuration (quarkus.narayana.lra.*)","Ensure proxies preserve the LRA_HTTP_CONTEXT_HEADER","Confirm @LRA annotations create an active context before cancellation"],"tags":["lra","narayana","missing-header","transaction"],"backgroundTag":"missing-lra-context-header","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}