quarkusio/quarkus · error · IllegalArgumentException
bad pet
Error message
bad pet
What it means
An IllegalArgumentException with message 'bad pet' is thrown inside the reactive messaging transaction of PetProducer.post when the pet name equals 'bad'. The pet is persisted within an emitter.withTransaction block and the exception rolls back the transaction, letting tests verify that Hibernate ORM transactions integrated with Kafka emitters are rolled back and the Kafka message is not sent.
Source
Thrown at integration-tests/reactive-messaging-hibernate-orm/src/main/java/io/quarkus/it/kafka/pet/PetProducer.java:28
import io.smallrye.mutiny.Uni;
import io.smallrye.reactive.messaging.kafka.transactions.KafkaTransactions;
@Path("/kafka")
public class PetProducer {
@Channel("pets")
KafkaTransactions<Pet> emitter;
@POST
@Path("/pets")
@Transactional
public void post(String name) {
Log.infov("Sending pet {0}", name);
Pet pet = new Pet(name);
emitter.withTransaction(e -> {
pet.persist();
if (pet.name.equals("bad")) {
throw new IllegalArgumentException("bad pet");
}
Log.infov("Persisted pet {0}", pet);
e.send(pet);
return Uni.createFrom().voidItem();
}).await().indefinitely();
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Post a pet name other than 'bad' to avoid the intentional rollback path.
- If seen in tests, it is expected — assert the DB has no persisted 'bad' pet and no Kafka message was produced.
- If persistence should succeed despite the marker name, remove/adjust the equality check or rename the sentinel value.
- Handle the failure on the caller side (onFailure) only if you explicitly intend to swallow the rollback.
Example fix
// before
if (pet.name.equals("bad")) {
throw new IllegalArgumentException("bad pet");
}
// after (guard at the resource level instead)
if ("bad".equals(name)) {
return Response.status(400).entity("invalid pet name").build();
} Defensive patterns
Strategy: validation
Validate before calling
if ("bad".equals(name)) {
// sentinel name: transaction will roll back and no Kafka message is sent
return Response.status(400).entity("invalid pet name").build();
} Type guard
boolean isSafePetName(String name) {
return name != null && !"bad".equals(name);
} Try / catch
try {
emitter.withTransaction(e -> { pet.persist(); e.send(pet); return Uni.createFrom().voidItem(); })
.await().indefinitely();
} catch (IllegalArgumentException e) {
if ("bad pet".equals(e.getMessage())) {
// transaction rolled back; message not published — expected sentinel path
}
throw e;
} Prevention
- Validate pet names at the REST boundary before entering the transactional producer.
- Remember persist() inside withTransaction rolls back when the callback throws.
- In tests, assert both DB state and Kafka (no record for the rolled-back pet).
- Avoid sentinel magic names in production; prefer explicit error responses.
When it happens
Trigger: POST to the pets endpoint with body 'bad' — pet.persist() succeeds but the exception aborts the withTransaction callback before e.send(pet), rolling back the DB insert.
Common situations: Testing the reactive-messaging-hibernate-orm integration (rollback semantics); a user posting a pet literally named 'bad' to a deployed instance will always get this failure.
Related errors
- @ExactlyOnce on method ${methodName} requires both @Incoming
- @ExactlyOnce on method ${methodName} must return a value to
- @ExactlyOnce on method ${methodName} cannot be combined with
- @ExactlyOnce on method ${methodName} cannot combine @WithTra
- @ExactlyOnce on method ${methodName} cannot combine @Transac
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/b7614219c139b4cf.
Report an issue: GitHub.