Bug 144776 - JavaProject.resetCaches() needs to reset dependent projects
Summary: JavaProject.resetCaches() needs to reset dependent projects
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-31 16:44 EDT by Jess Garms CLA
Modified: 2007-04-27 05:18 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix and regression test (4.68 KB, patch)
2007-04-26 07:23 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jess Garms CLA 2006-05-31 16:44:36 EDT
We’re ran into a problem with generated types in the Model in Eclipse
3.1.2 with APT. Let me describe the situation:

Project 1/
            Foo.java, which creates (via APT):
               FooGen.java

Project 2/
            Bar.java, which extends FooGen.java

Everything builds correctly from JDT’s perspective, but sometimes (about 1 in 3 on most machines), when APT is processing Bar.java in Project 2 after a full clean build has been started, it gets an inconsistent type hierarchy for it, and doesn’t see that Bar extends FooGen.

The reason for this is that after both projects caches were reset during a clean, a separate plugin (non-generic Eclipse) was requesting an AST from project 2. This would cause project 2's caches to get loaded. After that both projects were built. Type generation in project 1 causes its caches to be reset, but not project 2. Then when project 2 was built, it used its cache and failed to find the new generated types in project 2.

To work around this in 3.1.2, we added a call to JavaProject.resetCaches during our CompilationParticipant's build method, but obviously this is sub-optimal. Hopefully we can find a better solution for 3.2. I realize it may be too late for 3.2 proper, but since this problem requires a third-party plugin to actually occur, we could push this into 3.2.1.
Comment 1 Jess Garms CLA 2007-03-01 18:21:53 EST
Jerome - any chance of a fix to this in the 3.3 M6 timeframe?
Comment 2 Jerome Lanneluc CLA 2007-03-02 06:30:39 EST
I'm not sure to understand your diagnosis. The project cache only caches classpath entries, package fragment roots, and package fragments. It doesn't cache types. So I don't see why resetting this cache would make FooGen visible in the hierarchy.

Could you please provide more details on how to reproduce this issue ? A small plugin demonstrating the problem would be ideal.
Comment 3 Jess Garms CLA 2007-03-02 13:55:09 EST
Yes, that is the problem: the package fragment roots are cached. In this case, a new package is created for FooGen, which does not always get picked up when compiling Project 2. 

I'm afraid a repro is difficult to produce as it currently would require a large subset of our Eclipse-based product. Let me know if the info above is sufficient to describe what's happening. Thanks!
Comment 4 Jerome Lanneluc CLA 2007-03-05 12:40:39 EST
How is the package fragment created ? If you use IPackageFragmentRoot#createPackageFragement(...) this should reset the cache for you.
Comment 5 Jess Garms CLA 2007-03-21 19:07:15 EDT
Calling createPackageFragment() only seems to reset the cache in the *current* project, not in the dependent project. So in this case, Project 1 gets reset, but not Project 2.
Comment 6 Jerome Lanneluc CLA 2007-03-22 08:13:17 EDT
Thanks Jess. I now understand the problem. We should reset the caches of dependent projects as well in JavaModelOperation#run(IProgressMonitor) line 748.
Comment 7 Jerome Lanneluc CLA 2007-04-26 07:23:17 EDT
Created attachment 65007 [details]
Proposed fix and regression test
Comment 8 Jerome Lanneluc CLA 2007-04-26 11:05:08 EDT
Fix and test released for 3.3M7 in HEAD.
Comment 9 David Audel CLA 2007-04-27 05:18:18 EDT
Verified for 3.3 M7 using build I20070427-0010