8207816: Align declaration of SerializedLambda.readResolve with serialization conventions

Reviewed-by: briangoetz
This commit is contained in:
Joe Darcy 2018-07-19 09:20:08 -07:00
parent 069fa394d0
commit 269286da50

View File

@ -25,6 +25,8 @@
package java.lang.invoke; package java.lang.invoke;
import java.io.Serializable; import java.io.Serializable;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
@ -223,7 +225,7 @@ public final class SerializedLambda implements Serializable {
return capturedArgs[i]; return capturedArgs[i];
} }
private Object readResolve() throws ReflectiveOperationException { private Object readResolve() throws ObjectStreamException {
try { try {
Method deserialize = AccessController.doPrivileged(new PrivilegedExceptionAction<>() { Method deserialize = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
@Override @Override
@ -235,12 +237,13 @@ public final class SerializedLambda implements Serializable {
}); });
return deserialize.invoke(null, this); return deserialize.invoke(null, this);
} } catch (ReflectiveOperationException roe) {
catch (PrivilegedActionException e) { ObjectStreamException ose = new InvalidObjectException("ReflectiveOperationException during deserialization");
ose.initCause(roe);
throw ose;
} catch (PrivilegedActionException e) {
Exception cause = e.getException(); Exception cause = e.getException();
if (cause instanceof ReflectiveOperationException) if (cause instanceof RuntimeException)
throw (ReflectiveOperationException) cause;
else if (cause instanceof RuntimeException)
throw (RuntimeException) cause; throw (RuntimeException) cause;
else else
throw new RuntimeException("Exception in SerializedLambda.readResolve", e); throw new RuntimeException("Exception in SerializedLambda.readResolve", e);