{"record":{"id":"f0882d1b56cc21d0","repo":"quarkusio/quarkus","slug":"our-custom-xml-format-mapper-throws-exceptions-so","errorCode":null,"errorMessage":"Our custom XML format mapper throws exceptions. So we were expecting transaction to fail, but it did not!","messagePattern":"Our custom XML format mapper throws exceptions\\. So we were expecting transaction to fail, but it did not!","errorType":"http","errorClass":"AssertionError","httpStatus":500,"severity":"error","filePath":"integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java","lineNumber":229,"sourceCode":"        });\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            em.createQuery(\"delete from EntityWithXml\").executeUpdate();\n        });\n\n        Exception exception = null;\n        try {\n            QuarkusTransaction.requiringNew().run(() -> {\n                EntityWithXmlOtherPU otherPU = new EntityWithXmlOtherPU(\n                        new EntityWithXmlOtherPU.ToBeSerializedWithDateTime(LocalDate.of(2023, 7, 28)));\n                otherEm.persist(otherPU);\n            });\n        } catch (Exception e) {\n            exception = e;\n        }\n\n        if (exception == null) {\n            throw new AssertionError(\n                    \"Our custom XML format mapper throws exceptions. So we were expecting transaction to fail, but it did not!\");\n        }\n        if (!(exception instanceof UnsupportedOperationException)\n                || !exception.getMessage().contains(\"I cannot convert anything to XML\")) {\n            throw new AssertionError(\"flush failed for a different reason than expected.\", exception);\n        }\n\n        return \"OK\";\n    }\n\n}\n","sourceCodeStart":211,"sourceCodeEnd":241,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java#L211-L241","documentation":"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.","triggerScenarios":"After committing a transaction that persists an EntityWithXml, exception remains null because no UnsupportedOperationException('I cannot convert anything to XML') was thrown at flush.","commonSituations":"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.","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"],"exampleFix":"// before\n// no mapper registered -> default XML serialization succeeds\n// after\n@JsonFormat\n@PersistenceUnitExtension(\"other\")\npublic class ThrowingXmlFormatMapper implements FormatMapper {\n    public <T> String toString(T value, JavaType<T> t, WrapperOptions o) {\n        throw new UnsupportedOperationException(\"I cannot convert anything to XML\");\n    }\n    public <T> T fromString(CharSequence c, JavaType<T> t, WrapperOptions o) {\n        throw new UnsupportedOperationException(\"I cannot convert anything from XML\");\n    }\n}","handlingStrategy":"try-catch","validationCode":"// verify the throwing mapper is actually registered before running the negative test\nboolean mapperRegistered = Arc.container().select(FormatMapper.class)\n    .stream().anyMatch(m -> m.getClass().getSimpleName().toLowerCase().contains(\"xml\"));","typeGuard":null,"tryCatchPattern":"try {\n    QuarkusTransaction.requiringNew().run(() -> em.persist(entity));\n    fail(\"expected flush to fail\");\n} catch (UnsupportedOperationException e) {\n    assertTrue(e.getMessage().contains(\"I cannot convert anything to XML\"), e.getMessage());\n}","preventionTips":["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"],"tags":["jpa","hibernate","xml","format-mapper","test-assertion"],"backgroundTag":"expected-exception-not-thrown","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}