diff options
author | MikeMatrix <m.braun92@gmail.com> | 2013-01-11 02:07:38 +0100 |
---|---|---|
committer | feildmaster <admin@feildmaster.com> | 2013-01-15 05:05:20 -0600 |
commit | cdba964122a9ad6238f549b38a438cb3722495ae (patch) | |
tree | 1b474f79ff411fbe28a4cef65ff8d497ed1d45bc | |
parent | a809f5bf0e42617900d94061163e0ff4196027ce (diff) | |
download | bukkit-cdba964122a9ad6238f549b38a438cb3722495ae.tar bukkit-cdba964122a9ad6238f549b38a438cb3722495ae.tar.gz bukkit-cdba964122a9ad6238f549b38a438cb3722495ae.tar.lz bukkit-cdba964122a9ad6238f549b38a438cb3722495ae.tar.xz bukkit-cdba964122a9ad6238f549b38a438cb3722495ae.zip |
Added negative id check to Material.getMaterial(int). Fixes BUKKIT-3414
Negative id values would try to access the array out of bounds and throw an java.lang.ArrayIndexOutOfBoundsException.
-rw-r--r-- | src/main/java/org/bukkit/Material.java | 2 | ||||
-rw-r--r-- | src/test/java/org/bukkit/MaterialTest.java | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 1a726104..7d26f61e 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -528,7 +528,7 @@ public enum Material { * @return Material if found, or null */ public static Material getMaterial(final int id) { - if (byId.length > id) { + if (byId.length > id && id >= 0) { return byId[id]; } else { return null; diff --git a/src/test/java/org/bukkit/MaterialTest.java b/src/test/java/org/bukkit/MaterialTest.java index c1051caf..e74e2f28 100644 --- a/src/test/java/org/bukkit/MaterialTest.java +++ b/src/test/java/org/bukkit/MaterialTest.java @@ -33,6 +33,7 @@ public class MaterialTest { @Test public void getByOutOfRangeId() { assertThat(Material.getMaterial(Integer.MAX_VALUE), is(nullValue())); + assertThat(Material.getMaterial(Integer.MIN_VALUE), is(nullValue())); } @Test |