changeset 7291:2628d8ec8d82

Add toString to SerializedLambda; add debugging logic for deserialization failures
author briangoetz
date Thu, 07 Feb 2013 09:46:22 -0500
parents 83d2ed4895b1
children 1432662bd29c
files src/share/classes/java/lang/invoke/MethodHandleInfo.java src/share/classes/java/lang/invoke/SerializedLambda.java
diffstat 2 files changed, 26 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/invoke/MethodHandleInfo.java	Thu Feb 07 09:36:41 2013 -0500
+++ b/src/share/classes/java/lang/invoke/MethodHandleInfo.java	Thu Feb 07 09:46:22 2013 -0500
@@ -76,7 +76,7 @@
        return referenceKind;
    }
     
-    private String getReferenceKindString() {
+   public static String getReferenceKindString(int referenceKind) {
         switch (referenceKind) {
             case REF_NONE: return "REF_NONE";
             case REF_getField: return "getfield";
@@ -88,12 +88,13 @@
             case REF_invokeSpecial: return "invokespecial";
             case REF_newInvokeSpecial: return "newinvokespecial";
             case REF_invokeInterface: return "invokeinterface";
-            default: return "UNKNOWN_REFENCE_KIND";
+            default: return "UNKNOWN_REFENCE_KIND" + "[" + referenceKind + "]";
         }
     }
 
     @Override
     public String toString() {
-        return String.format("%s %s.%s:%s", getReferenceKindString(), declaringClass.getName(), name, methodType);
+        return String.format("%s %s.%s:%s", getReferenceKindString(referenceKind),
+                             declaringClass.getName(), name, methodType);
     }
 }
--- a/src/share/classes/java/lang/invoke/SerializedLambda.java	Thu Feb 07 09:36:41 2013 -0500
+++ b/src/share/classes/java/lang/invoke/SerializedLambda.java	Thu Feb 07 09:46:22 2013 -0500
@@ -25,6 +25,7 @@
 package java.lang.invoke;
 
 import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
@@ -216,7 +217,16 @@
                 }
             });
 
-            return deserialize.invoke(null, this);
+            // @@@ For debugging -- remove try-catch below before committing
+            try {
+                return deserialize.invoke(null, this);
+            }
+            catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+                System.out.println(toString());
+                e.printStackTrace(System.out);
+                throw e;
+            }
+            // @@@ For debugging -- remove try-catch above before committing
         }
         catch (PrivilegedActionException e) {
             Exception cause = e.getException();
@@ -229,7 +239,17 @@
         }
     }
 
-/*
+    @Override
+    public String toString() {
+        return String.format("SerializedLambda[capturingClass=%s, functionalInterfaceMethod=%s %s.%s:%s, " +
+                             "implementation=%s %s.%s:%s, instantiatedMethodType=%s, numCaptured=%d]",
+                             capturingClass, MethodHandleInfo.getReferenceKindString(functionalInterfaceMethodKind),
+                             functionalInterfaceClass, functionalInterfaceMethodName, functionalInterfaceMethodSignature,
+                             MethodHandleInfo.getReferenceKindString(implMethodKind), implClass, implMethodName,
+                             implMethodSignature, instantiatedMethodType, capturedArgs.length);
+    }
+
+    /*
     // @@@ Review question: is it worthwhile implementing a versioned serialization protocol?
 
     private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {