From 5918c626a6b577d93aa2633768fcc092a9029ddb Mon Sep 17 00:00:00 2001 From: yusshu Date: Tue, 26 Dec 2023 17:25:08 -0500 Subject: [PATCH] fix(compiler): add random integer to compiled script class name, prevents duplicates --- src/main/java/team/unnamed/mocha/runtime/MolangCompiler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/team/unnamed/mocha/runtime/MolangCompiler.java b/src/main/java/team/unnamed/mocha/runtime/MolangCompiler.java index 75f1e4b..340c49e 100644 --- a/src/main/java/team/unnamed/mocha/runtime/MolangCompiler.java +++ b/src/main/java/team/unnamed/mocha/runtime/MolangCompiler.java @@ -47,11 +47,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import static java.util.Objects.requireNonNull; @ApiStatus.Internal public final class MolangCompiler { + private static final Random RANDOM = new Random(); + private final ClassLoader classLoader; private final ClassPool classPool; @@ -118,7 +121,7 @@ public MolangCompiler(final @NotNull ClassLoader classLoader, final @NotNull Glo } final String scriptClassName = getClass().getPackage().getName() + ".MolangFunctionImpl_" + clazz.getSimpleName() + "_" + implementedMethod.getName() - + "_" + Long.toHexString(System.currentTimeMillis()); + + "_" + Long.toHexString(System.currentTimeMillis()) + "_" + Integer.toHexString(RANDOM.nextInt(2024)); try { CtClass scriptCtClass = classPool.makeClass(scriptClassName);