Bug 324189 - [search] Method declaration search returns false results (suffix match on type name)
Summary: [search] Method declaration search returns false results (suffix match on typ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 1.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Satyam Kandula CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 323213 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-09-01 09:11 EDT by Deepak Azad CLA
Modified: 2011-01-27 01:33 EST (History)
5 users (show)

See Also:
jarthana: review+


Attachments
proposed fix (952 bytes, patch)
2010-09-01 09:11 EDT, Deepak Azad CLA
no flags Details | Diff
Jar file exhibiting the inner class issue (2.56 KB, application/octet-stream)
2010-09-02 06:03 EDT, Frederic Fusier CLA
no flags Details
Proposed patch on HEAD (9.20 KB, patch)
2011-01-21 04:35 EST, Satyam Kandula CLA
no flags Details | Diff
Proposed patch on HEAD (9.13 KB, patch)
2011-01-21 06:23 EST, Satyam Kandula CLA
satyam.kandula: review?
Details | Diff
Patch in consideration (1.56 KB, patch)
2011-01-25 10:41 EST, Satyam Kandula CLA
no flags Details | Diff
Proposed patch (4.13 KB, patch)
2011-01-25 11:17 EST, Satyam Kandula CLA
Olivier_Thomann: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Azad CLA 2010-09-01 09:11:29 EDT
Created attachment 177946 [details]
proposed fix

I20100831-1001

Steps
- Do a type search for 'worker' 
=> no * is appended in this case - good

- Do a method search for 'Worker.run()' 
=> it essentially searches for '*worker.run()' and hence returns results like 'InternalWorker.run()' etc - bad

The correct search should be for '*.worker.run()', attached patch should fix the problem.
Comment 1 Frederic Fusier CLA 2010-09-01 11:35:59 EDT
Do you have a more precise reproducible test case?

I cannot get the described symptoms. All the matches I've found are potential ones and the attached patch does not change anything...
Comment 2 Dani Megert CLA 2010-09-01 11:39:57 EDT
>Do you have a more precise reproducible test case?
Do a method declaration search for "Worker.run" via search dialog
==>
java.util.concurrent.ThreadPoolExecutor.Worker.run()
javax.swing.SwingWorker.run()
sun.jdbc.odbc.ee.PoolWorker.run()
Comment 3 Frederic Fusier CLA 2010-09-01 13:32:32 EDT
(In reply to comment #2)
> >Do you have a more precise reproducible test case?
> Do a method declaration search for "Worker.run" via search dialog
> ==>
> java.util.concurrent.ThreadPoolExecutor.Worker.run()
> javax.swing.SwingWorker.run()
> sun.jdbc.odbc.ee.PoolWorker.run()

Yep, I got it now... :-)

The missing precise key word was 'declaration' as I was doing as references search...
Comment 4 Satyam Kandula CLA 2010-09-02 05:47:38 EDT
Deepak, Thanks for the patch but there is one small problem with the patch. It misses declarations from default packages. Let me see if I can get to fix that.
Comment 5 Frederic Fusier CLA 2010-09-02 06:01:17 EDT
(In reply to comment #4)
> Deepak, Thanks for the patch but there is one small problem with the patch. It
> misses declarations from default packages. Let me see if I can get to fix that.

Satyam,

Please note that this patch also misses binary inner class as their name is something like EnclosingClass$Inner which fails to match the "*.worker" pattern...
Comment 6 Frederic Fusier CLA 2010-09-02 06:03:58 EDT
Created attachment 178028 [details]
Jar file exhibiting the inner class issue

Search for type declaration of "Worker" on a project which has the attached jar on its classpath misses the Test.Worker inner class with the patch...
Comment 7 Satyam Kandula CLA 2010-09-02 06:17:09 EDT
(In reply to comment #5)
Frederic, Yes this test also fails. Thanks for this additional test and I will take care of it also whenever I get the fix.
Comment 8 Dani Megert CLA 2010-09-02 07:40:26 EDT
Note that this bug is not limited to JAR / binary types and has been there since day one.
Comment 9 Dani Megert CLA 2010-09-15 08:47:21 EDT
Also, it looks like all methods named 'run' but with completely different type name are reported as potential matches. This looks wrong to me.
Comment 10 Satyam Kandula CLA 2010-09-15 11:14:04 EDT
(In reply to comment #9)
> Also, it looks like all methods named 'run' but with completely different type
> name are reported as potential matches. This looks wrong to me
Those bindings which couldn't be resolved end up in the potential matches. We cannot do much with them.
Comment 11 Dani Megert CLA 2010-09-15 11:28:29 EDT
>Those bindings which couldn't be resolved end up in the potential matches. We
>cannot do much with them.
Why can't they be resolved? It happens in the simplest case:
1. new workspace
2. new Java project
3. search for "Worker.run"
Comment 12 Satyam Kandula CLA 2010-09-15 12:11:20 EDT
(In reply to comment #11)
> >Those bindings which couldn't be resolved end up in the potential matches. We
> >cannot do much with them.
> Why can't they be resolved? It happens in the simplest case:
> 1. new workspace
> 2. new Java project
> 3. search for "Worker.run"
As you would have noticed, this types should be from some dependent plugins. Most likely,that particular type's hierarchy is not completely resolved. However, I do agree that there could be some mistake there, mistake in not able to resolve that.
Comment 13 Markus Keller CLA 2010-09-15 12:15:13 EDT
Remember that this is a method *declaration* search. I don't think any types whose name doesn't match should be considered by this kind of search at all.
Comment 14 Satyam Kandula CLA 2010-09-16 00:49:57 EDT
(In reply to comment #13)
> Remember that this is a method *declaration* search. I don't think any types
> whose name doesn't match should be considered by this kind of search at all.
Don't you think it should check for method declarations of sub classes? I believe it will be required for refactorings.
Comment 15 Satyam Kandula CLA 2010-09-16 02:29:32 EDT
(In reply to comment #9)
> Also, it looks like all methods named 'run' but with completely different type
> name are reported as potential matches. This looks wrong to me.
Yup, these are coming from nested/anonymous classes and yes we should fix this.
Comment 16 Satyam Kandula CLA 2010-09-16 05:24:20 EDT
(In reply to comment #15)
> Yup, these are coming from nested/anonymous classes and yes we should fix this.
Filed bug 325418 to track this.
Comment 17 Satyam Kandula CLA 2010-09-16 05:28:17 EDT
(In reply to comment #13)
> Remember that this is a method *declaration* search. I don't think any types
> whose name doesn't match should be considered by this kind of search at all.
Are you telling that the subtypes should not be returned for method *declaration* search? Javadoc for DECLARATIONS tells 
###########
DECLARATIONS: will search declarations matching with the corresponding element. In case the element is a method, declarations of matching methods in sub-types will also be found, allowing to find declarations of abstract methods, etc.
##########
Comment 18 Markus Keller CLA 2010-09-16 06:09:43 EDT
> In case the element is a method, declarations of matching methods in sub-types
> will also be found, allowing to find declarations of abstract methods, etc.

You're right, and we can't change that API.

So the way to go is to add a 'limitTo' flag, e.g. IJavaSearchConstants.IGNORE_SUB_TYPES that implements a much faster search that only considers matching type names (if the type name is empty or "*", it should of course consider all types, but it still doesn't need to build any hierarchies).
Comment 19 Satyam Kandula CLA 2010-09-16 07:25:26 EDT
(In reply to comment #18)
> So the way to go is to add a 'limitTo' flag, e.g.
> IJavaSearchConstants.IGNORE_SUB_TYPES that implements a much faster search that
> only considers matching type names (if the type name is empty or "*", it should
> of course consider all types, but it still doesn't need to build any
> hierarchies).
Yes, I agree with this and will open a separate bug for this.
Comment 20 Deepak Azad CLA 2010-09-18 11:17:41 EDT
...as I suspected, this is not limited to Declaration Search

- Fresh Workspace
- Create the following 2 classes 
package p;
class A {
	void foo() {		
	}	
	public static void main(String[] args) {
		new A().foo();
	}
}

package p;
class AnotherA {
	void foo() {		
	}	
	public static void main(String[] args) {
		new AnotherA().foo();
	}
}

- Do a Java Search for 'A.foo()' with 'Method' and 'References' options selected (Search in = Java Sources) => 2 matches are returned!

(I also suspect that the fix will be same for declaration and reference search.)
Comment 21 Olivier Thomann CLA 2010-10-18 12:28:10 EDT
Moving to M4 to keep more time for APT work.
Comment 22 Olivier Thomann CLA 2010-11-29 15:10:09 EST
Moving again.
Comment 23 Satyam Kandula CLA 2011-01-21 04:35:36 EST
Created attachment 187262 [details]
Proposed patch on HEAD
Comment 24 Satyam Kandula CLA 2011-01-21 04:58:06 EST
Jay, Can you please review? Thanks.
Comment 25 Satyam Kandula CLA 2011-01-21 06:23:25 EST
Created attachment 187271 [details]
Proposed patch on HEAD

There is a problem in the test of the previous patch. Fixed it. No source changes.
Comment 26 Jay Arthanareeswaran CLA 2011-01-21 07:58:34 EST
Patch looks good to me.
Comment 27 Satyam Kandula CLA 2011-01-21 09:49:34 EST
Thanks Jay, Released the patch on HEAD.
Comment 28 Satyam Kandula CLA 2011-01-25 09:32:29 EST
Thanks Olivier for letting me know. This patch doesn't indeed fix the case mentioned in comment 20. Hence, reopening this bug.
Comment 29 Satyam Kandula CLA 2011-01-25 10:04:15 EST
Looks like comment 20 is a special case. If the length of the pattern is 1 (here the length of A is 1). bug 323213 runs into the same problem.
Comment 30 Satyam Kandula CLA 2011-01-25 10:11:01 EST
(In reply to comment #29)
> Looks like comment 20 is a special case. If the length of the pattern is 1
> (here the length of A is 1). bug 323213 runs into the same problem.
Actually it is not the length 1 that is the special case, but AnotherA starting and ending with A which being the pattern is making the test case fail. CharOperation.match() doesn't handle this case well!
Comment 31 Satyam Kandula CLA 2011-01-25 10:41:43 EST
Created attachment 187525 [details]
Patch in consideration

Patch that fixes the special test case in comment 20. This also fixes bug 323213. 
Test to follow.
Comment 32 Satyam Kandula CLA 2011-01-25 11:17:40 EST
Created attachment 187533 [details]
Proposed patch

Added tests also. 
I am running the full test suite.
Comment 33 Olivier Thomann CLA 2011-01-25 12:41:40 EST
Patch looks good to me. The regression test should be moved to the CharOperationTest test suite.
Comment 34 Satyam Kandula CLA 2011-01-25 13:13:21 EST
Moved the test to CharOperationTest and Released on HEAD.
Comment 35 Deepak Azad CLA 2011-01-26 02:15:55 EST
Verified with I20110125-2012.
Comment 36 Satyam Kandula CLA 2011-01-27 01:33:52 EST
*** Bug 323213 has been marked as a duplicate of this bug. ***