提交 38a3cf16 编写于 作者: I igerasim

8076405: Improve serial serialization

Reviewed-by: alanb, chegar
上级 cf29b742
...@@ -1829,6 +1829,8 @@ public class ObjectInputStream ...@@ -1829,6 +1829,8 @@ public class ObjectInputStream
throws IOException throws IOException
{ {
SerialCallbackContext oldContext = curContext; SerialCallbackContext oldContext = curContext;
if (oldContext != null)
oldContext.check();
curContext = null; curContext = null;
try { try {
boolean blocked = desc.hasBlockExternalData(); boolean blocked = desc.hasBlockExternalData();
...@@ -1853,6 +1855,8 @@ public class ObjectInputStream ...@@ -1853,6 +1855,8 @@ public class ObjectInputStream
skipCustomData(); skipCustomData();
} }
} finally { } finally {
if (oldContext != null)
oldContext.check();
curContext = oldContext; curContext = oldContext;
} }
/* /*
...@@ -1887,7 +1891,8 @@ public class ObjectInputStream ...@@ -1887,7 +1891,8 @@ public class ObjectInputStream
defaultReadFields(null, slotDesc); // skip field values defaultReadFields(null, slotDesc); // skip field values
} else if (slotDesc.hasReadObjectMethod()) { } else if (slotDesc.hasReadObjectMethod()) {
SerialCallbackContext oldContext = curContext; SerialCallbackContext oldContext = curContext;
if (oldContext != null)
oldContext.check();
try { try {
curContext = new SerialCallbackContext(obj, slotDesc); curContext = new SerialCallbackContext(obj, slotDesc);
...@@ -1904,6 +1909,8 @@ public class ObjectInputStream ...@@ -1904,6 +1909,8 @@ public class ObjectInputStream
handles.markException(passHandle, ex); handles.markException(passHandle, ex);
} finally { } finally {
curContext.setUsed(); curContext.setUsed();
if (oldContext!= null)
oldContext.check();
curContext = oldContext; curContext = oldContext;
} }
......
...@@ -60,6 +60,13 @@ final class SerialCallbackContext { ...@@ -60,6 +60,13 @@ final class SerialCallbackContext {
return desc; 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 { private void checkAndSetUsed() throws NotActiveException {
if (thread != Thread.currentThread()) { if (thread != Thread.currentThread()) {
throw new NotActiveException( throw new NotActiveException(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册