src/share/classes/java/io/ObjectInputStream.java

Print this page

        

@@ -37,11 +37,10 @@
 import java.security.PrivilegedExceptionAction;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicBoolean;
 import static java.io.ObjectStreamClass.processQueue;
 import sun.reflect.misc.ReflectUtil;
 
 /**
  * An ObjectInputStream deserializes primitive data and objects previously

@@ -532,11 +531,11 @@
     {
         SerialCallbackContext ctx = curContext;
         if (ctx == null) {
             throw new NotActiveException("not in call to readObject");
         }
-        Object curObj = ctx.getObj();
+        ctx.checkAndSetUsed();
         ObjectStreamClass curDesc = ctx.getDesc();
         bin.setBlockDataMode(false);
         GetFieldImpl getField = new GetFieldImpl(curDesc);
         getField.readFields();
         bin.setBlockDataMode(true);

@@ -1595,11 +1594,11 @@
 
         ObjectStreamClass desc = new ObjectStreamClass();
         int descHandle = handles.assign(unshared ? unsharedMarker : desc);
         passHandle = NULL_HANDLE;
 
-        ObjectStreamClass readDesc = null;
+        ObjectStreamClass readDesc;
         try {
             readDesc = readClassDescriptor();
         } catch (ClassNotFoundException ex) {
             throw (IOException) new InvalidClassException(
                 "failed to read class descriptor").initCause(ex);

@@ -1974,21 +1973,25 @@
         if (cl != null && obj != null && !cl.isInstance(obj)) {
             throw new ClassCastException();
         }
 
         int primDataSize = desc.getPrimDataSize();
+        if (primDataSize > 0) {
         if (primVals == null || primVals.length < primDataSize) {
             primVals = new byte[primDataSize];
         }
         bin.readFully(primVals, 0, primDataSize, false);
         if (obj != null) {
             desc.setPrimFieldValues(obj, primVals);
         }
+        }
 
+        int numObjFields = desc.getNumObjFields();
+        if (numObjFields > 0) {
         int objHandle = passHandle;
         ObjectStreamField[] fields = desc.getFields(false);
-        Object[] objVals = new Object[desc.getNumObjFields()];
+            Object[] objVals = new Object[numObjFields];
         int numPrimFields = fields.length - objVals.length;
         for (int i = 0; i < objVals.length; i++) {
             ObjectStreamField f = fields[numPrimFields + i];
             objVals[i] = readObject0(f.isUnshared());
             if (f.getField() != null) {

@@ -1998,10 +2001,11 @@
         if (obj != null) {
             desc.setObjFieldValues(obj, objVals);
         }
         passHandle = objHandle;
     }
+    }
 
     /**
      * Reads in and returns IOException that caused serialization to abort.
      * All stream state is discarded prior to reading in fatal exception.  Sets
      * passHandle to fatal exception's handle.