What version of OpenRewrite are you using?
rewrite-core 8.81.1
rewrite-migrate-java 3.34.0
What is the smallest, simplest way to reproduce the problem?
@Test
void typedLambdaParameterRenamedToUnderscoreNeedsParentheses() {
rewriteRun(
spec -> spec.recipe(new ReplaceUnusedVariablesWithUnderscore()),
java(
"""
package com.helloworld;
public class Main {
interface Handler {
String handle(RequestContext context);
}
static class RequestContext {}
Handler route() {
return (RequestContext rc) -> {
return "result";
};
}
}
""",
spec -> spec.markers(javaVersion(25))));
}
What did you expect to see?
The explicitly typed lambda parameter should remain parenthesized:
Handler route() {
return (RequestContext _) -> {
return "result";
};
}
What did you see instead?
The recipe emits invalid Java:
Handler route() {
return RequestContext _ -> {
return "result";
};
}
What is the full stack trace of any errors you encountered?
The invalid output later failed Java formatting/parsing with errors like:
error: ')' or ',' expected
RequestContext _ -> {
^
error: not a statement
RequestContext _ -> {
^
What version of OpenRewrite are you using?
rewrite-core8.81.1rewrite-migrate-java3.34.0What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
The explicitly typed lambda parameter should remain parenthesized:
What did you see instead?
The recipe emits invalid Java:
What is the full stack trace of any errors you encountered?
The invalid output later failed Java formatting/parsing with errors like: