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

Bug 367543

Summary: [extract method] Method extraction does not check for overriding
Product: [Eclipse Project] JDT Reporter: Max Schaefer <mschaefer>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: deepakazad, reprogrammer
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug

Description Max Schaefer CLA 2011-12-25 08:57:03 EST
Build Identifier: M20110909-1335

Test case:

  public class A {
    int foo() {
      int r = 42; // extract this line
      return r;
    }

    public static void main(String[] args) {
      System.out.println(new B().foo());
    }
  }

  class B extends A {
    public int m() {
      return 23;
    }
  }

This program prints 42. Extracting the indicated line into a new method m yields the following program, which prints 23:

  public class A {
    int foo() {
      int r = m();
      return r;
    }

    public int m() {
      int r = 42;
      return r;
    }

    public static void main(String[] args) {
      System.out.println(new B().foo());
    }
  }

  class B extends A {
    public int m() {
      return 23;
    }
  }

The problem is that the extracted method is overridden in B, so the extracted call m() resolves to B.m instead of the extracted method A.m on objects of class B.

Reproducible: Always

Steps to Reproduce:
See above.
Comment 1 Eclipse Genie CLA 2019-10-22 19:50:05 EDT
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.