diff --git a/src/share/classes/java/io/ObjectInputStream.java b/src/share/classes/java/io/ObjectInputStream.java index e308d7d0071620795bebaba4ef76eed4405e7f86..61e76e3ca8cb4fa54517900a76a9a300cc69fc4e 100644 --- a/src/share/classes/java/io/ObjectInputStream.java +++ b/src/share/classes/java/io/ObjectInputStream.java @@ -1829,6 +1829,8 @@ public class ObjectInputStream throws IOException { SerialCallbackContext oldContext = curContext; + if (oldContext != null) + oldContext.check(); curContext = null; try { boolean blocked = desc.hasBlockExternalData(); @@ -1853,6 +1855,8 @@ public class ObjectInputStream skipCustomData(); } } finally { + if (oldContext != null) + oldContext.check(); curContext = oldContext; } /* @@ -1887,7 +1891,8 @@ public class ObjectInputStream defaultReadFields(null, slotDesc); // skip field values } else if (slotDesc.hasReadObjectMethod()) { SerialCallbackContext oldContext = curContext; - + if (oldContext != null) + oldContext.check(); try { curContext = new SerialCallbackContext(obj, slotDesc); @@ -1904,6 +1909,8 @@ public class ObjectInputStream handles.markException(passHandle, ex); } finally { curContext.setUsed(); + if (oldContext!= null) + oldContext.check(); curContext = oldContext; } diff --git a/src/share/classes/java/io/SerialCallbackContext.java b/src/share/classes/java/io/SerialCallbackContext.java index 748d38edb36325354408dbed82b236d9309bdf59..40090875aea06102f2904267692172f685e3d392 100644 --- a/src/share/classes/java/io/SerialCallbackContext.java +++ b/src/share/classes/java/io/SerialCallbackContext.java @@ -60,6 +60,13 @@ final class SerialCallbackContext { return desc; } + public void check() throws NotActiveException { + if (thread != null && thread != Thread.currentThread()) { + throw new NotActiveException( + "expected thread: " + thread + ", but got: " + Thread.currentThread()); + } + } + private void checkAndSetUsed() throws NotActiveException { if (thread != Thread.currentThread()) { throw new NotActiveException(