lishid / OpenInv

Open anyone's inventory as a chest, real-time!
GNU General Public License v3.0
120 stars 97 forks source link

IllegalAccessException in Java 9+ #93

Closed Tim269 closed 5 years ago

Tim269 commented 6 years ago

Hey - thank you so much for mainting this plugin <3. Here is a error I stumpling about recently.

[22:54:19 WARN]: java.lang.IllegalAccessException: Can not set final net.minecraft.server.v1_13_R2.NonNullList field net.minecraft.server.v1_13_R2.PlayerInventory.items to net.minecraft.server.v1_13_R2.NonNullList
[22:54:19 WARN]:        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:76)
[22:54:19 WARN]:        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:80)
[22:54:19 WARN]:        at java.base/jdk.internal.reflect.UnsafeQualifiedObjectFieldAccessorImpl.set(UnsafeQualifiedObjectFieldAccessorImpl.java:79)
[22:54:19 WARN]:        at java.base/java.lang.reflect.Field.set(Field.java:780)
[22:54:19 WARN]:        at com.lishid.openinv.internal.v1_13_R2.SpecialPlayerInventory.setItemArrays(SpecialPlayerInventory.java:161)
[22:54:19 WARN]:        at com.lishid.openinv.internal.v1_13_R2.SpecialPlayerInventory.<init>(SpecialPlayerInventory.java:43)
[22:54:19 WARN]:        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[22:54:19 WARN]:        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[22:54:19 WARN]:        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[22:54:19 WARN]:        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
[22:54:19 WARN]:        at com.lishid.openinv.util.InternalAccessor.createObject(InternalAccessor.java:103)
[22:54:19 WARN]:        at com.lishid.openinv.util.InternalAccessor.newSpecialPlayerInventory(InternalAccessor.java:210)
[22:54:19 WARN]:        at com.lishid.openinv.OpenInv.getSpecialInventory(OpenInv.java:327)
[22:54:19 WARN]:        at com.lishid.openinv.commands.OpenInvPluginCommand.openInventory(OpenInvPluginCommand.java:148)
[22:54:19 WARN]:        at com.lishid.openinv.commands.OpenInvPluginCommand.access$100(OpenInvPluginCommand.java:33)
[22:54:19 WARN]:        at com.lishid.openinv.commands.OpenInvPluginCommand$1$1.run(OpenInvPluginCommand.java:89)
[22:54:19 WARN]:        at org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftTask.run(CraftTask.java:63)
[22:54:19 WARN]:        at org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:423)
[22:54:19 WARN]:        at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:1008)
[22:54:19 WARN]:        at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:439)
[22:54:19 WARN]:        at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:943)
[22:54:19 WARN]:        at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:841)
[22:54:19 WARN]:        at java.base/java.lang.Thread.run(Thread.java:834)
RoboMWM commented 6 years ago

/version openinv may be helpful and what happens that causes this.

Tim269 commented 6 years ago

Oh sorry. I'm using OpenInv version 3.3.6 and git-Paper-432 (1.13.2)

catb0t commented 6 years ago

What were you doing before the exception?

Tim269 commented 6 years ago

I tried to execute /openinv <player> or /openender <player>. However any empty inventory pops up (not the actual one) along with the error in my server console.

Jikoo commented 6 years ago

Huh, what java version are you using? I've never seen java.base/ prepended on stack trace lines.

I'll look into it, but I'm not sure what could be causing that - we remove the final modifier prior to setting. It's not a SecurityManager or anything like that, it'd be a different error. The modifier just appears to not be changed.

Tim269 commented 6 years ago

I'm so sorry for being that bad at providing information. I assume my error is caused by my java version as I'm using "11.0.1" 2018-10-16 LTS

andris155 commented 5 years ago

Same problem in Java 11

RoboMWM commented 5 years ago

Curious if this has anything to do with some of the reflection stuff being removed in post-version 8 java.

Jikoo commented 5 years ago

Yeah, I assume somewhere in Java 9 OpenInv broke. Not sure how to handle it, honestly. I really don't want to encourage people to stay on Java 8, but all the good alternatives I can come up with are massive changes I definitely don't have time to implement for a while.

I guess the easiest temp fix would be to just override every ISpecialPlayerInventory manipulation method and redirect the entire inventory contents to a different list/array which actually is the internal one. It'd be way more messy and prone to accidental breakages than it is now (for updates, I basically copy+paste, then review method diffs) but it should allow us to limp along.

Jikoo commented 5 years ago

Do containers open silently at all? Looks like it should be broken as well.

Tim269 commented 5 years ago

Not sure what all is defined as containers - but chests do open silently as they used to be.

Jikoo commented 5 years ago

Interesting, so reflection in Java 9+ still allows accessing private variables, but doesn't allow removing the final modifier. Could be worse I guess.

Thrasilias commented 5 years ago

when will this be fixed. seems to be a little bit inactive ans people need this..

Jikoo commented 5 years ago

when will this be fixed. seems to be a little bit inactive ans people need this..

I haven't had much free time lately, though I'll admit this isn't a high priority for me due to the low percentage of servers using anything other than Java 8. I'll try to make a junky copy+paste workaround this week, but if anyone wants to take a stab at a higher quality solution that's certainly welcome.

Jikoo commented 5 years ago

Please try OpenInv 3.3.8-SNAPSHOT. Theoretically should work, but it's nowhere near as clean as it could be.

Jikoo commented 5 years ago

4.0.0 fixes Java 9+ issues.