From 8295b951d9dc261d69407f9e881e648a5851a8fc Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Thu, 29 Aug 2013 23:57:20 +0200 Subject: [PATCH] Don't throw an exception the first time we initialize IntHashMap. --- .../protocol/wrappers/WrappedIntHashMap.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedIntHashMap.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedIntHashMap.java index 50f39424..65231245 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedIntHashMap.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/WrappedIntHashMap.java @@ -98,9 +98,25 @@ public class WrappedIntHashMap { * @return The object that was removed, or NULL if the key is not present. */ public Object remove(int key) { + initializeGetMethod(); + + if (REMOVE_METHOD == null) + return removeFallback(key); return invokeMethod(REMOVE_METHOD, key); } + /** + * Remove a entry in the IntHashMap using a fallback method. + * @param key - the key of the mapping to remove. + * @return The removed element. + */ + private Object removeFallback(int key) { + Object old = get(key); + + invokeMethod(PUT_METHOD, key, null); + return old; + } + /** * Invoke a particular method on the current handle * @param method - the current method. @@ -162,7 +178,9 @@ public class WrappedIntHashMap { // Suppress } } - throw new IllegalStateException("Unable to find appropriate GET_METHOD for IntHashMap."); + + if (GET_METHOD == null) + throw new IllegalStateException("Unable to find appropriate GET_METHOD for IntHashMap."); } }