ProtocolLib

3M Downloads

PrettyPrinter performs illegal reflective access

A248 opened this issue ยท 2 comments

commented

Describe the bug
PrettyPrinter attempts to read private fields, which causes illegal reflective access. On Java 9 this causes a warning by default, and on Java 16 this is denied by default.

To Reproduce
Trigger one of the try-catch blocks which use reporter.reportDetailed in the main plugin class.

Expected behavior
PrettyPrinter does not reflect into private fields.

Screenshots
https://pastebin.com/79S1An7E

Version Info
Tested on 4.5.1 and 4.7.0. The relevant code is still in the master branch:

Object value = FieldUtils.readField(field, object, true);

Additional context
This can happen when any of the various try/catch Throwable blocks in the main plugin class are triggered.

commented

Can you paste the error in 4.7.0?

commented

I'm able to send you a unit test in a few days if you like.. There you have the stacktrace for 4.7.0:

[08:12:10 ERROR]: [Server thread/org.buk.cra.v1_.CraftServer] Unable to make field private final java.lang.String java.lang.Enum.name accessible: module java.base does not "opens java.lang" to module ProtocolLib initializing ProtocolLib v4.7.0 (Is it up to date?)
java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.String java.lang.Enum.name accessible: module java.base does not "opens java.lang" to module ProtocolLib
	at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357) ~[?:?]
	at java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[?:?]
	at java.lang.reflect.Field.checkCanSetAccessible(Field.java:177) ~[?:?]
	at java.lang.reflect.Field.setAccessible(Field.java:171) ~[?:?]
	at com.comphenix.protocol.reflect.FieldUtils.readField(FieldUtils.java:277) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printObject(PrettyPrinter.java:236) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printObject(PrettyPrinter.java:251) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printValue(PrettyPrinter.java:285) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printObject(PrettyPrinter.java:246) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printObject(PrettyPrinter.java:251) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printValue(PrettyPrinter.java:285) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printObject(PrettyPrinter.java:246) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printObject(PrettyPrinter.java:124) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printObject(PrettyPrinter.java:102) ~[?:?]
	at com.comphenix.protocol.reflect.PrettyPrinter.printObject(PrettyPrinter.java:89) ~[?:?]
	at com.comphenix.protocol.error.DetailedErrorReporter.getStringDescription(DetailedErrorReporter.java:480) ~[?:?]
	at com.comphenix.protocol.error.DetailedErrorReporter.reportDetailed(DetailedErrorReporter.java:375) ~[?:?]
	at com.comphenix.protocol.error.DelegatedErrorReporter.reportDetailed(DelegatedErrorReporter.java:63) ~[?:?]
	at com.comphenix.protocol.error.DelegatedErrorReporter.reportDetailed(DelegatedErrorReporter.java:87) ~[?:?]
	at com.comphenix.protocol.ProtocolLib.onLoad(ProtocolLib.java:231) ~[?:?]
	at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:433) ~[?:?]
	at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:197) ~[?:?]
	at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:670) ~[?:?]
	at java.lang.Thread.run(Thread.java:831) [?:?]