Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 367543 - [extract method] Method extraction does not check for overriding
Summary: [extract method] Method extraction does not check for overriding
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-25 08:57 EST by Max Schaefer CLA
Modified: 2019-10-22 19:50 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.