|
4 | 4 | import java.util.ArrayList; |
5 | 5 | import java.util.Collections; |
6 | 6 | import java.util.List; |
7 | | -import java.util.Objects; |
8 | 7 | import java.util.UUID; |
9 | 8 | import java.util.stream.Collectors; |
10 | 9 | import org.openrewrite.ExecutionContext; |
@@ -307,18 +306,24 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex |
307 | 306 | if (methodMatcher.matches(method, enclosingClass)) { |
308 | 307 | JavaType.Method type = method.getMethodType(); |
309 | 308 |
|
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() |
311 | 318 | .toString() |
312 | 319 | .equals( |
313 | 320 | "hudson.security.SecurityRealm{name=loadUserByUsername,return=org.acegisecurity.userdetails.UserDetails,parameters=[java.lang.String]}")) { |
314 | 321 | LOG.info( |
315 | 322 | "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()); |
317 | 324 | return super.visitMethodDeclaration(method, ctx); |
318 | 325 | } |
319 | | - if (type != null) { |
320 | | - type = type.withName("loadUserByUsername2"); |
321 | | - } |
| 326 | + type = type.withName("loadUserByUsername2"); |
322 | 327 | method = method.withName(method.getName() |
323 | 328 | .withSimpleName("loadUserByUsername2") |
324 | 329 | .withType(type)) |
|
0 commit comments