diff --git a/jdk/src/java.base/share/classes/java/io/ObjectInputStream.java b/jdk/src/java.base/share/classes/java/io/ObjectInputStream.java index b6891d572ee..389a70be1d3 100644 --- a/jdk/src/java.base/share/classes/java/io/ObjectInputStream.java +++ b/jdk/src/java.base/share/classes/java/io/ObjectInputStream.java @@ -1832,6 +1832,8 @@ public class ObjectInputStream throws IOException { SerialCallbackContext oldContext = curContext; + if (oldContext != null) + oldContext.check(); curContext = null; try { boolean blocked = desc.hasBlockExternalData(); @@ -1856,6 +1858,8 @@ public class ObjectInputStream skipCustomData(); } } finally { + if (oldContext != null) + oldContext.check(); curContext = oldContext; } /* @@ -1910,7 +1914,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); @@ -1927,6 +1932,8 @@ public class ObjectInputStream handles.markException(passHandle, ex); } finally { curContext.setUsed(); + if (oldContext!= null) + oldContext.check(); curContext = oldContext; } diff --git a/jdk/src/java.base/share/classes/java/io/SerialCallbackContext.java b/jdk/src/java.base/share/classes/java/io/SerialCallbackContext.java index 15c36b02dee..b901397cce3 100644 --- a/jdk/src/java.base/share/classes/java/io/SerialCallbackContext.java +++ b/jdk/src/java.base/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()); + } + } + public void checkAndSetUsed() throws NotActiveException { if (thread != Thread.currentThread()) { throw new NotActiveException(