summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorh31ix <zero_gravity@outlook.com>2013-03-29 22:43:05 -0400
committerTravis Watkins <amaranth@ubuntu.com>2013-04-02 16:10:04 -0500
commit743d0fb603356ee9473784576b571b30637a4baa (patch)
tree0151f0326c8c0f6d6d8c067a242e2bb36a29cd11 /src
parentc33908509a6fdfb12b061d146dce36eaeabfd83c (diff)
downloadcraftbukkit-743d0fb603356ee9473784576b571b30637a4baa.tar
craftbukkit-743d0fb603356ee9473784576b571b30637a4baa.tar.gz
craftbukkit-743d0fb603356ee9473784576b571b30637a4baa.tar.lz
craftbukkit-743d0fb603356ee9473784576b571b30637a4baa.tar.xz
craftbukkit-743d0fb603356ee9473784576b571b30637a4baa.zip
Properly return contents of Inventory. Fixes BUKKIT-3930
When an array of an inventory's contents is requested, we loop through the contents of the NMS inventory's ItemStacks in order to return Bukkit ItemStacks that can be used through the API. However, the NMS ItemStack can, in some cases, be larger than the physical size of the inventory. Using the size of the NMS array as a limit on the loop that follows can result in an ArrayIndexOutOfBoundsException because the Bukkit array's length is the actual size of the inventory, and thus will be smaller. With this commit we use the smaller of the two arrays' length as the limit in the loop, thus eliminating the possibility that the smaller array will be asked for an index higher than its length.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
index 31a29072..577e2101 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
@@ -54,7 +54,8 @@ public class CraftInventory implements Inventory {
ItemStack[] items = new ItemStack[getSize()];
net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();
- for (int i = 0; i < mcItems.length; i++) {
+ int size = Math.min(items.length, mcItems.length);
+ for (int i = 0; i < size; i++) {
items[i] = mcItems[i] == null ? null : CraftItemStack.asCraftMirror(mcItems[i]);
}