From 3f7eb83bd4254ae25b7bdf7a7bad0bb09bc1c03d Mon Sep 17 00:00:00 2001 From: Niels de Bruin Date: Mon, 28 Oct 2024 09:28:05 +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/dependencies/DependencyVulnerabilityCheck.java | 2 +- .../java/dependencies/RemoveExpiredSuppressions.java | 4 +++- .../openrewrite/java/dependencies/internal/VersionParser.java | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openrewrite/java/dependencies/DependencyVulnerabilityCheck.java b/src/main/java/org/openrewrite/java/dependencies/DependencyVulnerabilityCheck.java index 0d7c211..37a10a7 100644 --- a/src/main/java/org/openrewrite/java/dependencies/DependencyVulnerabilityCheck.java +++ b/src/main/java/org/openrewrite/java/dependencies/DependencyVulnerabilityCheck.java @@ -166,7 +166,7 @@ public Map> upgrade public static class Vulnerabilities { Map> gavToVulnerabilities; - public Set computeIfAbsent(ResolvedGroupArtifactVersion gav, Function> mappingFunction) { + public @Nullable Set computeIfAbsent(ResolvedGroupArtifactVersion gav, Function> mappingFunction) { return gavToVulnerabilities.computeIfAbsent(gav, mappingFunction); } } diff --git a/src/main/java/org/openrewrite/java/dependencies/RemoveExpiredSuppressions.java b/src/main/java/org/openrewrite/java/dependencies/RemoveExpiredSuppressions.java index 7b81cd0..fd2481e 100644 --- a/src/main/java/org/openrewrite/java/dependencies/RemoveExpiredSuppressions.java +++ b/src/main/java/org/openrewrite/java/dependencies/RemoveExpiredSuppressions.java @@ -15,6 +15,7 @@ */ package org.openrewrite.java.dependencies; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; @@ -41,8 +42,9 @@ public String getDescription() { @Override public TreeVisitor getVisitor() { return new XmlIsoVisitor() { + @Override - public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { + public @Nullable Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { Xml.Tag t = super.visitTag(tag, ctx); if (X_PATH_MATCHER.matches(getCursor())) { Optional untilAttribute = t.getAttributes().stream() diff --git a/src/main/java/org/openrewrite/java/dependencies/internal/VersionParser.java b/src/main/java/org/openrewrite/java/dependencies/internal/VersionParser.java index 2824b42..a78b9ea 100644 --- a/src/main/java/org/openrewrite/java/dependencies/internal/VersionParser.java +++ b/src/main/java/org/openrewrite/java/dependencies/internal/VersionParser.java @@ -16,6 +16,8 @@ package org.openrewrite.java.dependencies.internal; +import org.jspecify.annotations.Nullable; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -27,7 +29,7 @@ public class VersionParser { public VersionParser() { } - public Version transform(String original) { + public @Nullable Version transform(String original) { return cache.computeIfAbsent(original, this::parse); }