quarkusio/quarkus · warning · BadRequestException
Before and after name lengths do not match
Error message
Before and after name lengths do not match
What it means
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.
Source
Thrown at integration-tests/hibernate-orm-data/src/main/java/io/quarkus/it/hibernate/processor/data/security/SecuredMyEntityResource.java:183
}
@Path("/insert-all-1")
@POST
@Transactional
public void insertAll1(MyEntity entity) {
repository.insertAll1(List.of(entity));
}
@Path("/insert-all-2")
@POST
@Transactional
public void insertAll2(MyEntity entity) {
repository.insertAll2(List.of(entity));
}
private List<MyEntity> loadAndRenameEntities(@RestQuery String[] before, @RestQuery String[] after) {
if (before.length != after.length) {
throw new BadRequestException("Before and after name lengths do not match");
}
MyEntity[] entities = new MyEntity[before.length];
for (int i = 0; i < before.length; i++) {
entities[i] = getByName(before[i]);
entities[i].name = after[i];
}
return Arrays.asList(entities);
}
@PermissionChecker("find-for-donald")
boolean canFindForDonald(SecurityIdentity ignored) {
// grant permission "find-for-donald" if user requested it via header
return "find-for-donald".equals(httpHeaders.getHeaderString("dynamic-permission"));
}
}
View on GitHub (pinned to e1c734241f)
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
Example fix
// before GET /rename?before=a,b&after=x // after GET /rename?before=a,b&after=x,y
Defensive patterns
Strategy: validation
Validate before calling
if (before.length != after.length) throw new IllegalArgumentException("before/after arrays must have equal length"); Try / catch
try { rename(before, after); } catch (BadRequestException e) { log.warn("Rename rejected: {}", e.getMessage()); } Prevention
- 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
When it happens
Trigger: Calling loadAndRenameEntities via the rename endpoints (renameAllPermissions1And2, renameAllPermissions2And3, renameOverloadedSecured) with ?before=a,b&after=x (mismatched counts).
Common situations: 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.
Related errors
- Extra steps left over
- Unknown start character for json value: %s
- invalid char value: " + str
- invalid Character value:
- Should provide name or color query parameter
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/c647877da69a393d.
Report an issue: GitHub.