Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PGM cannot run on SportPaper with Java 17 #1213

Closed
calcastor opened this issue Aug 9, 2023 · 2 comments
Closed

PGM cannot run on SportPaper with Java 17 #1213

calcastor opened this issue Aug 9, 2023 · 2 comments

Comments

@calcastor
Copy link
Contributor

PGM cannot run with SportPaper using Java 17. This appears to occur here.

[20:36:27 ERROR]: Error occurred while enabling PGM v0.16-SNAPSHOT (git-610786e) (Is it up to date?)
java.lang.ExceptionInInitializerError: null
	at tc.oc.pgm.PGMPlugin.onEnable(PGMPlugin.java:120) ~[?:?]
	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:320) ~[sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:409) [sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:305) [sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:264) [sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:431) [sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:395) [sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:350) [sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:283) [sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:667) [sportpaper-1.8.8-R0.1-SNAPSHOT.jar:git-SportPaper-b362369-P.7913d6e-SP.fb1eb5c-CB.e1ebe52]
	at java.lang.Thread.run(Thread.java:833) [?:?]
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at tc.oc.pgm.util.bukkit.Platform.getNMSHacks(Platform.java:83) ~[?:?]
	at tc.oc.pgm.util.nms.NMSHacks.<clinit>(NMSHacks.java:46) ~[?:?]
	... 12 more
Caused by: java.lang.reflect.InvocationTargetException
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
	at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
	at tc.oc.pgm.util.bukkit.Platform.getNMSHacks(Platform.java:77) ~[?:?]
	at tc.oc.pgm.util.nms.NMSHacks.<clinit>(NMSHacks.java:46) ~[?:?]
	... 12 more
Caused by: java.lang.RuntimeException: java.lang.NoSuchFieldException: modifiers
	at tc.oc.pgm.util.reflect.ReflectionUtils.getField(ReflectionUtils.java:73) ~[?:?]
	at tc.oc.pgm.util.nms.v1_8.NMSHacks1_8.<init>(NMSHacks1_8.java:842) ~[?:?]
	at tc.oc.pgm.util.nms.v1_8.NMSHacksSportPaper.<init>(NMSHacksSportPaper.java:35) ~[?:?]
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
	at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
	at tc.oc.pgm.util.bukkit.Platform.getNMSHacks(Platform.java:77) ~[?:?]
	at tc.oc.pgm.util.nms.NMSHacks.<clinit>(NMSHacks.java:46) ~[?:?]
	... 12 more
Caused by: java.lang.NoSuchFieldException: modifiers
	at java.lang.Class.getDeclaredField(Class.java:2610) ~[?:?]
	at tc.oc.pgm.util.reflect.ReflectionUtils.getField(ReflectionUtils.java:69) ~[?:?]
	at tc.oc.pgm.util.nms.v1_8.NMSHacks1_8.<init>(NMSHacks1_8.java:842) ~[?:?]
	at tc.oc.pgm.util.nms.v1_8.NMSHacksSportPaper.<init>(NMSHacksSportPaper.java:35) ~[?:?]
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
	at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
	at tc.oc.pgm.util.bukkit.Platform.getNMSHacks(Platform.java:77) ~[?:?]
	at tc.oc.pgm.util.nms.NMSHacks.<clinit>(NMSHacks.java:46) ~[?:?]
	... 12 more
@cswhite2000
Copy link
Member

The same code is also present in SportPaper, from paper 1.8 in PaperSpigotConfig.java

Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(maxStack, maxStack.getModifiers() & ~Modifier.FINAL);

vs

Field modifiersField = ReflectionUtils.getField(Field.class, "modifiers");
...
modifiersField.setInt(dimensionField, dimensionField.getModifiers() & ~Modifier.FINAL);
dimensionField.set(worldServerField.get(world), 11);

Basically, it's updating the internal flag for whether the field is final and then updating the field.
This breaks in java 1.12+ because the final modifier cannot be removed starting in those versions.

@calcastor
Copy link
Contributor Author

Resolved via #1288 and Electroid/SportPaper#139

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

No branches or pull requests

2 participants