changeset 1905:85ba5a25c9e2

8010010: NPE generating serializedLambdaName for nested lambda Reviewed-by: mcimadamore
author rfield
date Wed, 20 Mar 2013 12:05:11 -0700
parents b80c4f8b1329
children b0d1bcd07069
files src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Mar 20 12:45:50 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Mar 20 12:05:11 2013 -0700
@@ -1299,9 +1299,16 @@
             return names.lambda.append(names.fromString("" + lambdaCount++));
         }
 
+        /**
+         * For a serializable lambda, generate a name which maximizes name
+         * stability across deserialization.
+         * @param owner
+         * @return Name to use for the synthetic lambda method name
+         */
         private Name serializedLambdaName(Symbol owner) {
             StringBuilder buf = new StringBuilder();
             buf.append(names.lambda);
+            // Append the name of the method enclosing the lambda.
             String methodName = owner.name.toString();
             if (methodName.equals("<clinit>"))
                 methodName = "static";
@@ -1309,11 +1316,19 @@
                 methodName = "new";
             buf.append(methodName);
             buf.append('$');
+            // Append a hash of the enclosing method signature to differentiate
+            // overloaded enclosing methods.  For lambdas enclosed in lambdas,
+            // the generated lambda method will not have type yet, but the
+            // enclosing method's name will have been generated with this same
+            // method, so it will be unique and never be overloaded.
             if (owner.type != null) {
+                assert(directlyEnclosingLambda() != null);
                 int methTypeHash = methodSig(owner.type).hashCode();
                 buf.append(Integer.toHexString(methTypeHash));
             }
             buf.append('$');
+            // The above appended name components may not be unique, append a
+            // count based on the above name components.
             String temp = buf.toString();
             Integer count = serializableLambdaCounts.get(temp);
             if (count == null) {