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 227221 - Annotation processor run by internal compilation may recieve erroneous javax.lang.model information for generated enums
Summary: Annotation processor run by internal compilation may recieve erroneous javax....
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Compiler (show other bugs)
Version: 7.3
Hardware: All All
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-08 19:10 UTC by tms1979
Modified: 2015-09-17 11:15 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


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.
Comment 1 Martin Balin 2015-09-17 11:15:58 UTC
Report from old NetBeans version. Due to code changes since it was reported likely not reproducible now. Feel free to reopen if happens in 8.0.2 or 8.1.