quarkusio/quarkus · warning · AssertionError
flush failed for a different reason than expected.
Error message
flush failed for a different reason than expected.
What it means
In the same json endpoint, after catching the expected flush failure the test validates that the exception is an UnsupportedOperationException whose message contains 'I cannot convert anything to JSON'. Any other exception type or message triggers this AssertionError, indicating the flush failed for an unanticipated reason.
Source
Thrown at integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java:172
Exception exception = null;
try {
QuarkusTransaction.requiringNew().run(() -> {
EntityWithJsonOtherPU otherPU = new EntityWithJsonOtherPU(
new EntityWithJsonOtherPU.ToBeSerializedWithDateTime(LocalDate.of(2023, 7, 28)));
otherEm.persist(otherPU);
});
} catch (Exception e) {
exception = e;
}
if (exception == null) {
throw new AssertionError(
"Default mapper cannot process date/time properties. So we were expecting transaction to fail, but it did not!");
}
if (!(exception instanceof UnsupportedOperationException)
|| !exception.getMessage().contains("I cannot convert anything to JSON")) {
throw new AssertionError("flush failed for a different reason than expected.", exception);
}
return "OK";
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Log the caught exception's class and message to see the actual failure
- Verify the json column exists with the correct type in the PostgreSQL schema
- Check that no custom mapper replaced the default JSON mapper
- Align the assertion with the exception type/message produced by the current Hibernate version
Example fix
// before
if (!(exception instanceof UnsupportedOperationException)
|| !exception.getMessage().contains("I cannot convert anything to JSON")) {
throw new AssertionError("flush failed for a different reason than expected.", exception);
}
// after (diagnostic first)
System.out.println("caught: " + exception.getClass() + ": " + exception.getMessage()); Defensive patterns
Strategy: try-catch
Validate before calling
// inspect actual failure before asserting
if (exception != null) {
System.out.println("caught " + exception.getClass().getName() + ": " + exception.getMessage());
} Try / catch
try {
em.flush();
} catch (UnsupportedOperationException e) {
if (!e.getMessage().contains("I cannot convert anything to JSON")) {
throw new AssertionError("unexpected mapper message", e);
}
} catch (RuntimeException e) {
throw new AssertionError("flush failed for an unexpected reason", e);
} Prevention
- Catch specific exception types separately from generic RuntimeException
- Verify schema/json column types when flush fails
- Re-check assertion strings after upgrading Hibernate versions
- Log the full exception chain for wrapped persistence errors
When it happens
Trigger: Flush during persist of a JSON entity failing with an unexpected exception — e.g. SQLException from PostgreSQL, ClassCastException in the JSON binder, or a wrapped constraint violation — instead of the mapper's UnsupportedOperationException.
Common situations: Schema mismatch (column not json type), serialization errors from a custom ObjectMapper, Hibernate version upgrade changing exception wrapping, or connection/schema errors during flush.
Related errors
- Default mapper cannot process date/time properties. So we we
- No entities with json were found
- Incorrect number of results
- Incorrect number of results
- Incorrect order of results
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/fd77c0aabc0703d9.
Report an issue: GitHub.