quarkusio/quarkus · error · AssertionError
Our custom XML format mapper throws exceptions. So we were e
Error message
Our custom XML format mapper throws exceptions. So we were expecting transaction to fail, but it did not!
What it means
An AssertionError from hibernateXml when the test expected persisting an entity to fail (because the registered custom XML FormatMapper throws 'I cannot convert anything to XML'), but the transaction completed successfully. The test's negative-path assertion is inverted by a configuration change that made the mapper work or was never invoked.
Source
Thrown at integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java:229
});
QuarkusTransaction.requiringNew().run(() -> {
em.createQuery("delete from EntityWithXml").executeUpdate();
});
Exception exception = null;
try {
QuarkusTransaction.requiringNew().run(() -> {
EntityWithXmlOtherPU otherPU = new EntityWithXmlOtherPU(
new EntityWithXmlOtherPU.ToBeSerializedWithDateTime(LocalDate.of(2023, 7, 28)));
otherEm.persist(otherPU);
});
} catch (Exception e) {
exception = e;
}
if (exception == null) {
throw new AssertionError(
"Our custom XML format mapper throws exceptions. So we were expecting transaction to fail, but it did not!");
}
if (!(exception instanceof UnsupportedOperationException)
|| !exception.getMessage().contains("I cannot convert anything to XML")) {
throw new AssertionError("flush failed for a different reason than expected.", exception);
}
return "OK";
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Confirm the throwing XML FormatMapper is registered for the persistence unit under test (@PersistenceUnitExtension present and scoped correctly)
- Verify the entity attribute is actually mapped as XML so Hibernate invokes the FormatMapper at flush
- Check the mapper's message still matches "I cannot convert anything to XML" (the test asserts message content)
- Inspect quarkus.hibernate.orm.persistence-unit config to ensure the custom mapper is picked up
Example fix
// before
// no mapper registered -> default XML serialization succeeds
// after
@JsonFormat
@PersistenceUnitExtension("other")
public class ThrowingXmlFormatMapper implements FormatMapper {
public <T> String toString(T value, JavaType<T> t, WrapperOptions o) {
throw new UnsupportedOperationException("I cannot convert anything to XML");
}
public <T> T fromString(CharSequence c, JavaType<T> t, WrapperOptions o) {
throw new UnsupportedOperationException("I cannot convert anything from XML");
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// verify the throwing mapper is actually registered before running the negative test
boolean mapperRegistered = Arc.container().select(FormatMapper.class)
.stream().anyMatch(m -> m.getClass().getSimpleName().toLowerCase().contains("xml")); Try / catch
try {
QuarkusTransaction.requiringNew().run(() -> em.persist(entity));
fail("expected flush to fail");
} catch (UnsupportedOperationException e) {
assertTrue(e.getMessage().contains("I cannot convert anything to XML"), e.getMessage());
} Prevention
- Keep throwing stub mappers annotated with @PersistenceUnitExtension for the right PU
- Assert mapper registration in a startup/test-setup check
- Make negative tests assert both exception type and message so silent success is caught
When it happens
Trigger: After committing a transaction that persists an EntityWithXml, exception remains null because no UnsupportedOperationException('I cannot convert anything to XML') was thrown at flush.
Common situations: The custom throwing XML FormatMapper is no longer registered (missing @PersistenceUnitExtension or wrong config), Hibernate uses its default XML mapper instead, or the entity's XML attribute is never touched at flush.
Related errors
- No entities with XML were found
- Incorrect number of results
- Query string cannot be null
- AuthenticationFailedException
- Incorrect citizen: " + country.getName() + ", expected: " +
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/f0882d1b56cc21d0.
Report an issue: GitHub.