From cf2b92c24d4a9634a326c713cd2a2d95573a268c Mon Sep 17 00:00:00 2001 From: "PSpeed42@gmail.com" Date: Mon, 4 Apr 2011 01:01:17 +0000 Subject: [PATCH] Modified serializer to throw an exception if it tries to read from a buffer and doesn't understand what class it's reading. Error messages... it's the little things that matter. git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7180 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/networking/com/jme3/network/serializing/Serializer.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/engine/src/networking/com/jme3/network/serializing/Serializer.java b/engine/src/networking/com/jme3/network/serializing/Serializer.java index 02b91ab38..edac3ed25 100644 --- a/engine/src/networking/com/jme3/network/serializing/Serializer.java +++ b/engine/src/networking/com/jme3/network/serializing/Serializer.java @@ -57,6 +57,8 @@ import java.util.logging.Logger; public abstract class Serializer { protected static final Logger log = Logger.getLogger(Serializer.class.getName()); + private static final SerializerRegistration NULL_CLASS = new SerializerRegistration( null, Void.class, (short)-1 ); + private static final Map idRegistrations = new HashMap(); private static final Map classRegistrations = new HashMap(); @@ -267,7 +269,7 @@ public abstract class Serializer { */ public static SerializerRegistration readClass(ByteBuffer buffer) { short classID = buffer.getShort(); - if (classID == -1) return null; + if (classID == -1) return NULL_CLASS; return idRegistrations.get(classID); } @@ -280,7 +282,8 @@ public abstract class Serializer { */ public static Object readClassAndObject(ByteBuffer buffer) throws IOException { SerializerRegistration reg = readClass(buffer); - if (reg == null) return null; + if (reg == NULL_CLASS) return null; + if (reg == null) throw new SerializerException( "Class not found for buffer data." ); return reg.getSerializer().readObject(buffer, reg.getType()); } -- 2.11.0