From 33da18acda1d07b1aa0de96f6743c820168020d7 Mon Sep 17 00:00:00 2001 From: Niels de Bruin Date: Mon, 28 Oct 2024 11:47:09 +0100 Subject: [PATCH] refactor: add @Nullable to methods who may return null (#127) Use this link to re-run the recipe: https://app.moderne.io/builder/ji8mLIdUI?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..e092232 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 Xml.@Nullable 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); }