Bug 229128 - [search] Search finding matches in working copies that are not part of scope
Summary: [search] Search finding matches in working copies that are not part of scope
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 RC1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-28 13:52 EDT by Ernest Mah CLA
Modified: 2008-05-13 11:29 EDT (History)
3 users (show)

See Also:
frederic_fusier: review+


Attachments
Proposed fix and regression test (4.90 KB, patch)
2008-05-06 18:06 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 Ernest Mah CLA 2008-04-28 13:52:38 EDT
Build ID: I20080409-1425

Steps To Reproduce:
The problem seems to occur when I have any Java editors that are open and dirty (and the class it is editing also contains annotations).  These dirty editors are editing classes outside of the current project for which I obtain the package fragment roots.  

Here's the code, (arEls contains 2 PackageFragmentRoot objects, 1 is the single package in the src folder, and the other is the package in the '.apt_generated' folder, both from the same project).


		scope = SearchEngine.createJavaSearchScope(arEls);
		SearchPattern pattern = SearchPattern.createPattern("*", IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_PATTERN_MATCH); //$NON-NLS-1$
		if(pattern!=null)
		{
				
			try
			{
				searchEngine.search(pattern, participats, scope, requestor, null);
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}

The above search is returning even those modified classes outside of the two package fragments as matches in the acceptSearchMatch() api in my searchrequestor class.

I noticed there was code BasicSearchEngine.findMatches() at line 216 where working copies are added:
		SearchDocument[] matches = MatchLocator.addWorkingCopies(pattern, indexMatches, getWorkingCopies(), participant);

Does the code in addWorkingCopies limit the working copies added to those that are also part of the search scope?
Comment 1 Jerome Lanneluc CLA 2008-05-06 18:06:42 EDT
Created attachment 98974 [details]
Proposed fix and regression test
Comment 2 Jerome Lanneluc CLA 2008-05-06 18:07:13 EDT
Frederic, could you please review?
Comment 3 Frederic Fusier CLA 2008-05-07 03:46:58 EDT
Patch looks good to me: +1
Comment 4 Jerome Lanneluc CLA 2008-05-07 07:06:51 EDT
Fix and test released for 3.4RC1
Comment 5 David Audel CLA 2008-05-13 11:29:27 EDT
Verified for 3.4RC1 using I20080510-2000