Skip to content

Fix #1584: mark brotli4j as an optional dependency#1590

Open
andreasrosdalw wants to merge 3 commits into
LibrePDF:masterfrom
andreasrosdalw:fix-1584-brotli4j-optional
Open

Fix #1584: mark brotli4j as an optional dependency#1590
andreasrosdalw wants to merge 3 commits into
LibrePDF:masterfrom
andreasrosdalw:fix-1584-brotli4j-optional

Conversation

@andreasrosdalw

@andreasrosdalw andreasrosdalw commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1584.

brotli4j was declared as a regular compile-scope dependency, so every project depending on OpenPDF got it transitively. Libraries that detect brotli4j at runtime — e.g. Apache HttpClient 5, which registers a Brotli decompressor when it finds brotli4j on the classpath — would then try to use it and fail with UnsatisfiedLinkError because the JNI native library is not bundled.

Changes

  • openpdf-core/pom.xml: brotli4j is now <optional>true</optional>, matching the other optional dependencies (BouncyCastle, FOP, ICU4J). Brotli support in OpenPDF is opt-in anyway: Document.useBrotliCompression defaults to false, and BrotliFilter is only class-loaded when a PDF actually uses /BrotliDecode or the writer enables Brotli — consumers that never touch Brotli pay no cost and need no dependency.
  • BrotliFilter.ensureAvailable(): now also catches LinkageError. Without this, an absent (now optional) brotli4j would surface as a raw NoClassDefFoundError instead of the documented IOException. With it, users get a clear message with the Maven coordinates to add, and PdfWriter.setUseBrotliCompression(true) keeps its graceful fallback to Flate.
  • README.md: Brotli4j documented as optional, with the dependency snippet to add for Brotli support.

Tests

BrotliPDFTest still passes (the module's own test classpath is unaffected by <optional>). Consumers without brotli4j now get a descriptive IOException / Flate fallback instead of NoClassDefFoundError when touching the Brotli API, and are simply unaffected otherwise.

brotli4j was a regular compile-scope dependency, so every project using
OpenPDF got it transitively. Libraries that detect brotli4j at runtime
(e.g. Apache HttpClient 5) would then try to use it and fail with
UnsatisfiedLinkError because the JNI native library is not bundled.

Brotli support in OpenPDF is opt-in (Document.useBrotliCompression
defaults to false and BrotliFilter is only loaded when a PDF actually
uses /BrotliDecode), so the dependency is now <optional>true</optional>,
matching the other optional dependencies (BouncyCastle, FOP, ICU4J).

BrotliFilter.ensureAvailable() now also catches LinkageError, so when
brotli4j is absent from the classpath entirely, callers get the
documented IOException with the Maven coordinates to add instead of a
raw NoClassDefFoundError, and PdfWriter.setUseBrotliCompression(true)
falls back to Flate gracefully. README updated to document brotli4j as
optional.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Jul 21, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

andreasrosdalw and others added 2 commits July 21, 2026 09:47
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

brotli4j dependency should be marked optional in POM

1 participant