Community
Participate
Working Groups
When APT deletes a generated source file during build, using IFile.delete(), the corresponding class file does not get removed. This is due to what seems like a bug in JDT core. APT calls BuildContext.recordDeletedGeneratedFiles(). Later in the build, IncrementalImageBuilder.processAnnotations() reads that data and passes it to IncrementalImageBuilder.deleteGeneratedFiles(), which is supposed to delete the class files. But, deleteGeneratedFiles() starts out like this: for (int j = deletedGeneratedFiles.length; --j >= 0;) { SourceFile sourceFile = findSourceFile(deletedGeneratedFiles[j]); if (sourceFile == null) continue; And findSourceFile() starts out like this: if (!file.exists()) return null; So the result is that deleteGeneratedFiles() can't possibly do anything. In other words, deleteGeneratedFiles() seems to rely on the existence of the very same files whose deletion it is processing. I am not sure what the best fix is; one possibility might be for APT to not do the file deletion at all, and instead hand JDT a list of source files *to delete*.
I thought that was the original idea - you would leave it to JDT to delete the files.
That would be fine; but it does not appear to do that, either, if I'm reading the code correctly. It apparently only deletes class files.
Created attachment 59631 [details] Repro case Attaching a project that demonstrates the problem. Import this project into a workspace and build; open A.java; notice that gen.AGen is created, with a method foo(), so all references are resolved. Now, comment out the @Echo annotation. Notice that references are red-squiggled (due to type removal in reconcile). Save and build. Notice that there is NOT a problem in the problem pane, and that although AGen.java has been removed from the .apt_generated directory, AGen.class still exists in bin.
Reproduced. Will look into deleting the .class files assuming their corresponding source file has already been deleted... may even make it a condition that the source file is deleted.
Walter can you double check that APT is calling BuildContext.recordDeletedGeneratedFiles() with the source file AGen.java after its been deleted. It doesn't appear to happen with the supplied testcase.
It looks like I broke it in 3.3 while doing the refactoring for reconcile-time type generation. See bug 176883 for details. You should be able to see the behavior in 3.2.2. I'll also attach a patch for the 3.3 bug, so you can see it happen there. Sorry about that.
Created attachment 60499 [details] Patch for 3.3 This is not a complete fix for bug 176883, but it's good enough to let you see the present bug manifest in 3.3.
I've released a fix to bug 176883, so if you sync to HEAD this bug should be evident.
Created attachment 60602 [details] Proposed patch Walter - apply this to jdt.core HEAD & let me know what you think
That looks good to me. It fixes the problem, and when I step through it in the debugger it does what I would expect. Thanks.
Fixed and released in HEAD Extended ParticipantBuildTests.testBuildStarting() to test recordDeletedGeneratedFiles()
Verified for 3.3 M6 using build I20070319-1335