Skip to content

fix: create deflater in DEFLATER mode in CompressionFilter#57

Merged
elecharny merged 1 commit into
apache:2.2.Xfrom
ppkarwasz:fix/deflater-inflater-swap
Jun 12, 2026
Merged

fix: create deflater in DEFLATER mode in CompressionFilter#57
elecharny merged 1 commit into
apache:2.2.Xfrom
ppkarwasz:fix/deflater-inflater-swap

Conversation

@ppkarwasz

@ppkarwasz ppkarwasz commented Jun 12, 2026

Copy link
Copy Markdown
Member

What

Due to a copy/paste error in #52 CompressionFilter.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.

Why it went unnoticed

CompressionFilterTest was @Ignored with its body commented out (it depended on EasyMock's removed MockControl API), so CompressionFilter had no live coverage. ZlibTest only exercises Zlib directly, never going through onPreAdd().

Changes

  • One-line fix: deflater is now created with MODE_DEFLATER.
  • Rewrote CompressionFilterTest with Mockito, replacing the unused EasyMock dependency (Mockito is already managed in the root pom and used in mina-core).
  • Added coverage for 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.

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>
@elecharny

Copy link
Copy Markdown
Contributor

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 :/

@elecharny elecharny merged commit a48effc into apache:2.2.X Jun 12, 2026
5 of 9 checks passed
@elecharny

Copy link
Copy Markdown
Contributor

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.

@elecharny

Copy link
Copy Markdown
Contributor

Hi @ppkarwasz, I don't think we need to pass the size parameters for the deflater:

        Zlib deflater = new Zlib(compressionLevel, Zlib.MODE_DEFLATER);

instead of

        Zlib deflater = new Zlib(compressionLevel, Zlib.MODE_DEFLATER, maxDecompressedSize, 
                maxDecompressRatio, decompressRatioMinSize);

@ppkarwasz

Copy link
Copy Markdown
Member Author

Mockito 4 should work IIRC.

@ppkarwasz

Copy link
Copy Markdown
Member Author

I don't think we need to pass the size parameters for the deflater:

Yes, I added it for symmetry and in the previous PR I pushed the symmetry one step too far… 😆

@elecharny

Copy link
Copy Markdown
Contributor

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants