New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InvocationTargetException when compiling a class extending a class in the same file #117
Comments
Thanks for your report. Interesting, the following test fails with Java 8, but not with Java 17: @Test
public void x() {
Class<?> c = Reflect.compile( "p.A", "package p; public class A extends B {} class B {}").type();
System.out.println(c);
System.out.println(c.getSuperclass());
} With Java 17, it prints:
|
Yeah, there's substantially different logic for Java 9+ in Alternatively, can you just run those particular tests on a newer JDK? |
Cause of the issue here #81 , I already use a workaround in the tests as the processor produces new files: I made the processor able to redirect the intermediate data format without invoking the generation of the files, so I do not really need the compiled output, I just need the processor to get invoked. (As a nice side-effect, this enables me to test the processor without the complete generation of the files). I'm not sure whats causing this issue. When debugging my flaky test, I figured out that the order of classes matters when As I do not need any output of the compilation process, there is no need for my case to load any of the compiled classes. That could be an option for me, if there is no easy fix for the real problem but I'm not sure if you want to support such a case. Or probably thats already possible and I'm not aware of? |
It seems that Here are two tests with Java 8: This is an example which will always fail (that's your example from above):
and this one will always succeed:
I use randomly generated class names for my tests, thats why I got the flaky test. Now I could select in the corresponding test working class names to workaround this problem in my tests. Hopefully it helps you to check if there is anything you could do in jOOR to fix it. |
Yeah, thanks for the reproducers. Can confirm, both run fine on JDK 17, the first one fails on JDK 8 |
But that's a brittle thing to rely upon. Perhaps there's another way to "know" the correct order of classes without loading them? It would be possible with ASM, but I don't like the idea of adding that dependency... |
Well, the simplest solution I can think of is an |
Might be that there's an additional bug in the JDK 8 version, which seems unrelated. This test currently fails in the Java 8 distribution: @Test
public void testClassLoadingOrder3() {
Class<?> a = Reflect.compile("p.A", "package p; "
+ "public class A extends B {} "
+ "class B extends C {} "
+ "class C implements D {} "
+ "interface D extends E {} "
+ "interface E {}").type();
Class<?> b = a.getSuperclass();
Class<?> c = b.getSuperclass();
assertEquals("p.A", a.getName());
assertEquals("p.B", b.getName());
assertEquals("p.C", c.getName());
assertEquals(1, c.getInterfaces().length);
assertEquals("p.D", c.getInterfaces()[0].getName());
assertEquals(1, c.getInterfaces()[0].getInterfaces().length);
assertEquals("p.E", c.getInterfaces()[0].getInterfaces()[0].getName());
}
Your issue seems fixed now. Can you confirm this? |
Didnt tried it out, but when I'm looking at the commit I'm sure it will! Thank you very much! |
Expected behavior and actual behavior:
I got an InvocationTargetException for the compliation of a simple class which extends another class, which is in the same file:
I want to test an annotation processor, which detects the superclass of an annotated class. The superclass must be in the same package as the annotated class, which means I cannot simply extend an existing class like Object or Exception or the like.
Steps to reproduce the problem:
Reflect.compile( "sample.SampleClass", "package sample; public class SampleClass extends AnotherSampleClass{} class AnotherSampleClass{}");
My real test is actually flaky, i.e. it passes sometimes but I got also the Exception. The example above is a minimal example but seems to fail always.
Versions:
The text was updated successfully, but these errors were encountered: