Skip to content

Commit 1d8041c

Browse files
authored
Merge pull request #1590 from PratikMane0112/fix/add-npe-check
Add NPE check and anonymous classes override logic in MigrateAcegiSecurityToSpringSecurity
2 parents 0b584b7 + e51399a commit 1d8041c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

plugin-modernizer-core/src/main/java/io/jenkins/tools/pluginmodernizer/core/recipes/MigrateAcegiSecurityToSpringSecurity.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.ArrayList;
55
import java.util.Collections;
66
import java.util.List;
7-
import java.util.Objects;
87
import java.util.UUID;
98
import java.util.stream.Collectors;
109
import org.openrewrite.ExecutionContext;
@@ -307,18 +306,24 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
307306
if (methodMatcher.matches(method, enclosingClass)) {
308307
JavaType.Method type = method.getMethodType();
309308

310-
if (!Objects.requireNonNull(method.getMethodType().getOverride())
309+
// Check if the method type and its override are available
310+
if (type == null || type.getOverride() == null) {
311+
LOG.debug(
312+
"Skipping migration for method without override information (e.g., in anonymous class): {}",
313+
method.getSimpleName());
314+
return super.visitMethodDeclaration(method, ctx);
315+
}
316+
317+
if (!type.getOverride()
311318
.toString()
312319
.equals(
313320
"hudson.security.SecurityRealm{name=loadUserByUsername,return=org.acegisecurity.userdetails.UserDetails,parameters=[java.lang.String]}")) {
314321
LOG.info(
315322
"Don't migrate this one to loadUserByUsername2 as it doesn't override the method of SecurityRealm, instead overrides of: {}",
316-
method.getMethodType().getOverride().toString());
323+
type.getOverride().toString());
317324
return super.visitMethodDeclaration(method, ctx);
318325
}
319-
if (type != null) {
320-
type = type.withName("loadUserByUsername2");
321-
}
326+
type = type.withName("loadUserByUsername2");
322327
method = method.withName(method.getName()
323328
.withSimpleName("loadUserByUsername2")
324329
.withType(type))

0 commit comments

Comments
 (0)