Skip to content

Task runClient unable to launch in OpenJDK 8 for ForgeGradle 2.3 #652

@milandamen

Description

@milandamen

There has been an update to OpenJDK 8 Java that breaks the launch of minecraft with the runClient gradle task. In GradleStart there is a hackNatives function that hacks the Java library path to include Minecraft's native libraries. This code depends on inner workings of how Java loads native libraries. This behavior has recently changed to only load library paths on JVM startup.

How it used to work:

  1. GradleStart sets sys_paths to null and adds the minecraft natives directory to java.library.path property at start of the task.
  2. Minecraft boots and tries to load the awt system library.
  3. The java ClassLoader checks if sys_paths is null, which is true, and then re-initializes the library paths.
  4. Library awt is loaded normally and boot continues.

Behavior after Java update:

  1. GradleStart sets sys_paths to null and adds the minecraft natives directory to java.library.path property at start of the task.
  2. Minecraft boots and tries to load the awt system library.
  3. The java ClassLoader does not check if sys_paths is null, and crashes with a NullPointerException.

Exception log:

[17:01:09] [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.LinuxSysImplementation.<clinit>(LinuxSysImplementation.java:50) ~[lwjgl-2.9.4-nightly-20150209.jar:?]
	at org.lwjgl.Sys.createImplementation(Sys.java:131) ~[lwjgl-2.9.4-nightly-20150209.jar:?]
	at org.lwjgl.Sys.<clinit>(Sys.java:116) ~[lwjgl-2.9.4-nightly-20150209.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]
Exception in thread "main" 	at org.lwjgl.LinuxSysImplementation.<clinit>(LinuxSysImplementation.java:50) ~[lwjgl-2.9.4-nightly-20150209.jar:?]
	at org.lwjgl.Sys.createImplementation(Sys.java:131) ~[lwjgl-2.9.4-nightly-20150209.jar:?]
	at org.lwjgl.Sys.<clinit>(Sys.java:116) ~[lwjgl-2.9.4-nightly-20150209.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

Full log: https://pastebin.com/jVYg2ZX8

ForgeGradle hack code:

sysPathsField.set(null, null);

OpenJDK 8u commit which changed the behavior: http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/1d666f78532a/
Corresponding OpenJDK issue: https://bugs.openjdk.java.net/browse/JDK-8235886

Possible solution:

Change hack to be like Option 2 in this post: https://stackoverflow.com/questions/15409223/adding-new-paths-for-native-libraries-at-runtime-in-java/15409446#15409446

Metadata

Metadata

Assignees

No one assigned

    Labels

    forumNot an issue with ForgeGradle, see the forumswon't fixIssue is not a real issue or not something worth fixing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions