MuntashirAkon/AppManager · error · IllegalArgumentException
buffersize must be bigger than 0
Error message
buffersize must be bigger than 0
What it means
IOUtils.copy(InputStream,OutputStream,int) allocates a byte[buffersize] transfer buffer and rejects buffersize < 1 with IllegalArgumentException, since a zero/negative buffer can never be allocated or used for reads.
Solutions
- Pass a positive buffersize, e.g. 8192 (8 KB, a common default)
- Validate/clamp the configured buffer size before calling
- Use the two-argument IOUtils.copy(input, output) overload which picks a sane default
Example fix
// before IOUtils.copy(in, out, bufferSize); // bufferSize == 0 // after IOUtils.copy(in, out, Math.max(1, bufferSize));
Defensive patterns
Strategy: validation
Validate before calling
if (buffersize < 1) throw new IllegalArgumentException("buffersize must be >= 1"); Try / catch
try { IOUtils.copy(in, out, size); } catch (IllegalArgumentException e) { if (e.getMessage().contains("buffersize")) { IOUtils.copy(in, out, 8192); } else throw e; } Prevention
- Use the two-arg copy() overload when no custom size is needed
- Sanitize configured buffer sizes with Math.max(1, size)
- Guard against arithmetic that can underflow the size computation
When it happens
Trigger: Calling IOUtils.copy(input, output, 0) or with a negative buffersize, e.g. passing a user-configured chunk size that defaulted to 0 or a subtraction that yielded <= 0.
Common situations: Config file with buffersize=0; integer arithmetic overflow/underflow computing the size; copying the two-arg copy() signature but adding 0 as buffer size.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Bad mode
- Buffer size %,d must be at least
- count must not be negative or greater than " +…
- len(" + len + ") < 0.
- len(" + len + ") < 0.
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/7a9d37f53ae728ea.
Report an issue: GitHub.
Appendix: source
Thrown at app/src/main/java/org/apache/commons/compress/utils/IOUtils.java:66
/**
* Copies the content of a InputStream into an OutputStream
*
* @param input
* the InputStream to copy
* @param output
* the target Stream
* @param buffersize
* the buffer size to use, must be bigger than 0
* @return the number of bytes copied
* @throws IOException
* if an error occurs
* @throws IllegalArgumentException
* if buffersize is smaller than or equal to 0
*/
public static long copy(final InputStream input, final OutputStream output, final int buffersize) throws IOException {
if (buffersize < 1) {
throw new IllegalArgumentException("buffersize must be bigger than 0");
}
final byte[] buffer = new byte[buffersize];
int n = 0;
long count=0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
/**
* Skips the given number of bytes by repeatedly invoking skip on
* the given input stream if necessary.
*
* <p>In a case where the stream's skip() method returns 0 before
* the requested number of bytes has been skip this implementation
* will fall back to using the read() method.</p>View on GitHub (pinned to 0152f468fc)