Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7637

Bad logic in checking nullability of AttributeModifier slots

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • Java 21

    • 1.20.5-R0.1-SNAPSHOT
    • Yes

      AttributeModifier changed from storing a Nullable EquipmentSlot to a NotNull EquipmentSlotGroup at some point (I think with 1.20.5?), but there's a nullability flaw with the API implementation here.

      1. Instantiating AttributeModifier without an EquipmentSlotGroup or EquipmentSlot will invoke the fat constructor with `(EquipmentSlotGroup) null` - despite the EquipmentSlotGroup arg there being NotNull annotated [1]
      2. Since there's no Preconditions.checkArgument for passing null to this Notnull-annotated argument, the constructor works and instantiates an AttriuteModifier with slot as null
      3. This causes calls to the deprecated getSlot [2] method to throw NullPointerException, since that method tries to invoke getExample() on slot (which is null)

      Suggested fix: Add a Preconditions check preventing slot from being passed as null and change the constructor call here to pass null to the other constructor which accepts an EquipmentSlot (which correctly converts EquipmentSlot to EquipmentSlotGroup in a ternary).

      Thanks for your hard work.

      1. https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/attribute/AttributeModifier.java#30-32
      2. https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/attribute/AttributeModifier.java#97-99

            DerFrZocker Marvin Rieple
            William278 William278
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: