Skip to content

Instantly share code, notes, and snippets.

@anatawa12
Last active November 28, 2022 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anatawa12/d61520430a96ba5939cd5a66dbba5bb3 to your computer and use it in GitHub Desktop.
Save anatawa12/d61520430a96ba5939cd5a66dbba5bb3 to your computer and use it in GitHub Desktop.
How to execute runClient in ForgeGradle for 1.12 or older with newest jdk8.

go to TL;DR

日本語

since jdk 8u242, runClient Task and client run with GradleStart class will never succeed with error below:

[18:48:19] [main/ERROR] [LaunchWrapper]: Unable to launch
java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_242]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_242]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_242]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_242]
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_242]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_242]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_242]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_242]
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
	at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: java.lang.ExceptionInInitializerError
	at org.lwjgl.MacOSXSysImplementation.<clinit>(MacOSXSysImplementation.java:51) ~[lwjgl-2.9.2-nightly-20140822.jar:?]
	at org.lwjgl.Sys.createImplementation(Sys.java:130) ~[lwjgl-2.9.2-nightly-20140822.jar:?]
Exception in thread "main" 	at org.lwjgl.Sys.<clinit>(Sys.java:111) ~[lwjgl-2.9.2-nightly-20140822.jar:?]
	at net.minecraft.client.Minecraft.getSystemTime(Minecraft.java:3159) ~[Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:42) ~[Main.class:?]
	... 12 more
Caused by: java.lang.NullPointerException
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1847) ~[?:1.8.0_242]
	at java.lang.Runtime.loadLibrary0(Runtime.java:871) ~[?:1.8.0_242]
	at java.lang.System.loadLibrary(System.java:1124) ~[?:1.8.0_242]
	at java.awt.Toolkit$3.run(Toolkit.java:1636) ~[?:1.8.0_242]
	at java.awt.Toolkit$3.run(Toolkit.java:1634) ~[?:1.8.0_242]
	at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_242]
	at java.awt.Toolkit.loadLibraries(Toolkit.java:1633) ~[?:1.8.0_242]
	at java.awt.Toolkit.<clinit>(Toolkit.java:1670) ~[?:1.8.0_242]
	at org.lwjgl.MacOSXSysImplementation.<clinit>(MacOSXSysImplementation.java:51) ~[lwjgl-2.9.2-nightly-20140822.jar:?]
	at org.lwjgl.Sys.createImplementation(Sys.java:130) ~[lwjgl-2.9.2-nightly-20140822.jar:?]
	at org.lwjgl.Sys.<clinit>(Sys.java:111) ~[lwjgl-2.9.2-nightly-20140822.jar:?]
	at net.minecraft.client.Minecraft.getSystemTime(Minecraft.java:3159) ~[Minecraft.class:?]
	at net.minecraft.client.main.Main.main(Main.java:42) ~[Main.class:?]
	... 12 more
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.reflect.InvocationTargetException
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at java.lang.reflect.Method.invoke(Method.java:498)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: 	at GradleStart.main(GradleStart.java:25)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: Caused by: net.minecraftforge.fml.relauncher.FMLSecurityManager$ExitTrappedException
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: 	at net.minecraftforge.fml.relauncher.FMLSecurityManager.checkPermission(FMLSecurityManager.java:49)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: 	at java.lang.SecurityManager.checkExit(SecurityManager.java:761)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: 	at java.lang.Runtime.exit(Runtime.java:108)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: 	at java.lang.System.exit(System.java:973)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: 	at net.minecraft.launchwrapper.Launch.launch(Launch.java:138)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: 	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
[18:48:19] [main/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: 	... 6 more

this show why this error is occurred and how to avoid this error.

Why this error is occurred

the code shown below is the reason of this error.

// some lines in hackNatives() in GradleStart
final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
sysPathsField.setAccessible(true);
sysPathsField.set(null, null);

FG_1.2 GradleStart.java#L82-L84

This code make ClassLoader.sys_paths null to reset ClassLoader.usr_path. Before this code, re-sets "java.library.path" system property. However, the ClassLoader makes cache of path array with "java.library.path" system property at the starting of JVM. So we have to reset path cache.

Until jdk8u242, ClassLoader.loadLibrary always check whether ClassLoader.sys_paths is null and initialize ClassLoader.sys_paths and ClassLoader.usr_path. GradleStart.hackNatives is written based on this behavior.

However, Since jdk8u242, ClassLoader.loadLibrary never check ClassLoader.sys_paths and initialize ClassLoader.sys_paths and ClassLoader.usr_path at the starting of JVM. So ClassLoader.loadLibrary throws NPE if ClassLoader.sys_paths is null. Open JDK Source difference about this here.

how to avoid this error (if you fork ForgeGradle)

We have to run code like usr_paths = initializePath("java.library.path") with reflection. Minecraft Forge for minecraft 1.15 has been resolved this problem, so I think we should use way like. We can use that implementation below to reset ClassLoader.usr_path.

final Method initializePathMethod = ClassLoader.class.getDeclaredMethod("initializePath", String.class);
initializePathMethod.setAccessible(true);
final Object usrPathsValue = initializePathMethod.invoke(null, "java.library.path");
final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths");
usrPathsField.setAccessible(true);
usrPathsField.set(null, usrPathsValue);

MinecraftForge userdev LaunchTesting.java#L126-L131

how to avoid this error

I made fork of two versions of ForgeGradle, 1.2 and 2.3, for Minecraft Forge for 1.7.x, 1.8.x, and 1.12.x. If you're modder of 1.7.x, 1.8.x, and 1.12.x, You can use my forks of ForgeGradle.

For ForgeGradle 1.2, for minecraft 1.7.x and 1.8.x is here!

For ForgeGradle 2.3, for minecraft 1.12.x is here!

If you do not want to use my fork of ForgeGradle, or you're using other versions of ForgeGradle, Please make your own fork of ForgeGradle.

TL;DR

  • If you do not want to use my (anatawa12's) fork of ForgeGradle, make your own fork of ForgeGradle
  • If you're using ForgeGradle 1.2, for minecraft 1.7.x and 1.8.x, you can use my fork of ForgeGradle here
  • If you're using ForgeGradle 2.3, for minecraft 1.12.x, you can use my fork of ForgeGradle here
  • In other cases, make your own fork of ForgeGradle
@downtimekyle
Copy link

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment