fix: create deflater in DEFLATER mode in CompressionFilter#57
Conversation
onPreAdd() built the outbound deflater with Zlib.MODE_INFLATER instead of
MODE_DEFLATER, so every outbound write threw IllegalStateException ("not
initialized as DEFLATER") from Zlib.deflate(). Outbound compression was
completely broken.
The bug went unnoticed because CompressionFilterTest was @ignore'd with its
body commented out (it depended on EasyMock's removed MockControl API), so
CompressionFilter had no live coverage; ZlibTest only exercises Zlib directly.
Rewrite CompressionFilterTest with Mockito (replacing the unused EasyMock
dependency, already managed in the root pom) and add coverage for onPreAdd():
a compress/decompress round trip, and a guard that the deflater and inflater
are not swapped. Both tests fail against the buggy code.
Assisted-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks a lot Piotr, I was trying to reactivate the test that was commented (mostly due to the fact we were using an old version of easymock, and we just were too lazy to port it, which was a VERY bad idea...). Would this test been active, the original copy/paste mistake would never have been a problem :/ |
|
Ok, seems correct for 2.2.X. However I won't be able to backport the test because mockito 5 requires a Java version >= 11. Not such a big deal, as we can rely on 2.2.X for such tests, and backport the code but the test in 2.1.X and 2.0.X. |
|
Hi @ppkarwasz, I don't think we need to pass the size parameters for the deflater: instead of |
|
Mockito 4 should work IIRC. |
Yes, I added it for symmetry and in the previous PR I pushed the symmetry one step too far… 😆 |
|
@ppkarwasz works like a charm with mockito 4 on 2.1.X branch! I'm currently cutting the 3 releases, we should be good to go this week-end. Thanks for the help! |
What
Due to a copy/paste error in #52
CompressionFilter.onPreAdd()built the outbound deflater withZlib.MODE_INFLATERinstead ofMODE_DEFLATER, so every outbound write threwIllegalStateException("not initialized as DEFLATER") fromZlib.deflate(). Outbound compression was completely broken.Why it went unnoticed
CompressionFilterTestwas@Ignored with its body commented out (it depended on EasyMock's removedMockControlAPI), soCompressionFilterhad no live coverage.ZlibTestonly exercisesZlibdirectly, never going throughonPreAdd().Changes
MODE_DEFLATER.CompressionFilterTestwith Mockito, replacing the unused EasyMock dependency (Mockito is already managed in the root pom and used inmina-core).onPreAdd(): a compress/decompress round trip, and a guard that the deflater and inflater are not swapped.Both new tests fail against the buggy code with the expected
IllegalStateException, and pass with the fix.