From 8f3cc213a2ace9244308984f2005b3dce3dc73e8 Mon Sep 17 00:00:00 2001 From: Niels de Bruin Date: Mon, 28 Oct 2024 09:28:24 +0000 Subject: [PATCH] refactor: Annotate methods which may return `null` with `@Nullable` Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.AnnotateNullableMethods?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne --- .../java/migrate/joda/templates/TimeClassMap.java | 5 +++-- .../java/migrate/util/RemoveFinalizerFromZip.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeClassMap.java b/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeClassMap.java index 80fbaeb52c..4fbc099cb9 100644 --- a/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeClassMap.java +++ b/src/main/java/org/openrewrite/java/migrate/joda/templates/TimeClassMap.java @@ -15,6 +15,7 @@ */ package org.openrewrite.java.migrate.joda.templates; +import org.jspecify.annotations.Nullable; import org.openrewrite.java.tree.JavaType; import java.util.HashMap; @@ -48,11 +49,11 @@ private static JavaType.Class javaTypeClass(String fqn, JavaType.Class superType null, null, null, null, null); } - public static JavaType.Class getJavaTimeType(String typeFqn) { + public static @Nullable JavaType.Class getJavaTimeType(String typeFqn) { return new TimeClassMap().jodaToJavaTimeMap.get(typeFqn); } - public static String getJavaTimeShortName(String typeFqn) { + public static @Nullable String getJavaTimeShortName(String typeFqn) { return new TimeClassMap().jodaToJavaTimeShortName.get(typeFqn); } } diff --git a/src/main/java/org/openrewrite/java/migrate/util/RemoveFinalizerFromZip.java b/src/main/java/org/openrewrite/java/migrate/util/RemoveFinalizerFromZip.java index 4934c9f612..e156c90e2d 100644 --- a/src/main/java/org/openrewrite/java/migrate/util/RemoveFinalizerFromZip.java +++ b/src/main/java/org/openrewrite/java/migrate/util/RemoveFinalizerFromZip.java @@ -18,6 +18,7 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; import org.openrewrite.Recipe; @@ -62,8 +63,9 @@ public TreeVisitor getVisitor() { new UsesType<>(JAVA_UTIL_ZIP_INFLATER, false), new UsesType<>(JAVA_UTIL_ZIP_ZIP_FILE, false))), new JavaVisitor() { + @Override - public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { + public @Nullable J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { J.MethodInvocation mi = (J.MethodInvocation) super.visitMethodInvocation(method, ctx); if (METHOD_MATCHER.matches(mi)) {