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.
Summary: | Internal compilation not performed on all of multiple source files generated from a single annotated source file | ||
---|---|---|---|
Product: | java | Reporter: | tms1979 <tms1979> |
Component: | Compiler | Assignee: | Dusan Balek <dbalek> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P3 | ||
Version: | 7.1.2 | ||
Hardware: | PC | ||
OS: | Linux | ||
Issue Type: | DEFECT | Exception Reporter: | |
Attachments: | Test-project and var-cache-index-sXX directory |
Nailed it. Whether you hit the bug is dependent on what is passed as the vararg parameter for javax.annotation.processing.Filer.createSourceFile(...). According to the docs that parameter is described as: originatingElements - type or package elements causally associated with the creation of this file, may be elided or null If I pass null or the package element I don't hit the bug, but if I pass the type then all source files I've previously created are ignored for purposes of internal compilation. I guess that argument is used for something it shouldn't be, especially since a careless developer might pass any kind of javax.lang.model.element.Element there -- like I did in that sample project where I used the annotated element which could be a method. If I make sure sure not to pass anything for the originatingElements parameter in my annotation processor project then the IDE bugs I'm seeing in the projects using it goes away. Fixed in jet-main. Thanks for the test case. http://hg.netbeans.org/jet-main/rev/f6515b93042d Integrated into 'main-golden', will be available in build *201205050400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/f6515b93042d User: Dusan Balek <dbalek@netbeans.org> Log: Issue #211882: Internal compilation not performed on all of multiple source files generated from a single annotated source file - fixed. |
Created attachment 118904 [details] Test-project and var-cache-index-sXX directory I experence that the NetBeans internal compiler may not compile all source files generated from a single annotated source file. I've created a minimal test case where this occurs for me, which consists of an annotation processor project plus a project with this class: ----------- package testapapplication2; import testap2.GenerateAClass; @GenerateAClass(value="GeneratedClass") public class TestAPApplication2 { GeneratedClass generated; GeneratedClass2 generated2; @GenerateAClass(value="GeneratedClass2") public static void main(String[] args) { } } ----------- Here "GeneratedClass" and "GeneratedClass2" should be generated. Doing build makes both the generated source files appear under "Generated Sources (ap-source-output)", however the IDE still tags files in the Source Packages tree with errors that one of these generated classes are missing. In my exact case GeneratedClass is tagged as missing when used in a separate class ("testapapplication2.TestClass"). This behavior is consistent with what I see in the cache: ---- thormick@thormick-SH67H7 ~/.netbeans/7.1.2/var/cache/index/s104 $ ls -latR java/14/classes java/14/sources java/14/classes: total 12 drwxrwxr-x 2 thormick thormick 4096 2012-04-28 18:11 testapapplication2 drwxrwxr-x 6 thormick thormick 4096 2012-04-28 18:11 .. drwxrwxr-x 3 thormick thormick 4096 2012-04-28 18:11 . java/14/classes/testapapplication2: total 24 drwxrwxr-x 2 thormick thormick 4096 2012-04-28 18:11 . -rw-rw-r-- 1 thormick thormick 308 2012-04-28 18:11 GeneratedClass2.sig -rw-rw-r-- 1 thormick thormick 778 2012-04-28 18:11 TestAPApplication2.sig -rw-rw-r-- 1 thormick thormick 527 2012-04-28 18:11 TestClass.sig -rw-rw-r-- 1 thormick thormick 40 2012-04-28 18:11 TestAPApplication2.rapt drwxrwxr-x 3 thormick thormick 4096 2012-04-28 18:11 .. java/14/sources: total 12 drwxrwxr-x 2 thormick thormick 4096 2012-04-28 18:11 testapapplication2 drwxrwxr-x 6 thormick thormick 4096 2012-04-28 18:11 .. drwxrwxr-x 3 thormick thormick 4096 2012-04-28 18:11 . java/14/sources/testapapplication2: total 16 drwxrwxr-x 2 thormick thormick 4096 2012-04-28 18:11 . -rw-rw-r-- 1 thormick thormick 101 2012-04-28 18:11 GeneratedClass2.java -rw-rw-r-- 1 thormick thormick 100 2012-04-28 18:11 GeneratedClass.java drwxrwxr-x 3 thormick thormick 4096 2012-04-28 18:11 .. thormick@thormick-SH67H7 ~/.netbeans/7.1.2/var/cache/index/s104 $ find . | grep rapt ./java/14/classes/testapapplication2/TestAPApplication2.rapt thormick@thormick-SH67H7 ~/.netbeans/7.1.2/var/cache/index/s104 $ find . | grep rapt | xargs cat testapapplication2/GeneratedClass2.java ---- GeneratedClass.java and GeneratedClass2.java are generated by the annotation processor, but only GeneratedClass2.java is compiled by the internal compiler into a .sig file. In a larger project it was consistently the first source files generated for each annotated source file that were not compiled internally. I've seen this behavior off and on ever since annotation processor support was added. NetBeans would show missing class errors for generated classes in projects I've worked on even though they built just fine, with the error badges both in the project tab and opened files popping up and vanishing as files were touched and saved. Files that were marked as erroneous in the project tree due to this could also show no errors in the editor, and vice-versa. I wouldn't be surprised if the provided sample projects can be opened without error even if they can't for me, but please let me know what logging should be turned up if what I'm seeing can't be reproduced. The only interesting thing I've seen in messages.log is: WARNING [org.netbeans.modules.java.source.tasklist.IncorrectErrorBadges]: Incorrect error badges detected, file=/home/thormick/NetBeansProjects/TestAPApplication2/src/testapapplication2/TestClass.java. WARNING [org.netbeans.modules.java.source.tasklist.IncorrectErrorBadges]: Going to recompute root=/home/thormick/NetBeansProjects/TestAPApplication2/src, files in error=[]. Other times I've witnessed this behavior I've seen the following message repeated over and over in messages.log: INFO [org.netbeans.modules.java.hints.WrongPackageSuggestion]: source cp is either null or does not contain the compiled source cp= And also messages like the following once or twice: WARNING [org.netbeans.modules.java.source.parsing.JavacParser]: ClassPath identity changed for /home/thormick/NetBeansProjects/TestAPApplication2/build/generated-sources/ap-source-output/testapapplication2/GeneratedClass2.java@fbb9752e:1228f723, class path owner: /home/thormick/NetBeansProjects/TestAPApplication2 (class org.netbeans.modules.java.j2seproject.J2SEProject) original sourcePath: new sourcePath: null While searching for this I found one other bug (201511) that might be related. Help -> About: Product Version: NetBeans IDE 7.1.2 (Build 201204101705) Java: 1.7.0_147-icedtea; OpenJDK 64-Bit Server VM 21.0-b17 System: Linux version 3.0.0-12-generic running on amd64; UTF-8; en_US (nb) User directory: /home/thormick/.netbeans/7.1.2 Cache directory: /home/thormick/.netbeans/7.1.2/var/cache