Skip to content

Commit

Permalink
fix(compiler): add random integer to compiled script class name, prev…
Browse files Browse the repository at this point in the history
…ents duplicates
  • Loading branch information
yusshu committed Dec 26, 2023
1 parent 0550b8e commit 5918c62
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/team/unnamed/mocha/runtime/MolangCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5918c62

Please sign in to comment.