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.

Bug 53704 - [gjast] NPE from MDRParser
Summary: [gjast] NPE from MDRParser
Status: CLOSED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 4.x
Hardware: All Linux
: P1 blocker (vote)
Assignee: _ tball
URL:
Keywords:
: 53855 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-01-19 16:52 UTC by Pavel Flaska
Modified: 2007-09-26 09:14 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
NPE (3.62 KB, text/plain)
2005-01-19 16:53 UTC, Pavel Flaska
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Flaska 2005-01-19 16:52:29 UTC
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.
Comment 1 Pavel Flaska 2005-01-19 16:53:25 UTC
Created attachment 19792 [details]
NPE
Comment 2 Tomas Hurka 2005-01-19 17:00:23 UTC
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 }
Comment 3 Martin Matula 2005-01-24 12:48:51 UTC
*** Issue 53855 has been marked as a duplicate of this issue. ***
Comment 4 Martin Matula 2005-01-24 12:52:46 UTC
P2->P1 (see duplicate)
Comment 5 _ tball 2005-02-02 23:57:18 UTC
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.
Comment 6 Martin Matula 2005-02-03 12:41:56 UTC
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)
Comment 7 Martin Matula 2005-02-03 14:39:12 UTC
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
Comment 8 Martin Matula 2005-02-03 14:55:54 UTC
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.
Comment 9 Martin Matula 2005-02-07 14:15:27 UTC
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
Comment 10 Jiri Prox 2005-07-12 17:08:08 UTC
Verified in 4.2 (200507110943)
Comment 11 Quality Engineering 2007-09-20 10:08:40 UTC
Reorganization of java component