Community
Participate
Working Groups
When a method cannot be compiled because of errors in its body we should try to preserve the annotations defined for the method. This would improve the usage of problem methods for JUnit4 tests. Using this test case, import org.junit.Test; public class MyJUnit4Test { @Test public void test1() { syntax error } @Test public void test2() { } } test1 is not failing in a JUnit 4 test harness. Since the @Test annotation is not preserved, the JUnit4 test harness doesn't "recognized" test1 as a JUnit test.
another example @interface Annot {} public class X { @Annot void foo() { # } @Annot void bar() { zork(); } @Annot void baz() {} } I'd like to see this one addressed for 3.4. Olivier - would you have time for it ? It seems that in ClassFile#generateMethodInfoAttribute(MethodBinding methodBinding, boolean createProblemMethod) we already check for problem methods, and bypass annotation dumping if so. Also, we should consider dumping problem type annotations as well.
I can quickly look at this one. I remembered that I got some NPE when enabling it, but maybe your support for problems in annotation might fix it.
You may want to wait until I am done with bug 196200. Some of the changes near annotation resilience have not been released yet (unclear whether you need them)
Philippe, What behavior do you want in the case the annotation contains problems ? Look at: org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test198 org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test219 org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test220 If I remove the filtering for problem method, I end up with ClassCastException when trying to generate the annotations for the three cases. In these cases, we might simply want to remove the annotations from the .class files. This would still be an improvement to the existing code where they are never present for problem methods. Let me know what you think and I'll adjust the implementation. Thanks.
Created attachment 87512 [details] Proposed fix This patch removes annotations that cannot be generated, but preserves the other ones.
Philippe, please review and let me know what you think. I'll add regression tests for this support.
Looks good to me.
Created attachment 87590 [details] new patch and regression tests Better patch. If the parameter annotations are not properly generated, they are now completely removed (works for visible or invisible annotations). I added a catch block for ShouldNotImplement exception.
Released for 3.4M5. Added regression tests in: org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test249 org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test250 org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test251 org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test252 org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test253 org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test254 org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test255 org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest#test256
Verified for 3.4M5 using I20080204-0010