You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
InMemoryJavaCompiler.compile() returns reference to old class when compiling a new class with the same name #16
If I ask InMemoryJavaCompiler to compile a new class with the same name as an existing class, the compile() method returns a reference to the existing class.
Minimal example across two files, both in the default package, compiled and loaded on the classpath:
Example.java:
public class Example {
}
MinimalExample.java:
import org.mdkt.compiler.InMemoryJavaCompiler;
public class MinimalExample {
public static void main(String args[]) throws Exception {
Class<?> oldClass = Example.class;
InMemoryJavaCompiler compiler = InMemoryJavaCompiler.newInstance();
Class<?> newClass = compiler.compile("Example", "public class Example {\n }\n");
if (oldClass.hashCode() == newClass.hashCode()) {
System.out.println("I have two copies of the old class.");
}
}
}
Expected behaviour: the class returned by compile should be the result of compiling the string passed to it.
I think this is a bug.
Thanks very much for providing this library! I am very keen to use it in Gin :-)
Activity
drdrwhite commentedon Apr 11, 2018
Please could we get this pushed to Maven?
umeshshende commentedon Oct 2, 2020
Any update on this im facing same issue.