From aa3600a337db270692d77b21dbce0482eef90dd0 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Fri, 6 Dec 2013 23:07:56 +0100 Subject: [PATCH] Don't attempt to add NULL keys to a ConcurrentHashMap. Fixes #21 --- .../protocol/concurrency/PacketTypeSet.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/PacketTypeSet.java b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/PacketTypeSet.java index 0fa73e6c..3598c4ce 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/PacketTypeSet.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/concurrency/PacketTypeSet.java @@ -6,6 +6,7 @@ import java.util.Set; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.injector.packet.PacketRegistry; +import com.google.common.base.Preconditions; import net.minecraft.util.com.google.common.collect.Maps; @@ -32,8 +33,12 @@ public class PacketTypeSet { * @param type - the type to add. */ public synchronized void addType(PacketType type) { - types.add(type); - classes.add(getPacketClass(type)); + Class packetClass = getPacketClass(type); + types.add(Preconditions.checkNotNull(type, "type cannot be NULL.")); + + if (packetClass != null) { + classes.add(getPacketClass(type)); + } } /** @@ -41,8 +46,12 @@ public class PacketTypeSet { * @param type - the type to remove. */ public synchronized void removeType(PacketType type) { - types.remove(type); - classes.remove(getPacketClass(type)); + Class packetClass = getPacketClass(type); + types.remove(Preconditions.checkNotNull(type, "type cannot be NULL.")); + + if (packetClass != null) { + classes.remove(getPacketClass(type)); + } } /**