needsInput() returns true after finish()

Zhong Yu zhong.j.yu at
Sat Mar 10 03:59:12 UTC 2012

In, after finish() is called, needsInput() may
still return true. This is counter-intuitive.

It's probably not an issue in blocking style IO, since state is
implied by context, code (lexically) after finish() knows it doesn't
make sense to call needsInput().

In non-blocking IO, code needs another flag to remember that finish()
has been called, so that it won't call needsInput() again (which may
return a misleading true). That's an unnecessary chore, since Deflater
already contains the flag.

Suggested fix:
    public boolean needsInput() {
        synchronized (zsRef) {
            return !finish && len <= 0;

(I don't understand the `synchronized (zsRef)` part; this class should
only be used serially anyway. But if other methods require
synchronization, this method requires it too)

Zhong Yu

More information about the core-libs-dev mailing list