From fc271fbed3aae04d72a17bde5a6d2305e0cf64ab Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 24 Mar 2019 19:13:07 -0400 Subject: [PATCH] Restore some SANITY around nullability annotations Some of these were wrong (scoreboard manager), others are counter to everything everyone expects (Locations world being null, which wasnt ever safe EVER) others are just too noisy. Replace some with Contract to get rid of the nullability constraint and go back to the old days of IDE not considering it strictly one way or the other. Also, stop requiring annotations on package-private. Introduces the next Developer Perk for Paper-API: Your plugin isn't yellow anymore. Also fixed random dupe code in ensureServerConversions that got mistakenly set in the update. --- .../Add-getI18NDisplayName-API.patch | 2 +- ...lip-some-Spigot-API-null-annotations.patch | 128 ++++++++++++++++++ ...rivate-methods-for-nullability-annot.patch | 21 +++ ...PI-additions-for-quantity-flags-lore.patch | 2 +- .../ItemStack-getMaxItemUseDuration.patch | 2 +- .../ensureServerConversions-API.patch | 7 +- 6 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 Spigot-API-Patches/Flip-some-Spigot-API-null-annotations.patch create mode 100644 Spigot-API-Patches/Ignore-package-private-methods-for-nullability-annot.patch diff --git a/Spigot-API-Patches/Add-getI18NDisplayName-API.patch b/Spigot-API-Patches/Add-getI18NDisplayName-API.patch index f00538b1fb..45785b2e65 100644 --- a/Spigot-API-Patches/Add-getI18NDisplayName-API.patch +++ b/Spigot-API-Patches/Add-getI18NDisplayName-API.patch @@ -29,7 +29,7 @@ index 8e602cf51..dca77bbaf 100644 // Paper end } diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java -index e8f97c949..b1c02ac0d 100644 +index 4ee01be5f..3ff3458e7 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java @@ -0,0 +0,0 @@ public class ItemStack implements Cloneable, ConfigurationSerializable { diff --git a/Spigot-API-Patches/Flip-some-Spigot-API-null-annotations.patch b/Spigot-API-Patches/Flip-some-Spigot-API-null-annotations.patch new file mode 100644 index 0000000000..e27d1d2676 --- /dev/null +++ b/Spigot-API-Patches/Flip-some-Spigot-API-null-annotations.patch @@ -0,0 +1,128 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Sun, 24 Mar 2019 18:39:01 -0400 +Subject: [PATCH] Flip some Spigot API null annotations + +while some of these may of been true, they are extreme cases and cause +a ton of noise to plugin developers. + +These do not help plugin developers if they bring moise noise than value. + +diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java +index 6b0a09067..5d6c856dd 100644 +--- a/src/main/java/org/bukkit/Bukkit.java ++++ b/src/main/java/org/bukkit/Bukkit.java +@@ -0,0 +0,0 @@ public final class Bukkit { + * + * @return the scoreboard manager or null if no worlds are loaded. + */ +- @Nullable ++ @NotNull // Paper + public static ScoreboardManager getScoreboardManager() { + return server.getScoreboardManager(); + } +@@ -0,0 +0,0 @@ public final class Bukkit { + * @param clazz the class of the tag entries + * @return the tag or null + */ +- @Nullable ++ @Contract("null, null, null -> fail") // Paper + public static Tag getTag(@NotNull String registry, @NotNull NamespacedKey tag, @NotNull Class clazz) { + return server.getTag(registry, tag, clazz); + } +diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java +index 57ce443a5..6b8dde716 100644 +--- a/src/main/java/org/bukkit/Location.java ++++ b/src/main/java/org/bukkit/Location.java +@@ -0,0 +0,0 @@ public class Location implements Cloneable, ConfigurationSerializable { + * @param y The y-coordinate of this new location + * @param z The z-coordinate of this new location + */ +- public Location(@Nullable final World world, final double x, final double y, final double z) { ++ public Location(@NotNull final World world, final double x, final double y, final double z) { // Paper + this(world, x, y, z, 0, 0); + } + +@@ -0,0 +0,0 @@ public class Location implements Cloneable, ConfigurationSerializable { + * @param yaw The absolute rotation on the x-plane, in degrees + * @param pitch The absolute rotation on the y-plane, in degrees + */ +- public Location(@Nullable final World world, final double x, final double y, final double z, final float yaw, final float pitch) { ++ public Location(@NotNull final World world, final double x, final double y, final double z, final float yaw, final float pitch) { // Paper + this.world = world; + this.x = x; + this.y = y; +@@ -0,0 +0,0 @@ public class Location implements Cloneable, ConfigurationSerializable { + * + * @return World that contains this location + */ +- @Nullable ++ @NotNull + public World getWorld() { + return world; + } +diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java +index 66d22ba79..08cd7cabc 100644 +--- a/src/main/java/org/bukkit/Server.java ++++ b/src/main/java/org/bukkit/Server.java +@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient { + * + * @return the scoreboard manager or null if no worlds are loaded. + */ +- @Nullable ++ @NotNull // Paper + ScoreboardManager getScoreboardManager(); + + /** +@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient { + * @param clazz the class of the tag entries + * @return the tag or null + */ +- @Nullable ++ @Contract("null, null, null -> fail") // Paper + Tag getTag(@NotNull String registry, @NotNull NamespacedKey tag, @NotNull Class clazz); + + /** +diff --git a/src/main/java/org/bukkit/inventory/ItemFactory.java b/src/main/java/org/bukkit/inventory/ItemFactory.java +index dca77bbaf..8335f8a8b 100644 +--- a/src/main/java/org/bukkit/inventory/ItemFactory.java ++++ b/src/main/java/org/bukkit/inventory/ItemFactory.java +@@ -0,0 +0,0 @@ import org.bukkit.Server; + import org.bukkit.inventory.meta.BookMeta; + import org.bukkit.inventory.meta.ItemMeta; + import org.bukkit.inventory.meta.SkullMeta; ++import org.jetbrains.annotations.Contract; + import org.jetbrains.annotations.NotNull; + import org.jetbrains.annotations.Nullable; + +@@ -0,0 +0,0 @@ public interface ItemFactory { + * @return a new ItemMeta that could be applied to an item stack of the + * specified material + */ +- @Nullable ++ @Contract() // Paper + ItemMeta getItemMeta(@NotNull final Material material); + + /** +diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java +index 1b19f8215..4a6dea561 100644 +--- a/src/main/java/org/bukkit/inventory/ItemStack.java ++++ b/src/main/java/org/bukkit/inventory/ItemStack.java +@@ -0,0 +0,0 @@ import org.bukkit.enchantments.Enchantment; + import org.bukkit.inventory.meta.Damageable; + import org.bukkit.inventory.meta.ItemMeta; + import org.bukkit.material.MaterialData; ++import org.jetbrains.annotations.Contract; + import org.jetbrains.annotations.NotNull; + import org.jetbrains.annotations.Nullable; + +@@ -0,0 +0,0 @@ public class ItemStack implements Cloneable, ConfigurationSerializable { + * + * @return a copy of the current ItemStack's ItemData + */ +- @Nullable ++ @Contract() // Paper + public ItemMeta getItemMeta() { + return this.meta == null ? Bukkit.getItemFactory().getItemMeta(this.type) : this.meta.clone(); + } +-- \ No newline at end of file diff --git a/Spigot-API-Patches/Ignore-package-private-methods-for-nullability-annot.patch b/Spigot-API-Patches/Ignore-package-private-methods-for-nullability-annot.patch new file mode 100644 index 0000000000..3055e88488 --- /dev/null +++ b/Spigot-API-Patches/Ignore-package-private-methods-for-nullability-annot.patch @@ -0,0 +1,21 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Sun, 24 Mar 2019 18:44:26 -0400 +Subject: [PATCH] Ignore package-private methods for nullability annotations + +This isn't API + +diff --git a/src/test/java/org/bukkit/AnnotationTest.java b/src/test/java/org/bukkit/AnnotationTest.java +index 596f28076..cdc0afc0c 100644 +--- a/src/test/java/org/bukkit/AnnotationTest.java ++++ b/src/test/java/org/bukkit/AnnotationTest.java +@@ -0,0 +0,0 @@ public class AnnotationTest { + + private static boolean isMethodIncluded(@NotNull ClassNode clazz, @NotNull MethodNode method, @NotNull Map allClasses) { + // Exclude private, synthetic and deprecated methods +- if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0) { ++ if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_DEPRECATED)) != 0 || (method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC)) == 0) { // Paper - ignore package-private + return false; + } + +-- \ No newline at end of file diff --git a/Spigot-API-Patches/ItemStack-API-additions-for-quantity-flags-lore.patch b/Spigot-API-Patches/ItemStack-API-additions-for-quantity-flags-lore.patch index 2af3e9a0af..d1ef10c26a 100644 --- a/Spigot-API-Patches/ItemStack-API-additions-for-quantity-flags-lore.patch +++ b/Spigot-API-Patches/ItemStack-API-additions-for-quantity-flags-lore.patch @@ -5,7 +5,7 @@ Subject: [PATCH] ItemStack API additions for quantity/flags/lore diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java -index 1c7bbbcef..845a9255d 100644 +index 345dc8bdc..1b19f8215 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java @@ -0,0 +0,0 @@ package org.bukkit.inventory; diff --git a/Spigot-API-Patches/ItemStack-getMaxItemUseDuration.patch b/Spigot-API-Patches/ItemStack-getMaxItemUseDuration.patch index b027c8ab4e..603063b08d 100644 --- a/Spigot-API-Patches/ItemStack-getMaxItemUseDuration.patch +++ b/Spigot-API-Patches/ItemStack-getMaxItemUseDuration.patch @@ -6,7 +6,7 @@ Subject: [PATCH] ItemStack#getMaxItemUseDuration Allows you to determine how long it takes to use a usable/consumable item diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java -index b1c02ac0d..1c7bbbcef 100644 +index 3ff3458e7..345dc8bdc 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java @@ -0,0 +0,0 @@ public class ItemStack implements Cloneable, ConfigurationSerializable { diff --git a/Spigot-API-Patches/ensureServerConversions-API.patch b/Spigot-API-Patches/ensureServerConversions-API.patch index 69a67bffdb..831b13a10c 100644 --- a/Spigot-API-Patches/ensureServerConversions-API.patch +++ b/Spigot-API-Patches/ensureServerConversions-API.patch @@ -29,7 +29,7 @@ index cbcbe8c8a..8e602cf51 100644 + // Paper end } diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java -index 7b709457f..e8f97c949 100644 +index 7b709457f..4ee01be5f 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java @@ -0,0 +0,0 @@ public class ItemStack implements Cloneable, ConfigurationSerializable { @@ -37,11 +37,6 @@ index 7b709457f..e8f97c949 100644 } - return result; -+ // Set damage again incase meta overwrote it -+ if (args.containsKey("damage")) { -+ result.setDurability(damage); -+ } -+ + return result.ensureServerConversions(); // Paper }