quarkusio/quarkus · error · WebApplicationException

Fruit Name was not set on request.

Error message

Fruit Name was not set on request.

What it means

The PUT update endpoint requires the request body to carry a fruit name; a null name cannot update the entity so the resource fails fast with HTTP 422 (Unprocessable Entity) via WebApplicationException. This is an application-level validation guard, not a framework error.

Source

Thrown at integration-tests/hibernate-search-orm-elasticsearch-tenancy/src/main/java/io/quarkus/it/hibernate/search/orm/elasticsearch/multitenancy/fruit/FruitResource.java:74

    @POST
    @Path("/")
    @Transactional
    public Response create(@NotNull Fruit fruit) {
        if (fruit.getId() != null) {
            throw new WebApplicationException("Id was invalidly set on request.", 422);
        }
        LOG.debugv("Create {0}", fruit.getName());
        entityManager.persist(fruit);
        return Response.ok(fruit).status(Response.Status.CREATED).build();
    }

    @PUT
    @Path("/{id}")
    @Transactional
    public Fruit update(@NotNull @PathParam("id") int id, @NotNull Fruit fruit) {
        if (fruit.getName() == null) {
            throw new WebApplicationException("Fruit Name was not set on request.", 422);
        }

        Fruit entity = entityManager.find(Fruit.class, id);
        if (entity == null) {
            throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404);
        }
        entity.setName(fruit.getName());

        LOG.debugv("Update #{0} {1}", fruit.getId(), fruit.getName());

        return entity;
    }

    @DELETE
    @Path("/{id}")
    @Transactional
    public Response delete(@NotNull @PathParam("id") int id) {
        Fruit fruit = entityManager.getReference(Fruit.class, id);

View on GitHub (pinned to e1c734241f)

Solutions

  1. Include a non-null "name" in the PUT request body
  2. Client-side validate that name is present before sending
  3. Use JSON Patch or a dedicated partial-update DTO if partial updates are intended
  4. Add @NotNull on the entity/DTO field to get standard Bean Validation 400 responses

Example fix

// before
PUT /fruits/1
{}

// after
PUT /fruits/1
{"name": "Apple"}
Defensive patterns

Strategy: validation

Validate before calling

if (fruit.getName() == null || fruit.getName().isBlank()) {
    throw new IllegalArgumentException("name is required for update");
}

Type guard

boolean isValidForUpdate(Fruit f) {
    return f != null && f.getName() != null && !f.getName().isBlank();
}

Try / catch

try {
    Response r = target.path("/fruits/" + id).request().put(Entity.json(fruit));
    if (r.getStatus() == 422) { /* name missing in payload */ }
} catch (WebApplicationException e) {
    if (e.getResponse().getStatus() == 422) { /* prompt user for name */ }
}

Prevention

When it happens

Trigger: PUT /fruits/{id} with a JSON body missing the "name" field or explicitly containing "name": null.

Common situations: Frontend partial-update forms that only send changed fields; clients that renamed the JSON property; serialization configured to skip null/empty fields; clients performing a PUT with an empty object {}.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/3be8092fe4373d71. Report an issue: GitHub.