{"record":{"id":"d0ac6e20e63c6360","repo":"quarkusio/quarkus","slug":"should-provide-name-or-color-query-parameter","errorCode":null,"errorMessage":"Should provide name or color query parameter","messagePattern":"Should provide name or color query parameter","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"integration-tests/elasticsearch-java-client/src/main/java/io/quarkus/it/elasticsearch/java/FruitResource.java","lineNumber":51,"sourceCode":"        fruitService.index(fruit);\n        return Response.created(URI.create(\"/fruits/\" + fruit.id)).build();\n    }\n\n    @GET\n    @Path(\"/{id}\")\n    public Fruit get(@PathParam(\"id\") String id) throws IOException {\n        return fruitService.get(id);\n    }\n\n    @GET\n    @Path(\"/search\")\n    public List<Fruit> search(@QueryParam(\"name\") String name, @QueryParam(\"color\") String color) throws IOException {\n        if (name != null) {\n            return fruitService.searchByName(name);\n        } else if (color != null) {\n            return fruitService.searchByColor(color);\n        } else {\n            throw new BadRequestException(\"Should provide name or color query parameter\");\n        }\n    }\n\n    // This is just for tests, as it's bad practice to allow REST API callers\n    // to just inject whatever JSON they like into your Elasticsearch requests.\n    @GET\n    @Path(\"/search/unsafe\")\n    public List<Fruit> searchUnsafe(@QueryParam(\"json\") String json) throws IOException {\n        return fruitService.searchWithJson(json);\n    }\n\n    @Path(\"bulk\")\n    @DELETE\n    public Response delete(List<String> identityList) throws IOException {\n        fruitService.delete(identityList);\n        return Response.ok().build();\n    }\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/elasticsearch-java-client/src/main/java/io/quarkus/it/elasticsearch/java/FruitResource.java#L33-L69","documentation":"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.","triggerScenarios":"GET /fruits/search (or equivalent path) with no query parameters, or with parameters spelled differently (e.g. 'colour').","commonSituations":"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.","solutions":["Add a query parameter: ?name=apple or ?color=red.","Fix the parameter name in the client to exactly 'name' or 'color'.","If intentional, expect/assert the 400 response in tests."],"exampleFix":"// before\nGET /fruits/search\n// after\nGET /fruits/search?name=apple","handlingStrategy":"validation","validationCode":"if ((name == null || name.isBlank()) && (color == null || color.isBlank())) {\n    throw new IllegalArgumentException(\"Either name or color query parameter is required\");\n}","typeGuard":"null","tryCatchPattern":"try {\n    List<Fruit> fruits = target(\"/fruits/search\").queryParam(\"name\", name).request().get(new GenericType<>() {});\n} catch (jakarta.ws.rs.BadRequestException e) {\n    log.error(\"Provide ?name or ?color\");\n}","preventionTips":["Always attach at least one of name/color to search requests.","Validate query parameters in the client before sending.","Keep client parameter names in sync with the resource signature."],"tags":["rest","elasticsearch","bad-request"],"backgroundTag":"missing-required-argument","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}