Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345621

Summary: [search] There is no way to specify varargs in the search pattern
Product: [Eclipse Project] JDT Reporter: Xan <xan.xan>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r, Olivier_Thomann
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Xan CLA 2011-05-12 12:30:31 EDT
Build Identifier: 20110505-1223

"a.b.c.D.method(int, String[])" and "a.b.c.D.*(int, String[])"
do not return the same number of results.

If you have a class with only one method with the following signature:
public void method(int a, String[] strings)

Now you try to perform two searches for its references. One with the complete signature and the other one replacing the name of the method with wildcard. The two searchs must return the same number of results, But they don't!

In our case, the method has the following 4 references:
ref. 1 -> method(1);
ref. 2 -> method(2, "string");
ref. 3 -> method(3, "string1", "string2");
ref. 4 -> method(4, new String[] {"string1", "string2" });

Searching using the name of the method returns the 4 instances.
Searching with wildcard instead of the name of the method returns 2 instances (ref. 2 and 4).

Reproducible: Always

Steps to Reproduce:
1. Create a class (aka. TestingClass) with a public method with the following signature:
public void method(int a, String[] strings) {}

2. Create another class with one method which calls four times the method created in 1. The body of this method is the following:
TestingClass test = new TestingClass();
test.method(1);
test.method(2,"hola");
test.method(3,"hola", "dos");
test.method(4, new String[] {"hola", "uno"});

3. Search Menu option -> Java
In this dialog set the following information:
Search String: TestingClass.method(int, String[])
Search For: Method
Limit To: References
Search In: Sources

...and finally click Search...

The result are the expected 4 references.

4. Now Search Menu option -> Java
In this dialog set the following information:
Search String: TestingClass.*(int, String[])
Search For: Method
Limit To: References
Search In: Sources

...and finally click Search...
Now, the number of references found are 2.
Comment 1 Satyam Kandula CLA 2011-05-13 06:22:34 EDT
Is the method really taking String[] or String ...? Using String[], reference to method(1) is not correct. 
If it is String ..., currently the search pattern is not honouring the var arg, which should be fixed. 
However, I don't see a difference between using a wild card or otherwise. Please confirm if I am missing anything.
Comment 2 Xan CLA 2011-05-13 07:09:21 EDT
(In reply to comment #1)
> Is the method really taking String[] or String ...? Using String[], reference
> to method(1) is not correct. 
> If it is String ..., currently the search pattern is not honouring the var arg,
> which should be fixed. 
> However, I don't see a difference between using a wild card or otherwise.
> Please confirm if I am missing anything.

Yes, the method is taking 'String ...'

So the method signature is the following:
public void method(int a, String...strings)

As you say, there is no way to set this signature within the search pattern. So for searching, the pattern that i'm using is the following:
TestingClass.method(int, String[])

This pattern returns the four references of the method. And this is ok.

But the pattern:
TestingClass.*(int, String[])

only returns two references.

In this case, the class only has one method, so replacing the method name with wild card should return the same 4 instances.

Am I wrong?
Comment 3 Satyam Kandula CLA 2011-05-13 09:06:59 EDT
> TestingClass.method(int, String[])
> 
> This pattern returns the four references of the method. And this is ok.
I am seeing only two references here. If I select the method and then do search for references, I get four references. However, if I bring up the dialog box and search for the pattern, I only get two references irrespective of using the method name or *.
Comment 4 Xan CLA 2011-05-16 03:58:11 EDT
So, finally,

Are you saying that the problem comes from the search pattern?

The scenarios that we are currently aware of:

A.- If you select the method name and then do search, the proposed search pattern  is not correct, the varargs is replaced with an array syntax. But returns the 4 references of this method.


B.- If you bring up the search dialog and set the method name proposed by scenario 1. Only 2 references are found.

C.- Like scenario 2 but setting wildcard instead of the method name, 2 references are found as scenario 2.

Then, the problem is the following:

- The proposed search pattern when you select a method with var args is not correct. But all the references are found, but if you try to perform this search by hand (scenario 2), the results doesn't match the expected ones.

So, is there a solution for this problem? (or workaround)
Comment 5 Satyam Kandula CLA 2011-05-16 04:25:09 EDT
(In reply to comment #4)
> A.- If you select the method name and then do search, the proposed search
> pattern  is not correct, the varargs is replaced with an array syntax. But
> returns the 4 references of this method.
The varargs is not replaced with array syntax, but internally it stores a vararg state. 

> - The proposed search pattern when you select a method with var args is not
> correct. But all the references are found, but if you try to perform this
> search by hand (scenario 2), the results doesn't match the expected ones.
> 
> So, is there a solution for this problem? (or workaround)
As of now, only workaround is don't use the parameters for search. I will work for a solution.
Comment 6 Satyam Kandula CLA 2011-05-23 07:06:24 EDT
Modified the bug summary to reflect the real problem.
Comment 7 Eclipse Genie CLA 2019-11-04 07:02:30 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.