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

Bug 397152

Summary: [search] for declaration/occurrences of method wrongly finds homonym in anonymous class
Product: [Eclipse Project] JDT Reporter: Milos Gligoric <milos.gligoric>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: manju656, markus.kell.r
Version: 4.2.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Milos Gligoric CLA 2012-12-25 16:03:26 EST
Steps to reproduce:
1. See the instructions in code below
2. The resulting code does not compile

Build id: 20121114-2344

class ChangeMethodSignatureBug1 {

    void p() {
        new I() {
            public void m() {
            }
        };
        new J() {
            // This method will also be updated
            public void m() {
            }
        };
    }
}

interface I {
    // Invoke "Change Method Signature" on the method below
    void m();
}

interface J {
    void m();
}
Comment 1 Martin Mathew CLA 2012-12-31 00:23:49 EST
Issue is reproducible using I20121029-2000. The code refactoring results in compiler error.
Comment 2 Markus Keller CLA 2013-01-08 11:36:09 EST
Bug in the search engine, changing subject from "[change method signature] Updates a method in unrelated class which leads to a compilation error".


In ChangeSignatureProcessor.findOccurrences(..) line 1616, we create a search pattern like this:

    pattern= RefactoringSearchEngine.createOrPattern(fRippleMethods,
IJavaSearchConstants.ALL_OCCURRENCES);

fRippleMethods are I.m() and ChangeMethodSignatureBug1.new I().m().

The search result wrongly contains "ChangeMethodSignatureBug1.new J().m()" as well. This also happens when I change the pattern to

    pattern= SearchPattern.createPattern(fRippleMethods[0],
IJavaSearchConstants.DECLARATIONS, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE)

, only searching for declarations of the anonymous "new I().m()".

The supertype of the second anonymous also doesn't matter. It even fails here when I search for declarations of "new I().m()":

package p;

class ChangeMethodSignatureBug1 {

    void p() {
        new I() {
            public void m() {
            }
        };
        new Object() {
            // This method will also be updated
            public void m() {
            }
        };
    }
}

abstract class I {
    // Invoke "Change Method Signature" on the method below
    abstract void m();
}

=> Looks like there's a missing check whether a candidate method in a anonymous class is really declared in a subtype of the target method.
Comment 3 Eclipse Genie CLA 2019-02-19 20:31:04 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.