quarkusio/quarkus · error · IllegalArgumentException

Currently only 'fruitsFindBy?type=name' is supported

Error message

Currently only 'fruitsFindBy?type=name' is supported

What it means

A plain IllegalArgumentException thrown by the private findBy helper of FruitResource to signal that only the query type 'name' is implemented for the fruitsFindBy endpoint. It is a developer/client contract guard: any @QueryParam("type") other than 'name' (case-insensitive) is rejected. As an uncaught IllegalArgumentException in a JAX-RS resource it typically surfaces as HTTP 500 rather than a clean 400.

Source

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

        entityManager.remove(fruit);
        return Response.status(204).build();
    }

    @GET
    @Path("fruitsFindBy")
    public Response findByDefault(@NotNull @QueryParam("type") String type, @NotNull @QueryParam("value") String value) {
        return findBy(type, value);
    }

    @GET
    @Path("{tenant}/fruitsFindBy")
    public Response findByTenant(@NotNull @QueryParam("type") String type, @NotNull @QueryParam("value") String value) {
        return findBy(type, value);
    }

    private Response findBy(@NotNull String type, @NotNull String value) {
        if (!"name".equalsIgnoreCase(type)) {
            throw new IllegalArgumentException("Currently only 'fruitsFindBy?type=name' is supported");
        }
        List<Fruit> list = entityManager.createNamedQuery("Fruits.findByName", Fruit.class).setParameter("name", value)
                .getResultList();
        if (list.size() == 0) {
            return Response.status(404).build();
        }
        Fruit fruit = list.get(0);
        return Response.status(200).entity(fruit).build();
    }

    @Provider
    public static class ErrorMapper implements ExceptionMapper<Exception> {

        @Override
        public Response toResponse(Exception exception) {
            LOG.error("Failed to handle request", exception);

            int code = 500;

View on GitHub (pinned to e1c734241f)

Solutions

  1. Use type=name in the query string: GET /fruitsFindBy?type=name&value=<fruit name>
  2. If you need another search field, extend findBy with an additional branch (e.g. by id) and map it to an appropriate named query
  3. Map IllegalArgumentException to HTTP 400 with an ExceptionMapper for a cleaner client contract

Example fix

// before
if (!"name".equalsIgnoreCase(type)) {
    throw new IllegalArgumentException("Currently only 'fruitsFindBy?type=name' is supported");
}
// after
if ("id".equalsIgnoreCase(type)) {
    list = entityManager.createNamedQuery("Fruits.findById", Fruit.class).setParameter("id", Long.valueOf(value)).getResultList();
} else if (!"name".equalsIgnoreCase(type)) {
    throw new BadRequestException("Currently only 'fruitsFindBy?type=name' is supported");
}
Defensive patterns

Strategy: validation

Validate before calling

if (!"name".equalsIgnoreCase(type)) {
    throw new IllegalArgumentException("Only type=name is supported by fruitsFindBy");
}

Try / catch

try {
    given().get("/fruitsFindBy?type=" + type + "&value=" + value);
} catch (Exception e) {
    // fall back to type=name or fix the query parameter
}

Prevention

When it happens

Trigger: Calling GET /fruitsFindBy?type=<anything-but-name>&value=... through either the public findByDefault or findByTenant endpoints, e.g. type=id, type=colour, or a misspelled type value.

Common situations: Client assumes richer query support than the test resource implements; API evolution where new type values were expected but never implemented; typo in query parameter value ('Name ' with space passes equalsIgnoreCase? no — trailing space fails).

Related errors


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