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
- 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");
}
}
- Place the cursor on the invocation
getValue inside the lambda expression:
Supplier<String> s = () -> getValue();
- 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:
This is invalid Java syntax. A block lambda body cannot contain a bare string literal statement. Therefore, the refactored program fails to compile.
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
getValueinside the lambda expression:Expected result
The method invocation inside the expression lambda should be replaced with a valid expression:
Actual result
VS Code Java generates invalid code:
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.