[SPIGOT-1356] PotionEffectType.values() contains null Created: 19/Dec/15  Updated: 22/Dec/15  Resolved: 22/Dec/15

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: blablubbabc Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None


 Description   

Currently PotionAffectType.values() contains 'null' at index 0, because https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/potion/PotionEffectType.java#205 holding the potion effect types is initialized with a length of 24, and is used to directly map array index to the potion effect type. However, because there is no potion effect type with id 0, the array will contain null at that index.

This might be inconvenient / unexpected for plugins using PotionEffectType.values() (for example to iterate over all potion effect types), because they expect behavior similar to that of Enum.values() (which does not contain null) and plugins will then have to be aware of this and check for this special case.

Maybe it might be preferable to initialize the array with a length of 23 and map the potion effects to id-1 internally.
Or let values() return a sub-array starting at index 1.



 Comments   
Comment by md_5 [ 22/Dec/15 ]

Snapshot JavaDoc updated: "This array is not necessarily in any particular order and may contain null."

Comment by Black Hole [ 20/Dec/15 ]

Or just update JavaDoc.

Comment by blablubbabc [ 19/Dec/15 ]

Potion*EffectTypes

Generated at Thu Mar 27 04:22:36 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.