Prevent Nashorn from defining anonymous classes if Java is too new

Solar Flux Reborn now works on Java 17
This commit is contained in:
embeddedt 2023-02-19 18:44:21 -05:00
parent a99889e160
commit d2d29f14cb
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -39,6 +39,14 @@ public class ModernFixMixinPlugin implements IMixinConfigPlugin {
this.logger.info("Loaded configuration file for ModernFix: {} options available, {} override(s) found",
config.getOptionCount(), config.getOptionOverrideCount());
try {
Class.forName("sun.misc.Unsafe").getDeclaredMethod("defineAnonymousClass", Class.class, byte[].class, Object[].class);
} catch(ReflectiveOperationException | NullPointerException e) {
this.logger.info("Applying Nashorn fix");
Properties properties = System.getProperties();
properties.setProperty("nashorn.args", properties.getProperty("nashorn.args", "") + " --anonymous-classes=false");
}
/* We abuse the constructor of a mixin plugin as a safe location to start modifying the classloader */
/* Swap the transformer for ours */
ClassLoader loader = Thread.currentThread().getContextClassLoader();