Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 211882 - Internal compilation not performed on all of multiple source files generated from a single annotated source file
Internal compilation not performed on all of multiple source files generated ...
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Compiler
7.1.2
PC Linux
: P3 (vote)
: 7.2
Assigned To: Dusan Balek
issues@java
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-30 20:59 UTC by tms1979
Modified: 2012-05-05 10:22 UTC (History)
0 users

See Also:
Issue Type: DEFECT
:


Attachments
Test-project and var-cache-index-sXX directory (87.27 KB, application/zip)
2012-04-30 20:59 UTC, tms1979
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tms1979 2012-04-30 20:59:52 UTC
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
Comment 1 tms1979 2012-05-01 18:51:29 UTC
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.
Comment 2 Dusan Balek 2012-05-03 13:47:00 UTC
Fixed in jet-main. Thanks for the test case.

http://hg.netbeans.org/jet-main/rev/f6515b93042d
Comment 3 Quality Engineering 2012-05-05 10:22:23 UTC
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.


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