apache/beam · error · RuntimeException
Error when creating unmarshaller from JAXB Context.
Error message
Error when creating unmarshaller from JAXB Context.
What it means
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.
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.
Example fix
// before: missing runtime on Java 11 // after: add dependency // implementation 'javax.xml.bind:jaxb-api:2.3.1' // implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.1'
Defensive patterns
Strategy: try-catch
Validate before calling
try { JAXBContext.newInstance(recordClass).createUnmarshaller(); } catch (Exception e) { throw new IllegalStateException("Record class not JAXB-unmarshalable", e); } Try / catch
try { coder = Jaxbcoder.of(Record.class); } catch (RuntimeException e) { throw new IllegalStateException("JAXB unmarshaller setup failed: " + e.getCause(), e); } Prevention
- 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.
When it happens
Trigger: Creating a JAXBCoder for a class whose JAXBContext cannot produce an Unmarshaller, then attempting to decode bytes from the stream, invoking initialValue.
Common situations: 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.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- Error binding classes to a JAXB Context.
- Error when creating marshaller from JAXB Context.
- at key is not supported
- A function must be provided to convert the input type into…
- A PValue contained in
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/a0bed186d8bb9d64.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/JAXBCoder.java:85
@Override
protected Marshaller initialValue() {
try {
JAXBContext jaxbContext = getContext();
return jaxbContext.createMarshaller();
} catch (JAXBException e) {
throw new RuntimeException("Error when creating marshaller from JAXB Context.", e);
}
}
};
this.jaxbUnmarshaller =
new EmptyOnDeserializationThreadLocal<Unmarshaller>() {
@Override
protected Unmarshaller initialValue() {
try {
JAXBContext jaxbContext = getContext();
return jaxbContext.createUnmarshaller();
} catch (Exception e) {
throw new RuntimeException("Error when creating unmarshaller from JAXB Context.", e);
}
}
};
}
/**
* Create a coder for a given type of JAXB annotated objects.
*
* @param jaxbClass the {@code Class} of the JAXB annotated objects.
*/
public static <T> JAXBCoder<T> of(Class<T> jaxbClass) {
return new JAXBCoder<>(jaxbClass);
}
@Override
public void encode(T value, OutputStream outStream) throws IOException {
encode(value, outStream, Context.NESTED);
}View on GitHub (pinned to 12126d8942)