Skip to content

Use jrt:/ file system as fallback for missing jmods - #541

Merged
piazzesiNiccolo-GS merged 8 commits into
Guardsquare:masterfrom
Marcono1234:jmods-jrt-filesystem
Nov 19, 2026
Merged

piazzesiNiccolo-GS merged 8 commits into
Guardsquare:masterfrom
Marcono1234:jmods-jrt-filesystem

Conversation

@Marcono1234

@Marcono1234 Marcono1234 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Needs Guardsquare/proguard-core#186

See also original POC #504

Resolves #473 (hopefully)

@Marcono1234 Marcono1234 left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I hope the new tests in InputReaderTest are realistic, but if possible please also run this (manually?) with an integration test setup in case you have one.

I have done a bit integration testing locally and it seems to work as expected. Make sure to run with -verbose to see the new "Using jrt:/ file system fallback ..." log message.

DataEntryReader reader;
DataEntrySource source = maybeGetJrtFallback(classPathFile, classPathEntry.isJmod());
if (source != null) {
reader = DataEntryReaderFactory.applyGeneralFilter(classPathEntry, dataEntryReader);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I hope it suffices to just use applyGeneralFilter (respectively ClassPathEntry#getFilter) here. Not sure if it is necessary to also apply any file-extension specific filters, e.g. getJarFilter() or getJmodFilter().

val dest = pathPieces.fold(destDir, Path::resolve)
Files.createDirectories(dest.parent)
// Some of the copied files are > 100 MB; for better performance just create a hardlink
Files.createLink(dest, source)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I hope creating a hardlink instead of copying the files is fine here. That should not cause any problems I think, unless some program or the user were to try modify the file (other than deleting it), which would modify the actual JDK.

Could maybe reduce the risk by additionally making the hardlinked file read-only / non-writable but that might make cleanup of the tempdir more cumbersome.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The hardlinks don't work on my Linux machine:

java.nio.file.FileSystemException: /tmp/proguard.InputReaderTest7748393587331681400/lib/jrt-fs.jar -> /home/fergal/.jdks/corretto-11.0.21/lib/jrt-fs.jar: Invalid cross-device link

Using a symbolic link instead fixes it for me. If that doesn't work universally, it may be worth creating minimal jmods/jars/modules for ProGuard to load, either building them in the test or adding them as resource files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for letting me know! I have changed it to try creating a symlink as fallback now (the comment in code explains the rationale). Can you please try if that solves it for you?

I currently don't have a local test setup where creating the hardlink fails, but when I temporarily changed it to always create the symlink, loading it as jrt file system seemed to work for me on Linux.

Regarding creating a minimal lib/modules file: Not sure how easy that is, and I am afraid that would make the test harder to maintain so for now I would like to avoid that.

@piazzesiNiccolo-GS

piazzesiNiccolo-GS commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

You can rebase your PR, JRtDataSource should now be available to PG

@Marcono1234

Copy link
Copy Markdown
Contributor Author

Did a regular merge for now; if you want I can squash all commits in the end though. (In case you are not doing that anyway when the PR is merged.)

@piazzesiNiccolo-GS

Copy link
Copy Markdown
Contributor

Did a regular merge for now; if you want I can squash all commits in the end though. (In case you are not doing that anyway when the PR is merged.)

Not a problem indeed, will squash merge if needed 👍 We will have a thorough review in the next couple days just fyi. Thanks again for looking into it.

@piazzesiNiccolo-GS

piazzesiNiccolo-GS commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

The test dependency issue should not cause tests to fail for your PR anymore, after syncing

@Marcono1234
Marcono1234 marked this pull request as ready for review October 30, 2026 17:15
val dest = pathPieces.fold(destDir, Path::resolve)
Files.createDirectories(dest.parent)
// Some of the copied files are > 100 MB; for better performance just create a hardlink
Files.createLink(dest, source)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The hardlinks don't work on my Linux machine:

java.nio.file.FileSystemException: /tmp/proguard.InputReaderTest7748393587331681400/lib/jrt-fs.jar -> /home/fergal/.jdks/corretto-11.0.21/lib/jrt-fs.jar: Invalid cross-device link

Using a symbolic link instead fixes it for me. If that doesn't work universally, it may be worth creating minimal jmods/jars/modules for ProGuard to load, either building them in the test or adding them as resource files.

@sonarqubecloud

Copy link
Copy Markdown

onacit added a commit to jinahya/proguard-with-maven-example that referenced this pull request Nov 17, 2026
- Select the jmod profile by java.base.jmod existence instead of a JDK
  version range; the java24+ profile left ProGuard with no JDK classes.
- Add java9+-without-jmods profile which extracts java.base from jrt:/
  into a jar (src/build/ExtractJdk.java) for JDKs shipped without jmods
  (JEP 493; e.g., Temurin 24+). To be removed once ProGuard falls back to
  jrt:/ by itself: Guardsquare/proguard#541
- Update parent, proguard-base 7.10.0, proguard-core 9.4.1, and plugins.
- docker.maven.sh: accept <tag> <phase>, allocate a tty only when present.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@piazzesiNiccolo-GS

Copy link
Copy Markdown
Contributor

Also verified this on Macos JDK ✅

@piazzesiNiccolo-GS
piazzesiNiccolo-GS merged commit 4428f61 into Guardsquare:master Nov 19, 2026
4 checks passed
@Marcono1234
Marcono1234 deleted the jmods-jrt-filesystem branch November 24, 2026 09:58
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.

How to setup libraryjars, if jmods are missing

3 participants