src/share/classes/java/io/ObjectOutputStream.java
Print this page
@@ -33,11 +33,10 @@
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import static java.io.ObjectStreamClass.processQueue;
-import java.io.SerialCallbackContext;
import sun.reflect.misc.ReflectUtil;
/**
* An ObjectOutputStream writes primitive data types and graphs of Java objects
* to an OutputStream. The objects can be read (reconstituted) using an
@@ -456,11 +455,11 @@
if (curPut == null) {
SerialCallbackContext ctx = curContext;
if (ctx == null) {
throw new NotActiveException("not in call to writeObject");
}
- Object curObj = ctx.getObj();
+ ctx.checkAndSetUsed();
ObjectStreamClass curDesc = ctx.getDesc();
curPut = new PutFieldImpl(curDesc);
}
return curPut;
}
@@ -1525,18 +1524,22 @@
}
desc.checkDefaultSerialize();
int primDataSize = desc.getPrimDataSize();
+ if (primDataSize > 0) {
if (primVals == null || primVals.length < primDataSize) {
primVals = new byte[primDataSize];
}
desc.getPrimFieldValues(obj, primVals);
bout.write(primVals, 0, primDataSize, false);
+ }
+ int numObjFields = desc.getNumObjFields();
+ if (numObjFields > 0) {
ObjectStreamField[] fields = desc.getFields(false);
- Object[] objVals = new Object[desc.getNumObjFields()];
+ Object[] objVals = new Object[numObjFields];
int numPrimFields = fields.length - objVals.length;
desc.getObjFieldValues(obj, objVals);
for (int i = 0; i < objVals.length; i++) {
if (extendedDebugInfo) {
debugInfoStack.push(
@@ -1552,10 +1555,11 @@
debugInfoStack.pop();
}
}
}
}
+ }
/**
* Attempts to write to stream fatal IOException that has caused
* serialization to abort.
*/
@@ -2462,11 +2466,13 @@
*/
public String toString() {
StringBuilder buffer = new StringBuilder();
if (!stack.isEmpty()) {
for(int i = stack.size(); i > 0; i-- ) {
- buffer.append(stack.get(i-1) + ((i != 1) ? "\n" : ""));
+ buffer.append(stack.get(i - 1));
+ if (i != 1)
+ buffer.append('\n');
}
}
return buffer.toString();
}
}