changeset 12404:098db82c3351

8076405: Improve serial serialization Reviewed-by: alanb, igerasim
author chegar
date Fri, 17 Apr 2015 15:36:32 +0100
parents 6f728e38a695
children 5d084680f135
files src/java.base/share/classes/java/io/ObjectInputStream.java src/java.base/share/classes/java/io/SerialCallbackContext.java
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/io/ObjectInputStream.java	Fri Apr 17 15:28:44 2015 +0100
+++ b/src/java.base/share/classes/java/io/ObjectInputStream.java	Fri Apr 17 15:36:32 2015 +0100
@@ -1832,6 +1832,8 @@
         throws IOException
     {
         SerialCallbackContext oldContext = curContext;
+        if (oldContext != null)
+            oldContext.check();
         curContext = null;
         try {
             boolean blocked = desc.hasBlockExternalData();
@@ -1856,6 +1858,8 @@
                 skipCustomData();
             }
         } finally {
+            if (oldContext != null)
+                oldContext.check();
             curContext = oldContext;
         }
         /*
@@ -1910,7 +1914,8 @@
                     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 @@
                         handles.markException(passHandle, ex);
                     } finally {
                         curContext.setUsed();
+                        if (oldContext!= null)
+                            oldContext.check();
                         curContext = oldContext;
                     }
 
--- a/src/java.base/share/classes/java/io/SerialCallbackContext.java	Fri Apr 17 15:28:44 2015 +0100
+++ b/src/java.base/share/classes/java/io/SerialCallbackContext.java	Fri Apr 17 15:36:32 2015 +0100
@@ -60,6 +60,13 @@
         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(