Author: robert
Date: 2008-01-19 03:33:18 +0000 (Sat, 19 Jan 2008)
New Revision: 17163

Modified:
   trunk/freenet/src/freenet/support/Serializer.java
Log:
dis.read() could return -1


Modified: trunk/freenet/src/freenet/support/Serializer.java
===================================================================
--- trunk/freenet/src/freenet/support/Serializer.java   2008-01-19 00:13:49 UTC 
(rev 17162)
+++ trunk/freenet/src/freenet/support/Serializer.java   2008-01-19 03:33:18 UTC 
(rev 17163)
@@ -54,9 +54,17 @@

        public static Object readFromDataInputStream(Class type, 
DataInputStream dis) throws IOException {
                if (type.equals(Boolean.class)) {
-                       return Boolean.valueOf(dis.read() == 1);
+                       int bool=dis.read();
+                       if (bool==1)
+                               return Boolean.TRUE;
+                       if (bool==0)
+                               return Boolean.FALSE;
+                       throw new IOException("Boolean is non boolean value: 
"+bool);
                } else if (type.equals(Byte.class)) {
-                       return new Byte((byte) dis.read());
+                       int b=dis.read();
+                       if (b<0)
+                               throw new IOException();
+                       return new Byte((byte)b);
                } else if (type.equals(Short.class)) {
                        return new Short(dis.readShort());
                } else if (type.equals(Integer.class)) {


Reply via email to