-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Fix Java 12 compatibility #3726
Fix Java 12 compatibility #3726
Conversation
Seems like it can be done with the use of Still though, is this workaround still relevant on modern versions? |
It's just some hacky code to provide some support for people who reload their server instead of restarting them, so IMO it can be removed entirely |
The modifiers field wasn't removed, Java 12 added the You can still use VarHandles to read/modify the field as explained here. |
By removed I meant that, but does not matter anyway. That's an implementation detail. VarHandle method is a hacky way too like Unsafe, but worse than Unsafe in my opinion. Sure, it is easier than Unsafe and avoids sun.misc import, but it gives an illegal access warning and all illegal access operations will be denied in Java 16. Quick test case: VarHandleModifiersTest.javafinal class VarHandleModifiersTest {
public static final void main(final String[] args) {
try {
final var lookup = java.lang.invoke.MethodHandles.privateLookupIn(java.lang.reflect.Field.class, java.lang.invoke.MethodHandles.lookup());
final var modifiers = lookup.findVarHandle(java.lang.reflect.Field.class, "modifiers", int.class);
} catch (final NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
} Result on Java 15
Result on Java 16 early access
Result on Java 17 early access is same, only changing version number. My opinion is, we should either remove it completely, or use Unsafe (from JEP 396, targeting Java 16: "It is not a goal to remove, encapsulate, or modify any critical internal APIs of the JDK for which standard replacements do not yet exist. This means that sun.misc.Unsafe will remain available."). Or just ignore it in Java 12+ (PRs current behaviour) From the behaviour said in the comment of the work around: Comment of the work around
This patch in Paper probably fixes this behaviour: |
Besides, |
In that case, I think we're safe to just remove that piece of code, Skript doesn't support reloads either way. But ignoring it on future versions is fine as well so unless anyone has any issues with this PR, I am merging. |
Description
Fixes this error:
The Field#modifiers field was removed on Java 12.
The eror happens on Java 12+ only and the stacktrace is only printed when Skript#testing returns true (i.e -ea/-enableassertions), but it should be fixed anyway.
By "fix", it just ignores the error. The behaviour is not same as on Java < 12. Can't find a better alternative rn, but probably there is.
Not tested on Java 11 but it would give a illegal access warning with or without this fix anyway. Perhaps unsetting static final fields should be removed altogether as most of them are constants? Don't know. The whole workaround may also be unnecessary, is this memory leak thing still exists on recent MC versions?
Target Minecraft Versions: any
Requirements: none
Related Issues: none