Bug 227221 - Annotation processor run by internal compilation may recieve erroneous javax.lang.model information for generated enums
Annotation processor run by internal compilation may recieve erroneous javax....
Status: NEW
Product: java
Classification: Unclassified
Component: Compiler
7.3
All All
: P3 (vote)
: TBD
Assigned To: Dusan Balek
issues@java
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-03-08 19:10 UTC by tms1979
Modified: 2013-03-08 19:10 UTC (History)
0 users

See Also:
Issue Type: DEFECT
:


Attachments
Test case for internal-compiled enum error (33.68 KB, application/zip)
2013-03-08 19:10 UTC, tms1979
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tms1979 2013-03-08 19:10:14 UTC
Created attachment 132391 [details]
Test case for internal-compiled enum error

Annotation processors may not recieve correct javax.lang.model information for generated enum types when run via internal compilation. The exact result seems to depend on whether the enum type is directly accessible via a annotation processing root element, with indirectly accessible enums showing up with TypeKind DECLARED but whose Element does not provide correct information.

The enclosed test-case provides a demonstration of this, it should behave correctly and produce the correct output when built in the editor, but also write debug messages to System.err that should show up in the NetBeans log and show the error.

A compile and build of the TestAPApp4 project should show compilation output of what happens during a correct compilation from scratch. Most notably is the check of the field that is of an enum type:

checking field: testEnumContainingClass
checking: someField, of type: GeneratedEnum, doesn't exist yet but will hopefully be generated: ERROR

If one touches and saves TestAPApp4 then does a compile file or build project the compilation output should show correct behavior when the generated enum source file already exists, notably are the lines corresponding to the above example:

checking field: testEnumContainingClass
checking: someField, of type: testapapp4.GeneratedEnum, existing kind: DECLARED
Note: OK: Type testapapp4.GeneratedEnum is of ENUM kind. 5 enclosed elements.

However, at this point (or after another touch-and-save of TestAPApp4 without an explicit build, I'm not 100% of the order and the first run after a clean and build sometimes works) the netbeans log in $userdir/var/log/messages.log should contain an erroneous run via internal compilation:

checking field: testEnumContainingClass
checking: someField, of type: testapapp4.GeneratedEnum, existing kind: DECLARED
 *** ERROR! *** testapapp4.GeneratedEnum is not an ENUM type! Element-kind of field type: CLASS. 0 enclosed elements.

Quite notably a touch-and-save of TestClassWithEnumField (which contains a field of the generated enum type) provides different output in messages.log:

checking field: testEnumContainingClass
checking: someField, of type: <any>, doesn't exist yet but will hopefully be generated: ERROR

This latter behavior is actually preferrable to me, because it's not too important for my part whether I get a TypeKind.ERROR (which just makes my AP re-generate the class) or a correct declared-type; only a TypeKind.DECLARED with erroneous data breaks things for me.


Also, keep an eye on the "X enclosed elements" value for enums. I've seen that it has differed between runs for the same type, for both generated and normal enums, but I haven't seen a pattern there.


This was first observed in (a lightly patched) 7.2 before reproduced in standard 7.3.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo