MuntashirAkon/AppManager · error · IllegalArgumentException

Invalid gzip compression level: " + compressionLevel

Error message

Invalid gzip compression level: " + compressionLevel

What it means

GzipParameters.setCompressionLevel validates the level against the zlib range: only -1 (DEFAULT_COMPRESSION) through 9 (BEST_COMPRESSION) are legal. Values outside that range are rejected with IllegalArgumentException before they can reach the native deflater.

Solutions

  1. Use a value between -1 and 9, e.g. Deflater.DEFAULT_COMPRESSION (-1), BEST_SPEED (1), or BEST_COMPRESSION (9)
  2. Clamp or validate user/config input before calling setCompressionLevel
  3. Use the built-in constants instead of magic numbers

Example fix

// before
params.setCompressionLevel(10); // IllegalArgumentException
// after
params.setCompressionLevel(Deflater.BEST_COMPRESSION); // 9
Defensive patterns

Strategy: validation

Validate before calling

if (level < -1 || level > 9) throw new IllegalArgumentException("gzip level must be -1..9, got " + level);

Try / catch

try { params.setCompressionLevel(level); } catch (IllegalArgumentException e) { log.warn(e.getMessage()); params.setCompressionLevel(Deflater.DEFAULT_COMPRESSION); }

Prevention

When it happens

Trigger: Calling setCompressionLevel with any int < -1 or > 9, e.g. 0, 10, or an uninitialized/miscomputed variable.

Common situations: Confusing 1-9 scale with 0-9 or 0-100 scales from other libraries; using a constant from a different API (e.g. Deflater.BEST_COMPRESSION misuse); passing user-supplied config without clamping.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/5050695b4ddc2b66. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/org/apache/commons/compress/compressors/gzip/GzipParameters.java:36

    private String comment;
    private int operatingSystem = 255; // Unknown OS by default

    public int getCompressionLevel() {
        return compressionLevel;
    }

    /**
     * Sets the compression level.
     *
     * @param compressionLevel the compression level (between 0 and 9)
     * @see Deflater#NO_COMPRESSION
     * @see Deflater#BEST_SPEED
     * @see Deflater#DEFAULT_COMPRESSION
     * @see Deflater#BEST_COMPRESSION
     */
    public void setCompressionLevel(final int compressionLevel) {
        if (compressionLevel < -1 || compressionLevel > 9) {
            throw new IllegalArgumentException("Invalid gzip compression level: " + compressionLevel);
        }
        this.compressionLevel = compressionLevel;
    }

    public long getModificationTime() {
        return modificationTime;
    }

    /**
     * Sets the modification time of the compressed file.
     *
     * @param modificationTime the modification time, in milliseconds
     */
    public void setModificationTime(final long modificationTime) {
        this.modificationTime = modificationTime;
    }

    public String getFilename() {

View on GitHub (pinned to 0152f468fc)