Bug 163733 - IncrementalImageBuilder.deleteGeneratedFiles() is broken
Summary: IncrementalImageBuilder.deleteGeneratedFiles() is broken
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-07 18:51 EST by Walter Harley CLA
Modified: 2007-03-20 11:45 EDT (History)
1 user (show)

See Also:


Attachments
Repro case (6.42 KB, application/octet-stream)
2007-02-23 02:41 EST, Walter Harley CLA
no flags Details
Patch for 3.3 (1.15 KB, patch)
2007-03-10 02:09 EST, Walter Harley CLA
no flags Details | Diff
Proposed patch (4.75 KB, patch)
2007-03-12 15:23 EDT, Kent Johnson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Walter Harley CLA 2006-11-07 18:51:26 EST
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*.
Comment 1 Kent Johnson CLA 2006-11-08 14:40:31 EST
I thought that was the original idea - you would leave it to JDT to delete the files.
Comment 2 Walter Harley CLA 2006-11-08 16:32:00 EST
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.
Comment 3 Walter Harley CLA 2007-02-23 02:41:20 EST
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.
Comment 4 Kent Johnson CLA 2007-03-09 15:30:28 EST
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.
Comment 5 Kent Johnson CLA 2007-03-09 16:17:00 EST
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.
Comment 6 Walter Harley CLA 2007-03-10 02:05:55 EST
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.
Comment 7 Walter Harley CLA 2007-03-10 02:09:10 EST
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.
Comment 8 Walter Harley CLA 2007-03-10 13:16:25 EST
I've released a fix to bug 176883, so if you sync to HEAD this bug should be evident.
Comment 9 Kent Johnson CLA 2007-03-12 15:23:33 EDT
Created attachment 60602 [details]
Proposed patch

Walter - apply this to jdt.core HEAD & let me know what you think
Comment 10 Walter Harley CLA 2007-03-12 16:16:04 EDT
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.
Comment 11 Kent Johnson CLA 2007-03-13 14:10:36 EDT
Fixed and released in HEAD

Extended ParticipantBuildTests.testBuildStarting() to test recordDeletedGeneratedFiles()
Comment 12 Eric Jodet CLA 2007-03-20 06:02:05 EDT
Verified for 3.3 M6 using build I20070319-1335