Skip to content

Downgrade to Java 17 and remove Java 21 features for Android compatibility#1513

Open
aslan564 wants to merge 1 commit intoLibrePDF:masterfrom
aslan564:java17-android-compatibility
Open

Downgrade to Java 17 and remove Java 21 features for Android compatibility#1513
aslan564 wants to merge 1 commit intoLibrePDF:masterfrom
aslan564:java17-android-compatibility

Conversation

@aslan564
Copy link

Summary

  • Lowered Java source/target from 21 to 17 in pom.xml
  • Replaced all 28 Java Records across 15 files with regular final classes (with public final fields + accessor methods for backward compatibility)
  • Replaced Virtual Threads (Executors.newVirtualThreadPerTaskExecutor) with CachedThreadPool in PdfBatch.java
  • Replaced SequencedCollection methods (getFirst()/getLast()) with standard List access (get(0)/get(size()-1))
  • Updated tests to remove Virtual Thread assertions

Motivation

Java Records, Virtual Threads, and SequencedCollection methods cause Android D8 desugaring failures:

Error: Global synthetics are not supported with D8 when no global-synthetics consumer is specified

Android's D8 compiler cannot handle java.lang.Record bytecode without explicit AGP 8.3+ global-synthetics configuration. This breaks all Android projects that depend on OpenPDF (directly or transitively), even if they only use a small subset of OpenPDF features.

By downgrading to Java 17 and replacing these Java 21 features, OpenPDF becomes fully compatible with Android development toolchains.

Test plan

  • All 2264 existing tests pass (mvn clean verify)
  • Bytecode verification confirms zero java.lang.Record references remain
  • No behavioral changes — all replacements maintain identical public API and semantics

Fixes #1512

…ility

Java Records, Virtual Threads, and SequencedCollection methods cause
Android D8 desugaring failures ("Global synthetics are not supported
with D8"). This commit ensures OpenPDF works on Android by:

- Lowering Java source/target from 21 to 17 in pom.xml
- Replacing all 28 Java Records across 15 files with regular final
  classes (public final fields + accessor methods for backward compat)
- Replacing Virtual Threads (Executors.newVirtualThreadPerTaskExecutor)
  with CachedThreadPool in PdfBatch.java
- Replacing SequencedCollection methods (getFirst/getLast) with
  standard List access (get(0)/get(size()-1))
- Updating tests to remove Virtual Thread assertions

All 2264 tests pass. Bytecode verification confirms zero
java.lang.Record references remain.

Fixes LibrePDF#1512

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link

@andreasrosdal
Copy link
Contributor

andreasrosdal commented Mar 13, 2026

If you need to use OpenPDF on Java 17, you can use the OpenPDF 2.0.5 release. The 2.0 branch supports Java 17.

Java on Android is it's very unique special creation. Maybe a fork of OpenPDF which is specific for Android would be a good idea. Yes, I suggest someone creates a fork of OpenPDF for Android. So I suggest OpenPDF will focus on the main modern Java version, for which Java 21 is a good choice in 2026.

There has been a significant effort to modernize OpenPDF 3.x for Java 21, so this PR you propose will halt the modernization.

https://github.com/LibrePDF/OpenPDF/releases/tag/2.0.5

<dependency>
  <groupId>com.github.librepdf</groupId>
  <artifactId>openpdf</artifactId>
  <version>2.0.5</version>
</dependency>

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.

Downgrade Java target from 21 to 17 and remove Records for Android compatibility

2 participants