This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
When you add the annotation to java enum, you will get the NPE. Steps to reproduce: i) Create enum in project, ii) connect annotation to the enum, iii) you will get the NPE. Another way: i) Run refactoring unit tests, ii) see results of RenameAnnAttributeTest.
Created attachment 19792 [details] NPE
It seems to me that gjast returns incorrect ASTree representing MODIFIERS for the case where enum has annotation. For example @MyAnnotation("aaa") public enum Test { AAA }
*** Issue 53855 has been marked as a duplicate of this issue. ***
P2->P1 (see duplicate)
I found a javac bug where enums with annotations were defined with the modifiers field having a bogus end position, and checked in a version of gjast that fixes this problem. Now Martin's test case dumps out as: . COMPILATION_UNIT [0,10] { . . null . . null . . TYPE_DECLARATIONS [0,10] { . . . ENUM_DECLARATION [0,10] { . . . . MODIFIERS [0,5] { . . . . . ANNOTATION [0,4] { . . . . . . IDENTIFIER(SuppressWarnings) [1,1] . . . . . . ELEMENT_VALUE_PAIRS [2,4] { . . . . . . . ELEMENT_VALUE_PAIR [3,3] { . . . . . . . . null . . . . . . . . STRING_LIT(aaa) [3,3] . . . . . . . } . . . . . . } . . . . . } . . . . . PUBLIC [5,5] . . . . } . . . . IDENTIFIER(Test) [7,7] . . . . null . . . . ENUM_BODY [8,10] { . . . . . ENUM_CONSTANTS [9,9] { . . . . . . ENUM_CONSTANT [9,9] { . . . . . . . IDENTIFIER(AAA) [9,9] . . . . . . . null . . . . . . . null . . . . . . } . . . . . } . . . . . null . . . . } . . . } . . } . } If this is correct, then there is a new problem in javacore when running the refactoring unit tests: testRenameAnnAttribute: java.lang.ArrayIndexOutOfBoundsException: 4 at org.netbeans.modules.javacore.jmiimpl.javamodel.JavaClassImpl.getPartEndTree(JavaClassImpl.java:938) at org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement.getPartEndOffset(MetadataElement.java:919) at org.netbeans.modules.refactoring.WhereUsedElement.<init>(WhereUsedElement.java:49) at org.netbeans.modules.refactoring.RenameUsageElement.<init>(RenameUsageElement.java:26) at org.netbeans.modules.refactoring.plugins.RenameRefactoringPlugin.addElementsForJmiObject(RenameRefactoringPlugin.java:422) at org.netbeans.modules.refactoring.plugins.RenameRefactoringPlugin.prepare(RenameRefactoringPlugin.java:362) at org.netbeans.modules.refactoring.api.AbstractRefactoring.pluginsPrepare(AbstractRefactoring.java:268) at org.netbeans.modules.refactoring.api.AbstractRefactoring.prepare(AbstractRefactoring.java:136) at org.netbeans.test.refactoring.rename.RenameAnnAttributeTest.testRenameAnnAttribute(RenameAnnAttributeTest.java:67) Although I am not experienced debugging the MDR support code, it looks like the test is failing because ENUM_DECLARATION only has four subtrees (CLASS_DECLARATION has six), so an index of four is too big.
Seems there is another bug in javacore. The problem in gjast related to annotations on enums seems to be fixed - files with annotations attached to enums can now be opened without failures. Find Usages however is still broken due to the bug in javacore. I am going to fix it. Also the gjast still returns a broken AST for annotations on enum constants. (the same exception is thrown)
Fixed the AIOOBE: Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationTypeImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationTypeImpl.java,v <-- AnnotationTypeImpl.java new revision: 1.11; previous revision: 1.10 done
I still get the same (or very similar) exception when I try to open a file containing the following: public @Deprecated enum NewEnum { @Deprecated CONSTANT1; } Probably the annotation at the enum constant is problematic. I am not sure, since when I remove one of the two occurrences of the @Deprecated annotation (any of them), the exception will disappear. This is probably also related to a bug I found in ASTree spec - it does not support annotations on enum constants. Reassigning back to Tom.
Fix merged to the q-build branch. Checking in external/gjast.jar.scrambled; /cvs/java/external/gjast.jar.scrambled,v <-- gjast.jar.scrambled new revision: 1.95.2.1; previous revision: 1.95 done Processing log script arguments... More commits to come... Checking in javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationTypeImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationTypeImpl.java,v <-- AnnotationTypeImpl.java new revision: 1.10.2.1; previous revision: 1.10 done Processing log script arguments... More commits to come... Checking in javacore/src/org/netbeans/modules/javacore/parser/ECRequestDescImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/parser/ECRequestDescImpl.java,v <-- ECRequestDescImpl.java new revision: 1.7.22.1; previous revision: 1.7 done
Verified in 4.2 (200507110943)
Reorganization of java component