Skip to content

refactor: update PDFium library version to 0.15.0 and improve native library loading with system property support#33

Merged
balazs-szucs merged 3 commits intogrimmory-tools:mainfrom
balazs-szucs:INIT
Apr 21, 2026
Merged

refactor: update PDFium library version to 0.15.0 and improve native library loading with system property support#33
balazs-szucs merged 3 commits intogrimmory-tools:mainfrom
balazs-szucs:INIT

Conversation

@balazs-szucs
Copy link
Copy Markdown
Member

@balazs-szucs balazs-szucs commented Apr 21, 2026

Summary by CodeRabbit

Release Notes v0.15.0

  • New Features

    • Added isAvailable() method to check if PDFium initialized successfully
    • Added loadError() method to retrieve initialization failure details
    • Added system properties to customize library path and auto-initialization behavior
  • Bug Fixes

    • Improved error messages with clearer guidance when native library loading fails
  • Chores

    • Version bump to 0.15.0

…library loading with system property support
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Warning

Rate limit exceeded

@balazs-szucs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 52 minutes and 12 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 52 minutes and 12 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 26e8f499-2a8d-4d4f-8302-7534c99043d2

📥 Commits

Reviewing files that changed from the base of the PR and between 15bcd2f and 02c0ec7.

📒 Files selected for processing (2)
  • src/main/java/org/grimmory/pdfium4j/PdfiumLibrary.java
  • src/main/java/org/grimmory/pdfium4j/internal/NativeLoader.java
📝 Walkthrough

Walkthrough

Version bump from 0.14.0 to 0.15.0 accompanied by refactoring of PDFium native library initialization using an initialization-on-demand holder pattern, plus new public APIs for availability checks and custom library path support via system properties.

Changes

Cohort / File(s) Summary
Version Update
build.gradle.kts
Bumped project version from 0.14.0 to 0.15.0.
Initialization Mechanism
src/main/java/org/grimmory/pdfium4j/PdfiumLibrary.java
Replaced synchronized initialization with initialization-on-demand holder pattern; added public constants PROP_LIBRARY_PATH and PROP_AUTOINIT; introduced isAvailable() and loadError() public methods; removed synchronized keyword from initialize(); centralized error handling in holder's State class.
Native Library Loading
src/main/java/org/grimmory/pdfium4j/internal/NativeLoader.java
Added support for pdfium4j.library.path system property to load custom library path; improved error messages; refactored exception handling to always wrap failures in NativeLoadException.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

backend, enhancement

Poem

🐰 A holder pattern hops into view,
Native paths now bend to what's true,
Initialization-on-demand takes its place,
Errors surfaced without the race,
Version bumps to 0.15, on we go! 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title follows the conventional commit format with a clear 'refactor:' prefix and accurately describes the main changes: version update to 0.15.0 and improvements to native library loading with system property support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added enhancement New feature or request backend labels Apr 21, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/org/grimmory/pdfium4j/internal/NativeLoader.java`:
- Around line 42-64: The override-path branch using
System.getProperty(PROP_LIBRARY_PATH) currently catches UnsatisfiedLinkError,
wraps it in NativeLoadException and assigns loadError but then returns to the
outer try/catch where the outer catch (NativeLoadException) allows fall-through
to System.loadLibrary("pdfium"); change the logic so that when an override path
was attempted you rethrow the NativeLoadException (or propagate it) instead of
letting outer catch fall back: add a boolean flag (e.g., overrideAttempted) set
when PROP_LIBRARY_PATH is non-null, set loadError and throw the
NativeLoadException immediately on failure in the override block, and in the
outer catch check overrideAttempted (or detect loadError from override) and
rethrow the original NativeLoadException rather than calling
System.loadLibrary("pdfium"); also add a unit test that sets
pdfium4j.library.path to a nonexistent absolute path and asserts the thrown
error is the override failure (from NativeLoadException) and no system-library
fallback occurs.

In `@src/main/java/org/grimmory/pdfium4j/PdfiumLibrary.java`:
- Around line 60-62: The initialize() method currently dereferences Holder.STATE
which forces State construction and native init even when
pdfium4j.autoinit=false; change PdfiumLibrary.initialize() to first read the
"pdfium4j.autoinit" system/property flag and only call Holder.STATE.require()
when autoinit is true. Also audit any other places that access Holder.STATE (the
block around the other referenced code at lines ~95-104) and replace direct
static dereferences with conditional checks or a safe accessor so that
Holder.STATE is not constructed unless autoinit is enabled or an explicit
initialize() was requested.
- Around line 86-93: The loadError() accessor must not trigger Holder.STATE
initialization; introduce a private static volatile Throwable field (e.g.
publishedLoadError) on PdfiumLibrary and change loadError() to return that field
directly instead of referencing Holder.STATE. Update the Holder.STATE/State
construction code so that when initialization runs it catches and stores any
Throwable into PdfiumLibrary.publishedLoadError (publishing failures) without
requiring callers to access Holder.STATE, and ensure State's constructor does
not rely on lazy accessors that would be invoked by loadError().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3505e43e-2baa-496f-8c3e-b92e7c091534

📥 Commits

Reviewing files that changed from the base of the PR and between 7eee063 and 15bcd2f.

📒 Files selected for processing (3)
  • build.gradle.kts
  • src/main/java/org/grimmory/pdfium4j/PdfiumLibrary.java
  • src/main/java/org/grimmory/pdfium4j/internal/NativeLoader.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🧰 Additional context used
🪛 PMD (7.23.0)
src/main/java/org/grimmory/pdfium4j/internal/NativeLoader.java

[Medium] 46-46: The value assigned to field 'loaded' is never used (overwritten on line 67) (UnusedAssignment)

(Best Practices)

🔇 Additional comments (1)
build.gradle.kts (1)

16-16: Backward compatibility confirmed for the minor version bump.

The version bump from 0.14.0 to 0.15.0 maintains backward compatibility. Verification confirms that all public APIs—including PdfDocument.probe(), PdfDocument.koReaderPartialMd5(), and KoReaderChecksum.calculate() methods—remain intact and unchanged. No public methods were removed or modified in breaking ways, and no deprecation annotations were added. The minor version increment is appropriate for this release.

Comment thread src/main/java/org/grimmory/pdfium4j/internal/NativeLoader.java Outdated
Comment thread src/main/java/org/grimmory/pdfium4j/PdfiumLibrary.java
Comment thread src/main/java/org/grimmory/pdfium4j/PdfiumLibrary.java
@balazs-szucs balazs-szucs merged commit b6ced0a into grimmory-tools:main Apr 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant