From d2d29f14cb556a86ebd93941d6aa7df105a9e462 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 19 Feb 2023 18:44:21 -0500 Subject: [PATCH] Prevent Nashorn from defining anonymous classes if Java is too new Solar Flux Reborn now works on Java 17 --- .../embeddedt/modernfix/core/ModernFixMixinPlugin.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/embeddedt/modernfix/core/ModernFixMixinPlugin.java b/src/main/java/org/embeddedt/modernfix/core/ModernFixMixinPlugin.java index c9157924..ea3b018d 100644 --- a/src/main/java/org/embeddedt/modernfix/core/ModernFixMixinPlugin.java +++ b/src/main/java/org/embeddedt/modernfix/core/ModernFixMixinPlugin.java @@ -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();