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 251864 - Broken refactoring on files generated by annotation processor
Summary: Broken refactoring on files generated by annotation processor
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Compiler (show other bugs)
Version: 8.0.1
Hardware: PC Linux
: P2 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-15 16:33 UTC by Jaroslav Tulach
Modified: 2015-09-15 01:23 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Stacktrace (6.04 KB, text/plain)
2015-04-15 17:25 UTC, Ralph Ruijs
Details
Diff of the first solution (2.54 KB, patch)
2015-09-14 14:10 UTC, Tomas Zezula
Details | Diff
Diff of the second solution (3.81 KB, patch)
2015-09-14 14:11 UTC, Tomas Zezula
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2015-04-15 16:33:19 UTC
I wanted to perform a package rename on my project and it consistently fails. First of all I thought it is a problem with some caches, but cleaning them didn't help. To reproduce get repository at following changeset:

https://github.com/jtulach/leaflet4j/commit/1007d55b4696b9d38d2d0b02f6f51a140404d8f9

build and open api project. Select the org.apidesign.html.leaflet.api package and rename it to xyz. Following exception appears:

Module Java Refactoring threw java.lang.IllegalStateException: endPosTable already set for : file:/home/jarda/.cache/netbeans/8.0.1/index/s19/java/14/sources/org/apidesign/html/leaflet/api/$JsCallbacks$.java.
Comment 1 Ralph Ruijs 2015-04-15 17:25:31 UTC
Created attachment 153218 [details]
Stacktrace

Full stacktrace of the problem when run on my machine, reassigning to java.source.

Only the second build was successful, the first one stopped with:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/ralph/work/leaflet4j/api/target/generated-sources/annotations/org/apidesign/html/leaflet/api/$JsCallbacks$.java:[2,14] duplicate class: org.apidesign.html.leaflet.api.$JsCallbacks$
[INFO] 1 error
[INFO] -------------------------------------------------------------
Comment 2 Svata Dedic 2015-05-11 14:06:24 UTC
The defect is triggered as follows:
the Refactoring executes an user task on a collection of files; the parsing API calls parser repeatedly for each of the file.s

The JavacParser reuses the *same* JavacTaskImpl for all files from the task's source collection.

In one particular iteraction, the parsed file contains an annotation, JavacProcessingEnvironment.doProcessing() calls annotation processor and an AP eventually generates $JsCallbacks$ file.

In another iteration, ANOTHER parsed files causes the same, but - since the JavacImpl is reused - the compiler detects that the source file has already linenumber attached (= it is being generated twice).

If we don't complete the AP processing, a particular one file may resolve identifiers incorrectly (classes not generated / missing). At the same time, APs flush their caches when processingOver() generating only partial content.

Reassigning to compiler + parsing API, suggestions welcome.
Comment 3 Tomas Zezula 2015-09-14 13:53:32 UTC
The exception is caused by a second parse of the generated file.
The file is generated from two source files in single javac.
There are 2 possibilities:

1st) Disable Processors for multi file task, in Ant projects they are disabled by default. So it's probably not big problem, the only problem I can imagine is missing errors generated by Processors.

2nd) The Processor running in TaskProcessor cannot write files, so the same file content is parsed for all files. The javac can be updated not to parse the generated file but take it directly from cache.

I will provide both impls as patches but for NB 8.1 integrate the first one as it's more safe. If someone complain we can integrate the second one in earlier release cycle.
Comment 4 Tomas Zezula 2015-09-14 14:10:17 UTC
Created attachment 156150 [details]
Diff of the first solution

Disabling processors for multi tasks.
Comment 5 Tomas Zezula 2015-09-14 14:11:38 UTC
Created attachment 156151 [details]
Diff of the second solution

JavacProcessingEnvironment patch not to parse generated files but use them from caches.
Comment 6 Tomas Zezula 2015-09-14 14:25:39 UTC
Fixed jet-main 093d8376d927.
Integrated the first solution.
Comment 7 Quality Engineering 2015-09-15 01:23:30 UTC
Integrated into 'main-silver', will be available in build *201509150002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/093d8376d927
User: Tomas Zezula <tzezula@netbeans.org>
Log: #251864:Broken refactoring on files generated by annotation processor