From cf5e329d65e7b7c33168ae4445e28f398a0cb89e Mon Sep 17 00:00:00 2001 From: martinfrancois Date: Tue, 11 Aug 2026 20:33:56 +0200 Subject: [PATCH] NullableOnMethodReturnType: add failing test for qualified nested return type moveNullableToNestedTypeSimpleName pins the correct placement of a TYPE_USE annotation on a qualified nested return type: Map.@Nullable Entry. The recipe currently emits public @Nullable Map.Entry, which javac rejects for a TYPE_USE-only annotation such as org.jspecify.annotations. Nullable. The limit was disclosed in #968. Marked @ExpectedToFail until fixed. --- .../NullableOnMethodReturnTypeTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/java/org/openrewrite/staticanalysis/NullableOnMethodReturnTypeTest.java b/src/test/java/org/openrewrite/staticanalysis/NullableOnMethodReturnTypeTest.java index 5eba00501..d87eab43a 100644 --- a/src/test/java/org/openrewrite/staticanalysis/NullableOnMethodReturnTypeTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/NullableOnMethodReturnTypeTest.java @@ -16,6 +16,7 @@ package org.openrewrite.staticanalysis; import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.ExpectedToFail; import org.openrewrite.DocumentExample; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -96,6 +97,39 @@ public class Foo { ); } + @ExpectedToFail("Annotation is placed before the qualified name, producing `@Nullable Map.Entry` which javac rejects") + @Test + void moveNullableToNestedTypeSimpleName() { + rewriteRun( + //language=java + java( + """ + import org.jspecify.annotations.Nullable; + + import java.util.Map; + + class Test { + @Nullable + public Map.Entry entry() { + return null; + } + } + """, + """ + import org.jspecify.annotations.Nullable; + + import java.util.Map; + + class Test { + public Map.@Nullable Entry entry() { + return null; + } + } + """ + ) + ); + } + @Test void dontTouchArguments() { rewriteRun(