Skip to content

Commit fff5f33

Browse files
authored
Fix Java 24 incompatibility (#306)
* maybe fix java 24 incompat * comments * comments * update groovy to 4.0.26 * remove java version check
1 parent f19ec87 commit fff5f33

File tree

10 files changed

+110
-192
lines changed

10 files changed

+110
-192
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ debug_woot = false
106106

107107
# SECTION: custom injected tags
108108

109-
groovy_version = 4.0.21
109+
groovy_version = 4.0.26
110110

111111
# END SECTION: custom injected tags
112112

src/main/java/com/cleanroommc/groovyscript/GroovyScript.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public class GroovyScript {
101101

102102
@Mod.EventHandler
103103
public void onConstruction(FMLConstructionEvent event) {
104-
JavaVersionCheck.validateJavaVersion(event.getSide());
105104
if (!SandboxData.isInitialised()) {
106105
LOGGER.throwing(new IllegalStateException("Sandbox data should have been initialised by now, but isn't! Trying to initialize again."));
107106
SandboxData.initialize((File) FMLInjectionData.data()[6], LOGGER);

src/main/java/com/cleanroommc/groovyscript/IncompatibleJavaException.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/main/java/com/cleanroommc/groovyscript/JavaVersionCheck.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/main/java/com/cleanroommc/groovyscript/core/mixin/LoaderControllerMixin.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
import com.cleanroommc.groovyscript.GroovyScript;
44
import com.cleanroommc.groovyscript.sandbox.LoadStage;
5-
import net.minecraftforge.fml.client.CustomModLoadingErrorDisplayException;
65
import net.minecraftforge.fml.common.LoadController;
76
import net.minecraftforge.fml.common.LoaderState;
8-
import net.minecraftforge.fml.common.ModContainer;
97
import org.spongepowered.asm.mixin.Mixin;
108
import org.spongepowered.asm.mixin.injection.At;
119
import org.spongepowered.asm.mixin.injection.Inject;
1210
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1311

14-
import java.lang.reflect.InvocationTargetException;
1512

1613
@Mixin(value = LoadController.class, remap = false)
1714
public class LoaderControllerMixin {
@@ -28,15 +25,4 @@ public void preInit(LoaderState state, Object[] eventData, CallbackInfo ci) {
2825
GroovyScript.runGroovyScriptsInLoader(LoadStage.POST_INIT);
2926
}
3027
}
31-
32-
@Inject(method = "errorOccurred", at = @At(value = "NEW", target = "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Lorg/apache/logging/log4j/message/FormattedMessage;", shift = At.Shift.BEFORE))
33-
public void errorOccured(ModContainer modContainer, Throwable exception, CallbackInfo ci) throws Throwable {
34-
if (exception instanceof InvocationTargetException) {
35-
exception = exception.getCause();
36-
}
37-
if (exception instanceof CustomModLoadingErrorDisplayException) {
38-
// normally every exception gets wrapped in a LoaderException making these """custom""" exceptions useless, thanks cpw
39-
throw exception;
40-
}
41-
}
4228
}
Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,20 @@
11
package com.cleanroommc.groovyscript.core.mixin.groovy;
22

3-
import com.cleanroommc.groovyscript.sandbox.transformer.AsmDecompileHelper;
4-
import groovy.lang.GroovyRuntimeException;
53
import org.codehaus.groovy.ast.decompiled.AsmDecompiler;
64
import org.codehaus.groovy.ast.decompiled.ClassStub;
7-
import org.codehaus.groovy.util.URLStreams;
8-
import org.objectweb.asm.ClassReader;
9-
import org.objectweb.asm.ClassWriter;
10-
import org.objectweb.asm.tree.ClassNode;
11-
import org.spongepowered.asm.mixin.Final;
125
import org.spongepowered.asm.mixin.Mixin;
13-
import org.spongepowered.asm.mixin.Shadow;
146
import org.spongepowered.asm.mixin.injection.At;
157
import org.spongepowered.asm.mixin.injection.Inject;
168
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
179

18-
import java.io.BufferedInputStream;
19-
import java.io.IOException;
20-
import java.io.InputStream;
21-
import java.lang.ref.SoftReference;
22-
import java.lang.reflect.InvocationTargetException;
23-
import java.net.URI;
24-
import java.net.URISyntaxException;
2510
import java.net.URL;
26-
import java.util.Map;
2711

2812
@Mixin(value = AsmDecompiler.class, remap = false)
2913
public class AsmDecompilerMixin {
3014

31-
@Shadow
32-
@Final
33-
private static Map<URI, SoftReference<ClassStub>> stubCache;
34-
35-
@Inject(method = "parseClass", at = @At("HEAD"), cancellable = true)
15+
@Inject(method = "parseClass", at = @At("HEAD"))
3616
private static void parseClass(URL url, CallbackInfoReturnable<ClassStub> cir) {
37-
URI uri;
38-
try {
39-
uri = url.toURI();
40-
} catch (URISyntaxException e) {
41-
throw new GroovyRuntimeException(e);
42-
}
43-
44-
SoftReference<ClassStub> ref = stubCache.get(uri);
45-
ClassStub stub = (ref != null ? ref.get() : null);
46-
if (stub == null) {
47-
try (InputStream stream = new BufferedInputStream(URLStreams.openUncachedStream(url))) {
48-
ClassReader classReader = new ClassReader(stream);
49-
ClassNode classNode = new ClassNode();
50-
classReader.accept(classNode, 0);
51-
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
52-
classNode.accept(writer);
53-
byte[] bytes = writer.toByteArray();
54-
if (!AsmDecompileHelper.remove(classNode.visibleAnnotations, AsmDecompileHelper.SIDE)) {
55-
bytes = AsmDecompileHelper.transform(classNode.name, bytes);
56-
}
57-
58-
// now decompile the class normally
59-
groovyjarjarasm.asm.ClassReader classReader2 = new groovyjarjarasm.asm.ClassReader(bytes);
60-
groovyjarjarasm.asm.ClassVisitor decompiler = AsmDecompileHelper.makeGroovyDecompiler();
61-
classReader2.accept(decompiler, ClassReader.SKIP_FRAMES);
62-
stub = AsmDecompileHelper.getDecompiledClass(decompiler);
63-
stubCache.put(uri, new SoftReference<>(stub));
64-
} catch (IOException |
65-
ClassNotFoundException |
66-
NoSuchFieldException |
67-
NoSuchMethodException |
68-
IllegalAccessException |
69-
InvocationTargetException |
70-
InstantiationException e) {
71-
throw new RuntimeException(e);
72-
}
73-
}
74-
cir.setReturnValue(stub);
17+
// redirected in ClassNodeResolverMixin
18+
throw new UnsupportedOperationException();
7519
}
7620
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.cleanroommc.groovyscript.core.mixin.groovy;
2+
3+
import com.cleanroommc.groovyscript.sandbox.transformer.AsmDecompileHelper;
4+
import groovy.lang.GroovyClassLoader;
5+
import org.codehaus.groovy.ast.ClassHelper;
6+
import org.codehaus.groovy.ast.ClassNode;
7+
import org.codehaus.groovy.ast.decompiled.AsmReferenceResolver;
8+
import org.codehaus.groovy.ast.decompiled.ClassStub;
9+
import org.codehaus.groovy.ast.decompiled.DecompiledClassNode;
10+
import org.codehaus.groovy.control.ClassNodeResolver;
11+
import org.codehaus.groovy.control.CompilationUnit;
12+
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.Overwrite;
14+
import org.spongepowered.asm.mixin.Shadow;
15+
16+
@Mixin(value = ClassNodeResolver.class, remap = false)
17+
public abstract class ClassNodeResolverMixin {
18+
19+
@Shadow
20+
private static boolean isFromAnotherClassLoader(GroovyClassLoader loader, String fileName) {
21+
return false;
22+
}
23+
24+
@Shadow
25+
private static ClassNodeResolver.LookupResult tryAsScript(String name, CompilationUnit compilationUnit, ClassNode oldClass) {
26+
return null;
27+
}
28+
29+
/**
30+
* @author brachy
31+
* @reason properly find classes
32+
*/
33+
@Overwrite
34+
private ClassNodeResolver.LookupResult findDecompiled(final String name, final CompilationUnit compilationUnit, final GroovyClassLoader loader) {
35+
ClassNode node = ClassHelper.make(name);
36+
if (node.isResolved()) {
37+
return new ClassNodeResolver.LookupResult(null, node);
38+
}
39+
40+
DecompiledClassNode asmClass = null;
41+
ClassStub stub = AsmDecompileHelper.findDecompiledClass(name);
42+
if (stub != null) {
43+
asmClass = new DecompiledClassNode(stub, new AsmReferenceResolver((ClassNodeResolver) (Object) this, compilationUnit));
44+
if (!asmClass.getName().equals(name)) {
45+
// this may happen under Windows because getResource is case-insensitive under that OS!
46+
asmClass = null;
47+
}
48+
}
49+
50+
if (asmClass != null) {
51+
String fileName = name.replace('.', '/') + ".class";
52+
if (isFromAnotherClassLoader(loader, fileName)) {
53+
return tryAsScript(name, compilationUnit, asmClass);
54+
}
55+
56+
return new ClassNodeResolver.LookupResult(null, asmClass);
57+
}
58+
return null;
59+
}
60+
}

src/main/java/com/cleanroommc/groovyscript/sandbox/GroovyScriptClassLoader.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@ public Class<?> loadClass(final String name, boolean lookupScriptFiles, boolean
188188
cls = recompile(source, name);
189189
} catch (IOException ioe) {
190190
last = new ClassNotFoundException("IOException while opening groovy source: " + name, ioe);
191-
} finally {
192-
if (cls == null) {
193-
removeClassCacheEntry(name);
194-
} else {
195-
setClassCacheEntry(cls);
196-
}
197191
}
198192
}
199193

0 commit comments

Comments
 (0)