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
This commit is contained in:
parent
d1d082156f
commit
041f47157d
@ -57,6 +57,8 @@ import java.util.logging.Logger;
|
|||||||
public abstract class Serializer {
|
public abstract class Serializer {
|
||||||
protected static final Logger log = Logger.getLogger(Serializer.class.getName());
|
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<Short, SerializerRegistration> idRegistrations = new HashMap<Short, SerializerRegistration>();
|
||||||
private static final Map<Class, SerializerRegistration> classRegistrations = new HashMap<Class, 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) {
|
public static SerializerRegistration readClass(ByteBuffer buffer) {
|
||||||
short classID = buffer.getShort();
|
short classID = buffer.getShort();
|
||||||
if (classID == -1) return null;
|
if (classID == -1) return NULL_CLASS;
|
||||||
return idRegistrations.get(classID);
|
return idRegistrations.get(classID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +282,8 @@ public abstract class Serializer {
|
|||||||
*/
|
*/
|
||||||
public static Object readClassAndObject(ByteBuffer buffer) throws IOException {
|
public static Object readClassAndObject(ByteBuffer buffer) throws IOException {
|
||||||
SerializerRegistration reg = readClass(buffer);
|
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());
|
return reg.getSerializer().readObject(buffer, reg.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user