ソースを参照

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: https://jmonkeyengine.googlecode.com/svn/trunk@7180 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

PSp..om 14 年 前
コミット
041f47157d

+ 5 - 2
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<Short, SerializerRegistration> idRegistrations         = new HashMap<Short, SerializerRegistration>();
     private static final Map<Class, SerializerRegistration> classRegistrations      = new HashMap<Class, SerializerRegistration>();
 
@@ -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());
     }