quarkusio/quarkus · warning · BadRequestException

Should provide name or color query parameter

Error message

Should provide name or color query parameter

What it means

A jakarta.ws.rs.BadRequestException (HTTP 400) thrown by the search endpoint of the elasticsearch-java-client test resource when neither the 'name' nor 'color' query parameter is supplied. The endpoint requires at least one search criterion to delegate to FruitService.

Source

Thrown at integration-tests/elasticsearch-java-client/src/main/java/io/quarkus/it/elasticsearch/java/FruitResource.java:51

        fruitService.index(fruit);
        return Response.created(URI.create("/fruits/" + fruit.id)).build();
    }

    @GET
    @Path("/{id}")
    public Fruit get(@PathParam("id") String id) throws IOException {
        return fruitService.get(id);
    }

    @GET
    @Path("/search")
    public List<Fruit> search(@QueryParam("name") String name, @QueryParam("color") String color) throws IOException {
        if (name != null) {
            return fruitService.searchByName(name);
        } else if (color != null) {
            return fruitService.searchByColor(color);
        } else {
            throw new BadRequestException("Should provide name or color query parameter");
        }
    }

    // This is just for tests, as it's bad practice to allow REST API callers
    // to just inject whatever JSON they like into your Elasticsearch requests.
    @GET
    @Path("/search/unsafe")
    public List<Fruit> searchUnsafe(@QueryParam("json") String json) throws IOException {
        return fruitService.searchWithJson(json);
    }

    @Path("bulk")
    @DELETE
    public Response delete(List<String> identityList) throws IOException {
        fruitService.delete(identityList);
        return Response.ok().build();
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Add a query parameter: ?name=apple or ?color=red.
  2. Fix the parameter name in the client to exactly 'name' or 'color'.
  3. If intentional, expect/assert the 400 response in tests.

Example fix

// before
GET /fruits/search
// after
GET /fruits/search?name=apple
Defensive patterns

Strategy: validation

Validate before calling

if ((name == null || name.isBlank()) && (color == null || color.isBlank())) {
    throw new IllegalArgumentException("Either name or color query parameter is required");
}

Type guard

null

Try / catch

try {
    List<Fruit> fruits = target("/fruits/search").queryParam("name", name).request().get(new GenericType<>() {});
} catch (jakarta.ws.rs.BadRequestException e) {
    log.error("Provide ?name or ?color");
}

Prevention

When it happens

Trigger: GET /fruits/search (or equivalent path) with no query parameters, or with parameters spelled differently (e.g. 'colour').

Common situations: Clients forgetting the query string entirely; parameter name typos; frontend sending empty-string values in some clients is fine (only null triggers it) but omitting them entirely triggers 400.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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