Make sure we enter and exit a Context in serialize()/deserialize().
Do not wrap return object in deserialize().
This commit is contained in:
parent
0dd4dba0f7
commit
892fe4b6e1
1 changed files with 22 additions and 13 deletions
|
@ -461,16 +461,21 @@ public class RhinoEngine implements ScriptingEngine {
|
||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
*/
|
*/
|
||||||
public void serialize(Object obj, OutputStream out) throws IOException {
|
public void serialize(Object obj, OutputStream out) throws IOException {
|
||||||
// use a special ScriptableOutputStream that unwraps Wrappers
|
Context.enter();
|
||||||
ScriptableOutputStream sout = new ScriptableOutputStream(out, core.global) {
|
try {
|
||||||
protected Object replaceObject(Object obj) throws IOException {
|
// use a special ScriptableOutputStream that unwraps Wrappers
|
||||||
if (obj instanceof Wrapper)
|
ScriptableOutputStream sout = new ScriptableOutputStream(out, core.global) {
|
||||||
obj = ((Wrapper) obj).unwrap();
|
protected Object replaceObject(Object obj) throws IOException {
|
||||||
return super.replaceObject(obj);
|
if (obj instanceof Wrapper)
|
||||||
}
|
obj = ((Wrapper) obj).unwrap();
|
||||||
};
|
return super.replaceObject(obj);
|
||||||
sout.writeObject(obj);
|
}
|
||||||
sout.flush();
|
};
|
||||||
|
sout.writeObject(obj);
|
||||||
|
sout.flush();
|
||||||
|
} finally {
|
||||||
|
Context.exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -483,9 +488,13 @@ public class RhinoEngine implements ScriptingEngine {
|
||||||
* @throws java.io.IOException
|
* @throws java.io.IOException
|
||||||
*/
|
*/
|
||||||
public Object deserialize(InputStream in) throws IOException, ClassNotFoundException {
|
public Object deserialize(InputStream in) throws IOException, ClassNotFoundException {
|
||||||
ObjectInputStream sin = new ScriptableInputStream(in, core.global);
|
Context.enter();
|
||||||
Object deserialized = sin.readObject();
|
try {
|
||||||
return Context.toObject(deserialized, core.global);
|
ObjectInputStream sin = new ScriptableInputStream(in, core.global);
|
||||||
|
return sin.readObject();
|
||||||
|
} finally {
|
||||||
|
Context.exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue