Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 357547 - [search] Search for method references is returning methods as overriden even if the superclass's method is only package-visible
Summary: [search] Search for method references is returning methods as overriden even ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.8 M7   Edit
Assignee: Satyam Kandula CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-13 15:30 EDT by Gustavo Soares CLA
Modified: 2012-04-30 04:17 EDT (History)
5 users (show)

See Also:
amj87.iitr: review+


Attachments
proposed patch for this bug (880 bytes, patch)
2012-02-29 15:26 EST, Samrat Dhillon CLA
no flags Details | Diff
Proposed patch (19.60 KB, patch)
2012-04-09 06:50 EDT, Satyam Kandula CLA
no flags Details | Diff
Updated patch (19.60 KB, patch)
2012-04-20 01:21 EDT, Satyam Kandula CLA
no flags Details | Diff
Updated patch (24.22 KB, patch)
2012-04-20 03:58 EDT, Satyam Kandula CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gustavo Soares CLA 2011-09-13 15:30:23 EDT
Build Identifier: 20110615-0604

The change method signature refactoring introduces a compilation error. 

Reproducible: Always

Steps to Reproduce:
1. Create the classes
package p2;
public class C {
}
package p1;
import p2.*;
public class B extends A {
  long k(){
    return 0;
  }
}
package p2;
public class A {
  long k(){
    return 1;
  }
  public long m(){
    return new A().k();
  }
}
2. Apply the change method signature refactoring to add a "int" parameter to B.k
package p1;
import p2.*;
public class B extends A {
  long k(int i){
    return 0;
  }
}

package p2;
public class C {
}

package p2;
public class A {
  long k(){
    return 1;
  }
  public long m(){
    return new A().k(0);
  }
}
3. The resulting program does not compile
Comment 1 Markus Keller CLA 2011-09-15 08:59:59 EDT
This is a bug in the search engine: A search for references to p1.B.k() should not find a match in p2.A.m(), since the package-visible p2.A.k() is *not* overridden by p1.B.k().
Comment 2 Olivier Thomann CLA 2011-09-15 11:08:12 EDT
Satyam, please investigate.
Comment 3 Samrat Dhillon CLA 2012-02-29 15:26:21 EST
Created attachment 211840 [details]
proposed patch for this bug

I found that the root cause is probably in org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java  isVirtualInvoke. I may not have fixed it in the best way. Basically checking if the method is private or if it is default and not in the same package then it is not a virtual invoke
Comment 4 Satyam Kandula CLA 2012-03-05 05:40:33 EST
Samrat, Thanks for the patch. The patch contains the changes required to fix the problem and that it is correct. It doesn't take care of null declaration qualification, which could be optional during search.

Do you want to fix this completely? If so, please try to fix this and try to get the testcase too. Otherwise, I could take this to completeness shortly. 

Thanks again.
Comment 5 Samrat Dhillon CLA 2012-03-05 09:37:45 EST
(In reply to comment #4)
> Samrat, Thanks for the patch. The patch contains the changes required to fix
> the problem and that it is correct. It doesn't take care of null declaration
> qualification, which could be optional during search.
> 
> Do you want to fix this completely? If so, please try to fix this and try to
> get the testcase too. Otherwise, I could take this to completeness shortly. 
> 
> Thanks again.

Satyam, can you please clarify a bit more. I am not sure if understand you correctly when you say "It doesn't take care of null declaration
 qualification, which could be optional during search."
Comment 6 Satyam Kandula CLA 2012-03-06 06:28:43 EST
(In reply to comment #5)
> Satyam, can you please clarify a bit more. I am not sure if understand you
> correctly when you say "It doesn't take care of null declaration
>  qualification, which could be optional during search."
If you do a Java search for references to <Type>.<Method>(), without qualifying <Type> at all, the this.pattern.declaringQualification could be null and there could be problems with the current patch.
Comment 7 Samrat Dhillon CLA 2012-03-07 11:48:55 EST
(In reply to comment #6)
> (In reply to comment #5)
> > Satyam, can you please clarify a bit more. I am not sure if understand you
> > correctly when you say "It doesn't take care of null declaration
> >  qualification, which could be optional during search."
> If you do a Java search for references to <Type>.<Method>(), without qualifying
> <Type> at all, the this.pattern.declaringQualification could be null and there
> could be problems with the current patch.

I think eclipse is not going in that path. If you do Java search for method references without specifying the type, mustResolve in MatchLocator.reportMatching is always set to false and hence MethodLocator.resolveLevel is never called. If you still think the patch needs tweaking please go ahead :)
Comment 8 Satyam Kandula CLA 2012-04-09 02:03:58 EDT
(In reply to comment #7)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > Satyam, can you please clarify a bit more. I am not sure if understand you
> > > correctly when you say "It doesn't take care of null declaration
> > >  qualification, which could be optional during search."
> > If you do a Java search for references to <Type>.<Method>(), without qualifying
> > <Type> at all, the this.pattern.declaringQualification could be null and there
> > could be problems with the current patch.
> 
> I think eclipse is not going in that path. If you do Java search for method
> references without specifying the type, mustResolve in
> MatchLocator.reportMatching is always set to false and hence
> MethodLocator.resolveLevel is never called. If you still think the patch needs
> tweaking please go ahead :)
Actually mentioning the type partially would run into this path. Fixing this seems to get more involved. Will attach a patch shortly.
Comment 9 Satyam Kandula CLA 2012-04-09 06:50:58 EDT
Created attachment 213744 [details]
Proposed patch
Comment 10 Satyam Kandula CLA 2012-04-09 06:52:18 EDT
Ayush, Can you review?
Comment 11 Ayushman Jain CLA 2012-04-19 06:57:59 EDT
(In reply to comment #10)
> Ayush, Can you review?

I have a few comments:
- copyrights need to be added to MatchLocator.

- In testBug357547c, A.k() - looks like u intended to make it default but made it public

- testBug357547b passes without the fix. Also, even if I change k() to public in A and B, it still does not return me any references. Does p*B.k() not include p1.B.k()? TO test more I created two more classes pp.ppB and pp.ppA with other things same as comment 0. Search for refs to p*B.k() should atleast return the call in ppA.m(), no?

- i think the condition added i.e. this.pattern.focus != null is always false in all the tests, which basically wipes out the effect of the other two conditions adjoing it. Is there a test case when focus is not null?

- Probably an existing problem: comment 0 example - right click on k() declared in B and search for declarations yields both B.k() and A.k(). However, search pattern is p1.B.k(). Why should A.k() be shown. When i search for p1.B.k from "java search" dialog i get only B.k() which looks correct.

- [unrelated] I get a warning on B.k() from comment 0 - The method B.k() does not override the inherited method from A since it is private to a different package. Quick fix offered is 'change visibility of A.k to default'. This is wrong. Will file a new UI bug for this.
Comment 12 Satyam Kandula CLA 2012-04-19 09:42:00 EDT
(In reply to comment #11)
Hi Ayush, Thanks for the review. 

> I have a few comments:
> - copyrights need to be added to MatchLocator.
There is not change in MatchLocator. Are you talking about something else? 

> 
> - In testBug357547c, A.k() - looks like u intended to make it default but made
> it public
That is true. I will change it. 

> 
> - testBug357547b passes without the fix. Also, even if I change k() to public
> in A and B, it still does not return me any references. Does p*B.k() not
> include p1.B.k()? TO test more I created two more classes pp.ppB and pp.ppA
> with other things same as comment 0. Search for refs to p*B.k() should atleast
> return the call in ppA.m(), no?
There looks like some other problem too. I will find that out. search for p*.B.k() works good. 

> 
> - i think the condition added i.e. this.pattern.focus != null is always false
> in all the tests, which basically wipes out the effect of the other two
> conditions adjoing it. Is there a test case when focus is not null?
testBug357547a is for that. 

> 
> - Probably an existing problem: comment 0 example - right click on k() declared
> in B and search for declarations yields both B.k() and A.k(). However, search
> pattern is p1.B.k(). Why should A.k() be shown. When i search for p1.B.k from
> "java search" dialog i get only B.k() which looks correct.
We should look at the package even in case of declarations. I will look at it. However, we intentionally report the B.k() adding some flavours to the search results. 


> - [unrelated] I get a warning on B.k() from comment 0 - The method B.k() does
> not override the inherited method from A since it is private to a different
> package. Quick fix offered is 'change visibility of A.k to default'. This is
> wrong. Will file a new UI bug for this.
I don't think this is wrong.
Comment 13 Ayushman Jain CLA 2012-04-19 11:12:22 EDT
(In reply to comment #12)
> (In reply to comment #11)
> Hi Ayush, Thanks for the review. 
> 
> > I have a few comments:
> > - copyrights need to be added to MatchLocator.
> There is not change in MatchLocator. Are you talking about something else? 
Sorry I meant MethodLocator, where Samrat had submitted the initial fix.

> > 
> > - i think the condition added i.e. this.pattern.focus != null is always false
> > in all the tests, which basically wipes out the effect of the other two
> > conditions adjoing it. Is there a test case when focus is not null?
> testBug357547a is for that. 
Oops yes I missed it

> > - [unrelated] I get a warning on B.k() from comment 0 - The method B.k() does
> > not override the inherited method from A since it is private to a different
> > package. Quick fix offered is 'change visibility of A.k to default'. This is
> > wrong. Will file a new UI bug for this.
> I don't think this is wrong.
Why not? The quick fix does not fix the problem, so its bogus, right?
Comment 14 Satyam Kandula CLA 2012-04-20 01:14:00 EDT
(In reply to comment #13)
> Sorry I meant MethodLocator, where Samrat had submitted the initial fix.
Samrat, can you give your copyright message. I would like to add in the file. 


> > > - [unrelated] I get a warning on B.k() from comment 0 - The method B.k() does
> > > not override the inherited method from A since it is private to a different
> > > package. Quick fix offered is 'change visibility of A.k to default'. This is
> > > wrong. Will file a new UI bug for this.
> > I don't think this is wrong.
> Why not? The quick fix does not fix the problem, so its bogus, right?
You are right. I didn't look at the message properly. It is a bug.
Comment 15 Satyam Kandula CLA 2012-04-20 01:21:56 EDT
Created attachment 214284 [details]
Updated patch

Updated according to Ayush's comments. 
- Made the change for search for declarations also to take care of the default, when a search pattern is used. Added a test for this. 
- Updated the tests (testBug357547b and testBug357547c) accoding to the comments. 
- Didn't fix the 'p*B' type reference problem mentioned for testBug357547b, as it is a separate issue.

Ayush, please have a look at this. Thanks.
Comment 16 Ayushman Jain CLA 2012-04-20 01:28:18 EDT
(In reply to comment #14)
> (In reply to comment #13)
> > Sorry I meant MethodLocator, where Samrat had submitted the initial fix.
> Samrat, can you give your copyright message. I would like to add in the file.
Samrat, the format is this:
Your Name <email@example.com> - Bug Title - https://bugs.eclipse.org/BUG_NUMBER

> > > > - [unrelated] I get a warning on B.k() from comment 0 - The method B.k() does
> > > > not override the inherited method from A since it is private to a different
> > > > package. Quick fix offered is 'change visibility of A.k to default'. This is
> > > > wrong. Will file a new UI bug for this.
Opened bug 377243
Comment 17 Satyam Kandula CLA 2012-04-20 01:42:20 EDT
(In reply to comment #15)
> Created attachment 214284 [details]
> Updated patch
> 
> Updated according to Ayush's comments. 
> - Made the change for search for declarations also to take care of the default,
> when a search pattern is used. Added a test for this. 
> - Updated the tests (testBug357547b and testBug357547c) accoding to the
> comments. 
> - Didn't fix the 'p*B' type reference problem mentioned for testBug357547b, as
> it is a separate issue.
> 
> Ayush, please have a look at this. Thanks.
Wrong patch.. will update with the new patch shortly.
Comment 18 Satyam Kandula CLA 2012-04-20 03:58:02 EDT
Created attachment 214290 [details]
Updated patch

Correct Patch as for comment 15
Comment 19 Samrat Dhillon CLA 2012-04-20 09:54:05 EDT
(In reply to comment #18)
> Created attachment 214290 [details]
> Updated patch
> 
> Correct Patch as for comment 15

Hi Satyam here is my copyright message.

Samrat Dhillon samrat.dhillon@gmail.com - Search for method references is returning methods as overriden even if the superclass's method is only package-visible - https://bugs.eclipse.org/357547
Comment 20 Ayushman Jain CLA 2012-04-23 01:10:16 EDT
+1. 
The two remaining issues can be handled in separate bugs:
- p*B.k() problem
- the second last point in comment 11
Comment 21 Satyam Kandula CLA 2012-04-23 02:19:11 EDT
(In reply to comment #20)
> +1. 
> The two remaining issues can be handled in separate bugs:
> - p*B.k() problem
> - the second last point in comment 11
Thanks Ayush for the review. 
Released this patch on master via commit 4f8b41427e5710e37012dc18560acc142566864b and commit 474e0db6559546cf5ac1476d3c4eb203e5f714e7
Comment 22 Jay Arthanareeswaran CLA 2012-04-30 04:16:05 EDT
(In reply to comment #20)
> +1. 
> The two remaining issues can be handled in separate bugs:
> - p*B.k() problem

I get the desired result if I use p*.B.k() - note the '.' after the '*'
Comment 23 Jay Arthanareeswaran CLA 2012-04-30 04:17:23 EDT
The fix for the bug as reported in comment #0 has been verified with build I20120429-1800