jruby/jruby · error · Zlib::StreamError

stream error

Error message

stream error

What it means

Error "stream error" thrown in jruby/jruby.

Source

Thrown at core/src/main/java/org/jruby/ext/zlib/JZlibDeflate.java:114

    public IRubyObject _initialize(ThreadContext context, IRubyObject[] args) {
        args = Arity.scanArgs(context, args, 0, 4);
        level = !args[0].isNil() ? checkLevel(context, toInt(context, args[0])) : -1;
        windowBits = !args[1].isNil() ? checkWindowBits(context, toInt(context, args[1]), false) : JZlib.MAX_WBITS;
        int memlevel = !args[2].isNil() ? toInt(context, args[2]) : 8; // ignored. Memory setting means nothing on Java.
        strategy = !args[3].isNil() ? toInt(context, args[3]) : 0;

        init(context, level, windowBits, memlevel, strategy);
        return this;
    }

    private void init(ThreadContext context, int level, int windowBits, int memlevel, int strategy) {
        flush = JZlib.Z_NO_FLUSH;
        flater = new com.jcraft.jzlib.Deflater();

        // TODO: Can we expect JZlib to check level, windowBits, and strategy here?
        // Then we should remove checkLevel, checkWindowsBits and checkStrategy.
        int err = flater.init(level, windowBits, memlevel);
        if (err == com.jcraft.jzlib.JZlib.Z_STREAM_ERROR) throw RubyZlib.newStreamError(context, "stream error");

        err = flater.params(level, strategy);
        if (err == com.jcraft.jzlib.JZlib.Z_STREAM_ERROR) throw RubyZlib.newStreamError(context, "stream error");

        collected = new byte[BASE_SIZE];
        collectedIdx = 0;
    }

    @JRubyMethod(visibility = PRIVATE)
    public IRubyObject initialize_copy(ThreadContext context, IRubyObject _other) {
        if (!(_other instanceof JZlibDeflate other)) throw typeError(context, "Expecting an instance of class JZlibDeflate");
        if (this == _other) return this;

        this.level = other.level;
        this.windowBits = other.windowBits;
        this.strategy = other.strategy;
        this.collected = new byte[other.collected.length];
        System.arraycopy(other.collected, 0, this.collected, 0, other.collected.length);

View on GitHub (pinned to fb650c13e0)

Solutions

  1. The zlib deflate stream reported an error, usually from an inconsistent stream state or invalid parameters. Recreate the deflater with valid level/strategy and feed well-formed input.

When it happens

Trigger: Thrown at core/src/main/java/org/jruby/ext/zlib/JZlibDeflate.java:114 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jruby/jruby@fb650c13e0 (2026-08-23). Data as JSON: /api/errors/1fb5272705adf7ac. Report an issue: GitHub.