From a12e69774fcccbc63c4c2110de1b5a66b6dd25d7 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Wed, 24 Mar 2021 03:02:32 -0700 Subject: [PATCH] Add checkerframework nullness annotations to accepted list for AnnotationTest (#5409) Also use checkerframework annotations instead of jetbrains ones for Inventory#getContents as jetbrains ones do not allow properly annotating the nullability of an array and it's contents. --- Spigot-API-Patches/Adventure.patch | 35 +++++++++++++++++++ ...ventory-getContents-null-annotations.patch | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Spigot-API-Patches/Adventure.patch b/Spigot-API-Patches/Adventure.patch index c7929797a..b0f99f418 100644 --- a/Spigot-API-Patches/Adventure.patch +++ b/Spigot-API-Patches/Adventure.patch @@ -3597,3 +3597,38 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 void setColor(@NotNull ChatColor color); /** +diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/test/java/org/bukkit/AnnotationTest.java ++++ b/src/test/java/org/bukkit/AnnotationTest.java +@@ -0,0 +0,0 @@ import org.objectweb.asm.tree.ParameterNode; + public class AnnotationTest { + + private static final String[] ACCEPTED_ANNOTATIONS = { ++ // Paper start ++ "Lorg/checkerframework/checker/nullness/qual/Nullable;", ++ "Lorg/checkerframework/checker/nullness/qual/NonNull;", ++ "Lorg/checkerframework/checker/nullness/qual/PolyNull;", ++ "Lorg/checkerframework/checker/nullness/qual/MonotonicNonNull;", ++ // Paper end + "Lorg/jetbrains/annotations/Nullable;", + "Lorg/jetbrains/annotations/NotNull;", + "Lorg/jetbrains/annotations/Contract;", +@@ -0,0 +0,0 @@ public class AnnotationTest { + continue; + } + +- if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations)) { ++ if (mustBeAnnotated(Type.getReturnType(method.desc)) && !isWellAnnotated(method.invisibleAnnotations) && !isWellAnnotated(method.visibleTypeAnnotations)) { // Paper - also check visible type annotations + warn(errors, clazz, method, "return value"); + } + +@@ -0,0 +0,0 @@ public class AnnotationTest { + return true; + } + +- private static boolean isWellAnnotated(@Nullable List annotations) { ++ private static boolean isWellAnnotated(@Nullable List annotations) { // Paper - allow children of AnnotationNode + if (annotations == null) { + return false; + } diff --git a/Spigot-API-Patches/fix-Inventory-getContents-null-annotations.patch b/Spigot-API-Patches/fix-Inventory-getContents-null-annotations.patch index ce2e36032..3554dc4da 100644 --- a/Spigot-API-Patches/fix-Inventory-getContents-null-annotations.patch +++ b/Spigot-API-Patches/fix-Inventory-getContents-null-annotations.patch @@ -15,7 +15,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - @NotNull - public ItemStack[] getContents(); - -+ public @Nullable ItemStack @NotNull [] getContents(); // Paper - make array elements nullable instead array ++ public @org.checkerframework.checker.nullness.qual.Nullable ItemStack @org.checkerframework.checker.nullness.qual.NonNull [] getContents(); // Paper - make array elements nullable instead array + /** * Completely replaces the inventory's contents. Removes all existing