8207816: Align declaration of SerializedLambda.readResolve with serialization conventions
authordarcy
Thu, 19 Jul 2018 09:20:08 -0700
changeset 51118 2467bd84c59b
parent 51117 c96c7d08ae49
child 51119 02266d771ec5
8207816: Align declaration of SerializedLambda.readResolve with serialization conventions Reviewed-by: briangoetz
src/java.base/share/classes/java/lang/invoke/SerializedLambda.java
--- a/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java	Thu Jul 19 16:22:19 2018 +0800
+++ b/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java	Thu Jul 19 09:20:08 2018 -0700
@@ -25,6 +25,8 @@
 package java.lang.invoke;
 
 import java.io.Serializable;
+import java.io.InvalidObjectException;
+import java.io.ObjectStreamException;
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
@@ -223,7 +225,7 @@
         return capturedArgs[i];
     }
 
-    private Object readResolve() throws ReflectiveOperationException {
+    private Object readResolve() throws ObjectStreamException {
         try {
             Method deserialize = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
                 @Override
@@ -235,12 +237,13 @@
             });
 
             return deserialize.invoke(null, this);
-        }
-        catch (PrivilegedActionException e) {
+        } catch (ReflectiveOperationException roe) {
+            ObjectStreamException ose = new InvalidObjectException("ReflectiveOperationException during deserialization");
+            ose.initCause(roe);
+            throw ose;
+        } catch (PrivilegedActionException e) {
             Exception cause = e.getException();
-            if (cause instanceof ReflectiveOperationException)
-                throw (ReflectiveOperationException) cause;
-            else if (cause instanceof RuntimeException)
+            if (cause instanceof RuntimeException)
                 throw (RuntimeException) cause;
             else
                 throw new RuntimeException("Exception in SerializedLambda.readResolve", e);