Skip to content

forgewrapper uses unsafe method sun.misc.Unsafe::staticFieldBase that is deprecated #14

@DioEgizio

Description

@DioEgizio

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::staticFieldBase has been called by io.github.zekerzhayard.forgewrapper.installer.util.ModuleUtil (file:/home/dioegizio/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/libraries/io/github/zekerzhayard/ForgeWrapper/prism-2025-12-07/ForgeWrapper-prism-2025-12-07.jar)
WARNING: Please consider reporting this to the maintainers of class io.github.zekerzhayard.forgewrapper.installer.util.ModuleUtil
WARNING: sun.misc.Unsafe::staticFieldBase will be removed in a future release

apparently according to JEP 498 this will be removed soon:

We are deprecating and removing the memory-access methods in sun.misc.Unsafe in phases:
JDK 23 deprecated all of the memory-access methods for removal. This caused compile-time deprecation warnings for code that refers to the methods, alerting library developers to their forthcoming removal.
JDK 24 will, by default, issue a warning on the first occasion that any memory-access method is used, whether directly or via reflection. That is, it will issue at most one warning regardless of which memory-access methods are used and how many times any particular method is used. This will alert application developers and users to the forthcoming removal of the methods, and the need to upgrade libraries. An example of the warning is:
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::setMemory has been called by com.foo.bar.Server (file:/tmp/foobarserver/thing.jar)
WARNING: Please consider reporting this to the maintainers of com.foo.bar.Server
WARNING: sun.misc.Unsafe::setMemory will be removed in a future release
JDK 26 or later will throw an exception whenever a memory-access method is used, whether directly or via reflection. This will further alert application developers and users to the imminent removal of the methods.
In releases after JDK 26, we will remove memory-access methods which have had standard replacements since JDK 9 (2017).
In releases after JDK 26, we will remove memory-access methods which have only had standard replacements since JDK 22 (2023).

this is very important because people will use versions of java that are newer than 25 on neoforge and forge at one point

edit: seems to be only used here:

public class ModuleUtil {
private final static MethodHandles.Lookup IMPL_LOOKUP = getImplLookup();
private static MethodHandles.Lookup getImplLookup() {
try {
// Get theUnsafe
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);
// Get IMPL_LOOKUP
Field implLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
return (MethodHandles.Lookup) unsafe.getObject(unsafe.staticFieldBase(implLookupField), unsafe.staticFieldOffset(implLookupField));
} catch (Throwable t) {
throw new RuntimeException(t);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions