{"record":{"id":"a0bed186d8bb9d64","repo":"apache/beam","slug":"error-when-creating-unmarshaller-from-jaxb-context","errorCode":null,"errorMessage":"Error when creating unmarshaller from JAXB Context.","messagePattern":"Error when creating unmarshaller from JAXB Context\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/JAXBCoder.java","lineNumber":85,"sourceCode":"          @Override\n          protected Marshaller initialValue() {\n            try {\n              JAXBContext jaxbContext = getContext();\n              return jaxbContext.createMarshaller();\n            } catch (JAXBException e) {\n              throw new RuntimeException(\"Error when creating marshaller from JAXB Context.\", e);\n            }\n          }\n        };\n    this.jaxbUnmarshaller =\n        new EmptyOnDeserializationThreadLocal<Unmarshaller>() {\n          @Override\n          protected Unmarshaller initialValue() {\n            try {\n              JAXBContext jaxbContext = getContext();\n              return jaxbContext.createUnmarshaller();\n            } catch (Exception e) {\n              throw new RuntimeException(\"Error when creating unmarshaller from JAXB Context.\", e);\n            }\n          }\n        };\n  }\n\n  /**\n   * Create a coder for a given type of JAXB annotated objects.\n   *\n   * @param jaxbClass the {@code Class} of the JAXB annotated objects.\n   */\n  public static <T> JAXBCoder<T> of(Class<T> jaxbClass) {\n    return new JAXBCoder<>(jaxbClass);\n  }\n\n  @Override\n  public void encode(T value, OutputStream outStream) throws IOException {\n    encode(value, outStream, Context.NESTED);\n  }","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/JAXBCoder.java#L67-L103","documentation":"JAXBCoder lazily creates a thread-local JAXB Unmarshaller for XML deserialization. If JAXBContext.createUnmarshaller() fails, the ThreadLocal initialValue wraps the exception in this RuntimeException. Decoding XML elements will fail until the JAXB context/classes are fixed.","triggerScenarios":"Creating a JAXBCoder for a class whose JAXBContext cannot produce an Unmarshaller, then attempting to decode bytes from the stream, invoking initialValue.","commonSituations":"Same root causes as marshaller failures: missing JAXB runtime on Java 11+, invalid JAXB annotations, classloading issues in pipeline workers where the annotated class is not visible to the JAXB provider.","solutions":["Check the wrapped exception cause for the concrete JAXB failure and fix the annotated class.","Verify the JAXB runtime (jaxb-runtime) is bundled with the pipeline so workers can instantiate the Unmarshaller.","Confirm the record class is on the classpath in worker environments (use a fat jar / correct staging).","Validate the class with JAXBContext.newInstance(cls).createUnmarshaller() locally before submitting the pipeline."],"exampleFix":"// before: missing runtime on Java 11\n// after: add dependency\n// implementation 'javax.xml.bind:jaxb-api:2.3.1'\n// implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.1'","handlingStrategy":"try-catch","validationCode":"try { JAXBContext.newInstance(recordClass).createUnmarshaller(); } catch (Exception e) { throw new IllegalStateException(\"Record class not JAXB-unmarshalable\", e); }","typeGuard":null,"tryCatchPattern":"try { coder = Jaxbcoder.of(Record.class); } catch (RuntimeException e) { throw new IllegalStateException(\"JAXB unmarshaller setup failed: \" + e.getCause(), e); }","preventionTips":["Verify the JAXB implementation is available at worker runtime, not just locally.","Keep the annotated record classes in an SDK-independent module staged with the job.","Test decode round-trips (encode then decode) in CI."],"tags":["java","apache-beam","jaxb","xml"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}