Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

InMemoryJavaCompiler.compile() returns reference to old class when compiling a new class with the same name #16

Open
drdrwhite opened this issue Nov 28, 2017 · 2 comments

Comments

@drdrwhite
Copy link

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 :-)

@drdrwhite
Copy link
Author

Please could we get this pushed to Maven?

@umeshshende
Copy link

Any update on this im facing same issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants