src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java

changeset 1639
fbbf5376e7e4
parent 1624
d0ae21e3a382
child 1652
cc38a6723663
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Mar 14 10:33:31 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Mar 14 22:54:17 2013 -0700
     1.3 @@ -1293,9 +1293,16 @@
     1.4              return names.lambda.append(names.fromString("" + lambdaCount++));
     1.5          }
     1.6  
     1.7 +        /**
     1.8 +         * For a serializable lambda, generate a name which maximizes name
     1.9 +         * stability across deserialization.
    1.10 +         * @param owner
    1.11 +         * @return Name to use for the synthetic lambda method name
    1.12 +         */
    1.13          private Name serializedLambdaName(Symbol owner) {
    1.14              StringBuilder buf = new StringBuilder();
    1.15              buf.append(names.lambda);
    1.16 +            // Append the name of the method enclosing the lambda.
    1.17              String methodName = owner.name.toString();
    1.18              if (methodName.equals("<clinit>"))
    1.19                  methodName = "static";
    1.20 @@ -1303,9 +1310,18 @@
    1.21                  methodName = "new";
    1.22              buf.append(methodName);
    1.23              buf.append('$');
    1.24 -            int methTypeHash = methodSig(owner.type).hashCode();
    1.25 -            buf.append(Integer.toHexString(methTypeHash));
    1.26 +            // Append a hash of the enclosing method signature to differentiate
    1.27 +            // overloaded enclosing methods.  For lambdas enclosed in lambdas,
    1.28 +            // the generated lambda method will not have type yet, but the
    1.29 +            // enclosing method's name will have been generated with this same
    1.30 +            // method, so it will be unique and never be overloaded.
    1.31 +            if (owner.type != null) {
    1.32 +                int methTypeHash = methodSig(owner.type).hashCode();
    1.33 +                buf.append(Integer.toHexString(methTypeHash));
    1.34 +            }
    1.35              buf.append('$');
    1.36 +            // The above appended name components may not be unique, append a
    1.37 +            // count based on the above name components.
    1.38              String temp = buf.toString();
    1.39              Integer count = serializableLambdaCounts.get(temp);
    1.40              if (count == null) {

mercurial