Animated-TabList

Animated-TabList

65.2k Downloads

"An illegal reflective access operation has occurred"

montlikadani opened this issue · 1 comments

commented

This is only due to newer changes in Java 12+, as field changes have been removed in this version, making it almost impossible to change them. But there is another solution to it that already exists and that is why this error comes up. But you don't have to worry. This is just a warning, as we are trying to modify the fields in the code so that the tablist and groups can appear, because if it weren’t, nothing would appear.

tl;dr Just ignore this error message.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by hu.montlikadani.tablist.bukkit.utils.ReflectionUtils (file:/plugins/TabList-5.5.0.jar) to method java.lang.Class.getDeclaredFields0(boolean)
WARNING: Please consider reporting this to the maintainers of hu.montlikadani.tablist.bukkit.utils.ReflectionUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

We're aware of this issue. But literally its impossible to ignore this warning from code.

Here's the code how the plugin modifies the fields if you're interested:

try {
modifiersField = Field.class.getDeclaredField("modifiers");
} catch (NoSuchFieldException e) { // Java 12+
try {
Method meth;
if (JavaAccessibilities.getCurrentVersion() >= 15) {
meth = Class.class.getDeclaredMethod("getDeclaredFieldsImpl");
} else {
meth = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class);
}
boolean accessibleBeforeSet = JavaAccessibilities.isAccessible(meth, null);
meth.setAccessible(true);
Field[] fields = (Field[]) (JavaAccessibilities.getCurrentVersion() >= 15 ? meth.invoke(Field.class)
: meth.invoke(Field.class, false));
for (Field f : fields) {
if ("modifiers".equals(f.getName())) {
modifiersField = f;
break;
}
}
meth.setAccessible(accessibleBeforeSet);
} catch (Exception ex) {
ex.printStackTrace();
}
}

EDIT: Using MethodLookup/Lookups or Unsafe will causes to disable warnings/errors from other projects, which shouldn't be happened. Further read: https://stackoverflow.com/a/46458447/11756293

Further investigation: with the release of Java 16, the return value of the getDeclaredFieldsImpl and getDeclaredFields methods, so the amount of an array returns 0 for some reason. Changing this to MethodHandles.Lookup can be fixed somewhat, but requires using the --add-opens JVM flag to open access to specific packages, but this will not be implemented as it is used by many. The only solution in this situation is to switch from reflection to own injector so that we can track the process of sending packets. With the help of observable, we can trace certain field properties, but to do that we would have to implement a setter method and call the PropertyChangeListener which is also impossible.

commented

0e924ad

Summary:
Completely removed the modification of the final properties so that there are no more startup error messages.