提交 2abce32b 编写于 作者: S smarks

8014987: Augment serialization handling

Reviewed-by: alanb, coffeys, skoivu
上级 678b1eff
...@@ -490,11 +490,12 @@ public class ObjectInputStream ...@@ -490,11 +490,12 @@ public class ObjectInputStream
public void defaultReadObject() public void defaultReadObject()
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException
{ {
if (curContext == null) { SerialCallbackContext ctx = curContext;
if (ctx == null) {
throw new NotActiveException("not in call to readObject"); throw new NotActiveException("not in call to readObject");
} }
Object curObj = curContext.getObj(); Object curObj = ctx.getObj();
ObjectStreamClass curDesc = curContext.getDesc(); ObjectStreamClass curDesc = ctx.getDesc();
bin.setBlockDataMode(false); bin.setBlockDataMode(false);
defaultReadFields(curObj, curDesc); defaultReadFields(curObj, curDesc);
bin.setBlockDataMode(true); bin.setBlockDataMode(true);
...@@ -528,11 +529,12 @@ public class ObjectInputStream ...@@ -528,11 +529,12 @@ public class ObjectInputStream
public ObjectInputStream.GetField readFields() public ObjectInputStream.GetField readFields()
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException
{ {
if (curContext == null) { SerialCallbackContext ctx = curContext;
if (ctx == null) {
throw new NotActiveException("not in call to readObject"); throw new NotActiveException("not in call to readObject");
} }
Object curObj = curContext.getObj(); Object curObj = ctx.getObj();
ObjectStreamClass curDesc = curContext.getDesc(); ObjectStreamClass curDesc = ctx.getDesc();
bin.setBlockDataMode(false); bin.setBlockDataMode(false);
GetFieldImpl getField = new GetFieldImpl(curDesc); GetFieldImpl getField = new GetFieldImpl(curDesc);
getField.readFields(); getField.readFields();
...@@ -1967,7 +1969,6 @@ public class ObjectInputStream ...@@ -1967,7 +1969,6 @@ public class ObjectInputStream
private void defaultReadFields(Object obj, ObjectStreamClass desc) private void defaultReadFields(Object obj, ObjectStreamClass desc)
throws IOException throws IOException
{ {
// REMIND: is isInstance check necessary?
Class<?> cl = desc.forClass(); Class<?> cl = desc.forClass();
if (cl != null && obj != null && !cl.isInstance(obj)) { if (cl != null && obj != null && !cl.isInstance(obj)) {
throw new ClassCastException(); throw new ClassCastException();
......
...@@ -430,11 +430,12 @@ public class ObjectOutputStream ...@@ -430,11 +430,12 @@ public class ObjectOutputStream
* <code>OutputStream</code> * <code>OutputStream</code>
*/ */
public void defaultWriteObject() throws IOException { public void defaultWriteObject() throws IOException {
if ( curContext == null ) { SerialCallbackContext ctx = curContext;
if (ctx == null) {
throw new NotActiveException("not in call to writeObject"); throw new NotActiveException("not in call to writeObject");
} }
Object curObj = curContext.getObj(); Object curObj = ctx.getObj();
ObjectStreamClass curDesc = curContext.getDesc(); ObjectStreamClass curDesc = ctx.getDesc();
bout.setBlockDataMode(false); bout.setBlockDataMode(false);
defaultWriteFields(curObj, curDesc); defaultWriteFields(curObj, curDesc);
bout.setBlockDataMode(true); bout.setBlockDataMode(true);
...@@ -452,11 +453,12 @@ public class ObjectOutputStream ...@@ -452,11 +453,12 @@ public class ObjectOutputStream
*/ */
public ObjectOutputStream.PutField putFields() throws IOException { public ObjectOutputStream.PutField putFields() throws IOException {
if (curPut == null) { if (curPut == null) {
if (curContext == null) { SerialCallbackContext ctx = curContext;
if (ctx == null) {
throw new NotActiveException("not in call to writeObject"); throw new NotActiveException("not in call to writeObject");
} }
Object curObj = curContext.getObj(); Object curObj = ctx.getObj();
ObjectStreamClass curDesc = curContext.getDesc(); ObjectStreamClass curDesc = ctx.getDesc();
curPut = new PutFieldImpl(curDesc); curPut = new PutFieldImpl(curDesc);
} }
return curPut; return curPut;
...@@ -1516,7 +1518,11 @@ public class ObjectOutputStream ...@@ -1516,7 +1518,11 @@ public class ObjectOutputStream
private void defaultWriteFields(Object obj, ObjectStreamClass desc) private void defaultWriteFields(Object obj, ObjectStreamClass desc)
throws IOException throws IOException
{ {
// REMIND: perform conservative isInstance check here? Class<?> cl = desc.forClass();
if (cl != null && obj != null && !cl.isInstance(obj)) {
throw new ClassCastException();
}
desc.checkDefaultSerialize(); desc.checkDefaultSerialize();
int primDataSize = desc.getPrimDataSize(); int primDataSize = desc.getPrimDataSize();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册