java.util.zip.Deflater: needsInput() returns true after finish()
Zhong Yu
zhong.j.yu at gmail.com
Sat Mar 10 03:59:12 UTC 2012
In java.util.zip.Deflater, 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:
java.util.zip.Deflater
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)
Regards,
Zhong Yu
More information about the core-libs-dev
mailing list