Replace Unsafe classpath lookup#232
Draft
DerMistkaefer wants to merge 1 commit into
Draft
Conversation
Stop using sun.misc.Unsafe to read the app class loader internals in ClassLoaders.systemClassPaths() and switch to standard java.class.path parsing instead. This removes the terminal deprecation warning on newer JDKs while keeping the resolved classpath output unchanged. Observed warning: WARNING: A terminally deprecated method in sun.misc.Unsafe has been called WARNING: sun.misc.Unsafe::objectFieldOffset has been called by space.vectrix.ignite.util.ClassLoaders (file:/usr/bin/paper/ignite-launcher.jar) WARNING: Please consider reporting this to the maintainers of class space.vectrix.ignite.util.ClassLoaders WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release Add a regression test that compares the new implementation against the previous Unsafe-based lookup on JDK internal class loaders, and wire in the minimal JUnit 5 test configuration required for launcher tests. Verified with a direct JVM comparison of old vs. new output (`same=true`) and a successful `:ignite-launcher:test` run.
vectrixdevelops
requested changes
Mar 24, 2026
vectrixdevelops
left a comment
Member
There was a problem hiding this comment.
Looks good so far! Just a few changes I'd suggest. Let's also remove the unit tests for now, we can look at adding a full unit test suite in the future.
| final Field pathField = ucpField.getType().getDeclaredField("path"); | ||
| final long pathFieldOffset = (long) objectFieldOffsetMethod.invoke(unsafe, pathField); | ||
| final ArrayList<URL> path = (ArrayList<URL>) getObjectMethod.invoke(unsafe, ucpObject, pathFieldOffset); | ||
| final String separator = System.getProperty("path.separator", File.pathSeparator); |
Member
There was a problem hiding this comment.
Just using File.pathSeparator would be good enough, don't need to grab it from the system property.
| final ArrayList<URL> path = (ArrayList<URL>) getObjectMethod.invoke(unsafe, ucpObject, pathFieldOffset); | ||
| final String separator = System.getProperty("path.separator", File.pathSeparator); | ||
| final List<URL> urls = new ArrayList<>(); | ||
| for(final String entry : classPath.split(java.util.regex.Pattern.quote(separator))) { |
Member
There was a problem hiding this comment.
Lets not use regex here. We can simply do split(File.pathSeparator).
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.
What changed
sun.misc.Unsafefallback inClassLoaders.systemClassPaths()with standardjava.class.pathparsingUnsafe-based behavior on JDK internal class loadersWhy
Running the launcher on newer JDKs emits a terminal deprecation warning because Ignite calls
sun.misc.Unsafe::objectFieldOffsetwhile inspecting the application class loader internals. The new implementation removes that dependency while preserving the resolved classpath output.Observed warning:
Verification
same=true:ignite-launcher:testpassed successfullyNotes