Skip to content

Commit

Permalink
Update method type as well when removing arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Nov 21, 2024
1 parent c19d89e commit f555b56
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private J.Lambda createLambdaParam(String paramName, JavaType paramType, List<J.
J.MethodInvocation body = unfoldMethodInvocationChain(createIdentifier(paramName, paramType), chain);
return new J.Lambda(Tree.randomId(), Space.EMPTY, Markers.EMPTY,
new J.Lambda.Parameters(Tree.randomId(), Space.EMPTY, Markers.EMPTY, false, Collections.singletonList(new JRightPadded<>(param, Space.EMPTY, Markers.EMPTY))),
Space.build(" ", Collections.emptyList()),
Space.build(" ", emptyList()),
body,
JavaType.Primitive.Void
);
Expand All @@ -145,9 +145,19 @@ private J.MethodInvocation unfoldMethodInvocationChain(J.Identifier core, List<J
if (XSS_PROTECTION_ENABLED.matches(invocation)) {
if (J.Literal.isLiteralValue(invocation.getArguments().get(0), false)) {
invocation = invocation.withName(invocation.getName().withSimpleName("disable")).withArguments(null);
JavaType.Method methodType = invocation.getMethodType();
if (methodType != null) {
methodType = methodType.withParameterNames(emptyList()).withParameterTypes(emptyList());
invocation = invocation.withMethodType(methodType).withName(invocation.getName().withType(methodType));
}
} else {
// Enabled by default; but returning `null` will cause issues, so we use `and()` as a placeholder
invocation = invocation.withName(invocation.getName().withSimpleName("and")).withArguments(null);
JavaType.Method methodType = invocation.getMethodType();
if (methodType != null) {
methodType = methodType.withParameterNames(emptyList()).withParameterTypes(emptyList());
invocation = invocation.withMethodType(methodType).withName(invocation.getName().withType(methodType));
}
}
}
select = invocation;
Expand Down Expand Up @@ -261,7 +271,7 @@ private List<J.MethodInvocation> computeAndMarkChain() {
}
}
if (cursor == null || chain.isEmpty()) {
return Collections.emptyList();
return emptyList();
}
if (!(cursor.getValue() instanceof J.MethodInvocation)) {
// top invocation is at the end of the chain - mark it. We'd need to strip off prefix from this invocation later
Expand Down

0 comments on commit f555b56

Please sign in to comment.