{"record":{"id":"c647877da69a393d","repo":"quarkusio/quarkus","slug":"before-and-after-name-lengths-do-not-match","errorCode":null,"errorMessage":"Before and after name lengths do not match","messagePattern":"Before and after name lengths do not match","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"integration-tests/hibernate-orm-data/src/main/java/io/quarkus/it/hibernate/processor/data/security/SecuredMyEntityResource.java","lineNumber":183,"sourceCode":"    }\n\n    @Path(\"/insert-all-1\")\n    @POST\n    @Transactional\n    public void insertAll1(MyEntity entity) {\n        repository.insertAll1(List.of(entity));\n    }\n\n    @Path(\"/insert-all-2\")\n    @POST\n    @Transactional\n    public void insertAll2(MyEntity entity) {\n        repository.insertAll2(List.of(entity));\n    }\n\n    private List<MyEntity> loadAndRenameEntities(@RestQuery String[] before, @RestQuery String[] after) {\n        if (before.length != after.length) {\n            throw new BadRequestException(\"Before and after name lengths do not match\");\n        }\n        MyEntity[] entities = new MyEntity[before.length];\n        for (int i = 0; i < before.length; i++) {\n            entities[i] = getByName(before[i]);\n            entities[i].name = after[i];\n        }\n        return Arrays.asList(entities);\n    }\n\n    @PermissionChecker(\"find-for-donald\")\n    boolean canFindForDonald(SecurityIdentity ignored) {\n        // grant permission \"find-for-donald\" if user requested it via header\n        return \"find-for-donald\".equals(httpHeaders.getHeaderString(\"dynamic-permission\"));\n    }\n}\n","sourceCodeStart":165,"sourceCodeEnd":199,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-data/src/main/java/io/quarkus/it/hibernate/processor/data/security/SecuredMyEntityResource.java#L165-L199","documentation":"This REST resource method renames entities by pairing each 'before' name with an 'after' name positionally. If the two query-parameter arrays differ in length, no valid pairing exists, so a BadRequestException (400) is thrown by design.","triggerScenarios":"Calling loadAndRenameEntities via the rename endpoints (renameAllPermissions1And2, renameAllPermissions2And3, renameOverloadedSecured) with ?before=a,b&after=x (mismatched counts).","commonSituations":"Manually constructing the query string and forgetting a value, programmatic clients joining arrays with commas where an element is dropped, or URL encoding swallowing an empty value.","solutions":["Make the before and after query arrays the same length","Check for empty values being dropped (e.g. 'a,,b' splitting) in your client","Inspect the actual request URL logged by the test/server to see the parsed arrays"],"exampleFix":"// before\nGET /rename?before=a,b&after=x\n// after\nGET /rename?before=a,b&after=x,y","handlingStrategy":"validation","validationCode":"if (before.length != after.length) throw new IllegalArgumentException(\"before/after arrays must have equal length\");","typeGuard":null,"tryCatchPattern":"try { rename(before, after); } catch (BadRequestException e) { log.warn(\"Rename rejected: {}\", e.getMessage()); }","preventionTips":["Build before/after pairs from a single Map<String,String> so lengths cannot diverge","Validate array lengths client-side before issuing the request","Avoid joining arrays with commas when values may be empty"],"tags":["rest","validation","bad-request","security-test"],"backgroundTag":"request-parameter-mismatch","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}