eclipse-jdt / eclipse-jdt/eclipse.jdt.ui

[Bug][Inline Method Refactoring] Inline Method refactoring for input program contians Lambda in Method Argument produces uncompilable program

Open
#1,778 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
59
Forks
127
Avg merge
1d 8h
Merged PRs (30d)
37

Description

Steps to reproduce

  1. Create a class named A:
public class A {
    void baseMethod(Runnable action) {
        action.run();
    }
}
  1. Then, create a class named B:
public class B extends A {
    void derivedMethod() {
        super.baseMethod(() -> System.out.println("Lambda Action"));
    }

    static void staticContextMethod(B obj) {
        obj.derivedMethod(); // Inline call to derivedMethod()
    }
}
  1. Left click derivedMethod() in obj.derivedMethod(); like I comment in class B. Then, right click -> Refactor -> Inline. Use default configuration to inline this method like following, click ok:

image

The program is successfully refactored without any warning or exception. The refactored program is following, which contains syntax error:

public class A {
    void baseMethod(Runnable action) {
        action.run();
    }
}

public class B extends A {
    void derivedMethod() {
        super.baseMethod(() -> System.out.println("Lambda Action"));
    }

    static void staticContextMethod(B obj) {
        super.baseMethod(() -> System.out.println("Lambda Action")); // syntax error
    }
}
  1. If choose the first default configuration like following:

image

  1. The refactored program is following, which also contains syntax error:
public class A {
    void baseMethod(Runnable action) {
        action.run();
    }
}

public class B extends A {
    static void staticContextMethod(B obj) {
        super.baseMethod(() -> System.out.println("Lambda Action")); // syntax error
    }
}

Environment

OS Version

Windows 10, 64-bit Operating System, x64-based processor

Eclipse Version

Eclipse IDE for Enterprise Java and Web Developers (includes Incubating components)
Version: 2024-09 (4.33.0)
Build id: 20240905-0614

JDK Version

java version "22.0.1" 2024-04-16
Java(TM) SE Runtime Environment (build 22.0.1+8-16)
Java HotSpot(TM) 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Inline Method refactoring invoked on B.derivedMethod() from B.staticContextMethod(B obj), using the A and B reproducer in the issue. Check both default configurations and verify that the refactored program remains valid Java and compiles without the reported syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.