quarkusio/quarkus · error · IllegalArgumentException
Different array length
Error message
Different array length
What it means
IllegalArgumentException from PausableHttpPostRequestEncoder.addBodyFileUploads: the parallel arrays passed for a multi-file upload parameter (files, contentTypes, isText) have different lengths. Each file needs exactly one content type and one isText flag; the array length mismatch is the fault.
Source
Thrown at independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/PausableHttpPostRequestEncoder.java:493
* Add a series of Files associated with one File parameter
*
* @param name
* the name of the parameter
* @param file
* the array of files
* @param contentType
* the array of content Types associated with each file
* @param isText
* the array of isText attribute (False meaning binary mode) for each file
* @throws IllegalArgumentException
* also throws if array have different sizes
* @throws ErrorDataEncoderException
* if the encoding is in error or if the finalize were already done
*/
public void addBodyFileUploads(String name, File[] file, String[] contentType, boolean[] isText)
throws ErrorDataEncoderException {
if (file.length != contentType.length && file.length != isText.length) {
throw new IllegalArgumentException("Different array length");
}
for (int i = 0; i < file.length; i++) {
addBodyFileUpload(name, file[i], contentType[i], isText[i]);
}
}
/**
* Add the InterfaceHttpData to the Body list
*
* @throws NullPointerException
* for data
* @throws ErrorDataEncoderException
* if the encoding is in error or if the finalize were already done
*/
public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderException {
if (headerFinalized) {
throw new ErrorDataEncoderException("Cannot add value once finalized");
}View on GitHub (pinned to e1c734241f)
Solutions
- Pad missing content types with a sensible default (e.g. application/octet-stream) before the call
- Assert array lengths are equal before calling addBodyFileUploads
- Switch to calling addBodyFileUpload per file to avoid parallel-array pitfalls
Example fix
// before
encoder.addBodyFileUploads("files", files, contentTypes, isTextFlags);
// after
if (files.length != contentTypes.length || files.length != isTextFlags.length) {
throw new IllegalStateException("arrays must match");
}
encoder.addBodyFileUploads("files", files, contentTypes, isTextFlags); Defensive patterns
Strategy: validation
Validate before calling
if (file.length != contentType.length || file.length != isText.length) { throw new IllegalArgumentException("arrays must have equal length"); } Type guard
null
Try / catch
try { encoder.addBodyFileUploads(name, files, types, flags); } catch (IllegalArgumentException e) { /* fix arrays or add one-by-one */ } Prevention
- Prefer a small record/DTO list over parallel arrays
- Default missing content types to application/octet-stream
- Validate array lengths in a helper before batch uploads
When it happens
Trigger: Calling addBodyFileUploads with arrays of mismatched lengths, e.g. file.length=2 but contentType.length=1.
Common situations: Building parallel arrays programmatically and skipping an entry for a file with unknown content type; refactoring single-upload code to batch mode.
Related errors
- setting content of MultiByteHttpData is not supported
- adding content to MultiByteHttpData is not supported
- getting all the contents of a MultiByteHttpData is not suppo
- MultiByteHttpData invoked on an invalid context :
- Reading MultiByteHttpData as String is not supported
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/b61dfe11adf4f6b5.
Report an issue: GitHub.