Fix #1584: mark brotli4j as an optional dependency#1590
Open
andreasrosdalw wants to merge 3 commits into
Open
Conversation
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>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
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.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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
UnsatisfiedLinkErrorbecause 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.useBrotliCompressiondefaults tofalse, andBrotliFilteris only class-loaded when a PDF actually uses/BrotliDecodeor the writer enables Brotli — consumers that never touch Brotli pay no cost and need no dependency.BrotliFilter.ensureAvailable(): now also catchesLinkageError. Without this, an absent (now optional) brotli4j would surface as a rawNoClassDefFoundErrorinstead of the documentedIOException. With it, users get a clear message with the Maven coordinates to add, andPdfWriter.setUseBrotliCompression(true)keeps its graceful fallback to Flate.README.md: Brotli4j documented as optional, with the dependency snippet to add for Brotli support.Tests
BrotliPDFTeststill passes (the module's own test classpath is unaffected by<optional>). Consumers without brotli4j now get a descriptiveIOException/ Flate fallback instead ofNoClassDefFoundErrorwhen touching the Brotli API, and are simply unaffected otherwise.