Skip to content

Inline Method produces invalid lambda body when inlining method call in expression lambda #4432

Closed

Description

@EngTes1

Description

When using Inline Method in VS Code Java on a method call inside an expression lambda, the refactoring generates invalid Java code.

Steps to reproduce

  1. Create the following Java file in VS Code :
package org.example;

import java.util.function.Supplier;

public class sdad {
    // Refactoring operation: Inline Method
    static String getValue() {
        return "lambda";
    }

    public static void main(String[] args) {
        Supplier<String> s = () -> getValue(); // inline getValue here
        System.out.println(s.get());
        System.out.println("done");
    }
}
  1. Place the cursor on the invocation getValue inside the lambda expression:
Supplier<String> s = () -> getValue();
  1. Apply Inline Method.

Expected result

The method invocation inside the expression lambda should be replaced with a valid expression:

package org.example;

import java.util.function.Supplier;

public class sdad {
    // Refactoring operation: Inline Method
    static String getValue() {
        return "lambda";
    }

    public static void main(String[] args) {
        Supplier<String> s = () -> "lambda";
        System.out.println(s.get());
        System.out.println("done");
    }
}

Actual result

VS Code Java generates invalid code:

package org.example;

import java.util.function.Supplier;

public class sdad {
    // Refactoring operation: Inline Method
    static String getValue() {
        return "lambda";
    }

    public static void main(String[] args) {
        Supplier<String> s = () -> {"lambda"};
        System.out.println(s.get());
        System.out.println("done");
    }
}

The generated lambda body is:

() -> {"lambda"}

This is invalid Java syntax. A block lambda body cannot contain a bare string literal statement. Therefore, the refactored program fails to compile.

Activity

  1. datho7561 commented on Jun 17, 2026

    @datho7561
    Contributor

    I wasn't able to reproduce this failure, it generates () -> "lambda" for me. Could you please try it with the prerelease build and let me know if it still fails there?

  2. EngTes1 commented on Jun 18, 2026

    @EngTes1
    Author

    @datho7561 Hi, thanks for your reply.I just tried it with the latest prerelease build, and I can no longer reproduce this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions