Skip to content

Replace Unsafe classpath lookup#232

Draft
DerMistkaefer wants to merge 1 commit into
vectrix-space:main/1.0.0from
DerMistkaefer:fix/unsafe-classpath-lookup
Draft

Replace Unsafe classpath lookup#232
DerMistkaefer wants to merge 1 commit into
vectrix-space:main/1.0.0from
DerMistkaefer:fix/unsafe-classpath-lookup

Conversation

@DerMistkaefer

Copy link
Copy Markdown

What changed

  • replace the sun.misc.Unsafe fallback in ClassLoaders.systemClassPaths() with standard java.class.path parsing
  • add a regression test that compares the new classpath resolution against the previous Unsafe-based behavior on JDK internal class loaders
  • add the minimal JUnit 5 test configuration needed for the new launcher test

Why

Running the launcher on newer JDKs emits a terminal deprecation warning because Ignite calls sun.misc.Unsafe::objectFieldOffset while inspecting the application class loader internals. The new implementation removes that dependency while preserving the resolved classpath output.

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

Verification

  • direct JVM comparison of old and new classpath resolution returned same=true
  • :ignite-launcher:test passed successfully

Notes

  • I am not fully sure yet whether we want to keep the new tests in this PR, even though they were useful to verify that the new classpath resolution matches the previous behavior

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.
@DerMistkaefer DerMistkaefer marked this pull request as draft March 23, 2026 22:23

@vectrixdevelops vectrixdevelops left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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))) {

@vectrixdevelops vectrixdevelops Mar 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lets not use regex here. We can simply do split(File.pathSeparator).

@vectrixdevelops vectrixdevelops added the type: enhancement New feature or request label Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants