From 2abce32b4b0b9ab1ed70962d0d7f32b22a5e8070 Mon Sep 17 00:00:00 2001 From: smarks Date: Thu, 11 Jul 2013 13:32:36 -0700 Subject: [PATCH] 8014987: Augment serialization handling Reviewed-by: alanb, coffeys, skoivu --- .../classes/java/io/ObjectInputStream.java | 15 +++++++------- .../classes/java/io/ObjectOutputStream.java | 20 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/share/classes/java/io/ObjectInputStream.java b/src/share/classes/java/io/ObjectInputStream.java index ca0400539..0e41b08dc 100644 --- a/src/share/classes/java/io/ObjectInputStream.java +++ b/src/share/classes/java/io/ObjectInputStream.java @@ -490,11 +490,12 @@ public class ObjectInputStream public void defaultReadObject() throws IOException, ClassNotFoundException { - if (curContext == null) { + SerialCallbackContext ctx = curContext; + if (ctx == null) { throw new NotActiveException("not in call to readObject"); } - Object curObj = curContext.getObj(); - ObjectStreamClass curDesc = curContext.getDesc(); + Object curObj = ctx.getObj(); + ObjectStreamClass curDesc = ctx.getDesc(); bin.setBlockDataMode(false); defaultReadFields(curObj, curDesc); bin.setBlockDataMode(true); @@ -528,11 +529,12 @@ public class ObjectInputStream public ObjectInputStream.GetField readFields() throws IOException, ClassNotFoundException { - if (curContext == null) { + SerialCallbackContext ctx = curContext; + if (ctx == null) { throw new NotActiveException("not in call to readObject"); } - Object curObj = curContext.getObj(); - ObjectStreamClass curDesc = curContext.getDesc(); + Object curObj = ctx.getObj(); + ObjectStreamClass curDesc = ctx.getDesc(); bin.setBlockDataMode(false); GetFieldImpl getField = new GetFieldImpl(curDesc); getField.readFields(); @@ -1967,7 +1969,6 @@ public class ObjectInputStream private void defaultReadFields(Object obj, ObjectStreamClass desc) throws IOException { - // REMIND: is isInstance check necessary? Class cl = desc.forClass(); if (cl != null && obj != null && !cl.isInstance(obj)) { throw new ClassCastException(); diff --git a/src/share/classes/java/io/ObjectOutputStream.java b/src/share/classes/java/io/ObjectOutputStream.java index f7a94bb03..c99aeb9cd 100644 --- a/src/share/classes/java/io/ObjectOutputStream.java +++ b/src/share/classes/java/io/ObjectOutputStream.java @@ -430,11 +430,12 @@ public class ObjectOutputStream * OutputStream */ public void defaultWriteObject() throws IOException { - if ( curContext == null ) { + SerialCallbackContext ctx = curContext; + if (ctx == null) { throw new NotActiveException("not in call to writeObject"); } - Object curObj = curContext.getObj(); - ObjectStreamClass curDesc = curContext.getDesc(); + Object curObj = ctx.getObj(); + ObjectStreamClass curDesc = ctx.getDesc(); bout.setBlockDataMode(false); defaultWriteFields(curObj, curDesc); bout.setBlockDataMode(true); @@ -452,11 +453,12 @@ public class ObjectOutputStream */ public ObjectOutputStream.PutField putFields() throws IOException { if (curPut == null) { - if (curContext == null) { + SerialCallbackContext ctx = curContext; + if (ctx == null) { throw new NotActiveException("not in call to writeObject"); } - Object curObj = curContext.getObj(); - ObjectStreamClass curDesc = curContext.getDesc(); + Object curObj = ctx.getObj(); + ObjectStreamClass curDesc = ctx.getDesc(); curPut = new PutFieldImpl(curDesc); } return curPut; @@ -1516,7 +1518,11 @@ public class ObjectOutputStream private void defaultWriteFields(Object obj, ObjectStreamClass desc) 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(); int primDataSize = desc.getPrimDataSize(); -- GitLab