Wed, 15 May 2013 06:53:01 -0700
8010006: NPE in javac with interface super in lambda
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Wed May 15 14:03:09 2013 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Wed May 15 06:53:01 2013 -0700 1.3 @@ -28,7 +28,6 @@ 1.4 import com.sun.tools.javac.tree.JCTree.*; 1.5 import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind; 1.6 import com.sun.tools.javac.tree.TreeMaker; 1.7 -import com.sun.tools.javac.tree.TreeScanner; 1.8 import com.sun.tools.javac.tree.TreeTranslator; 1.9 import com.sun.tools.javac.code.Attribute; 1.10 import com.sun.tools.javac.code.Kinds; 1.11 @@ -165,7 +164,7 @@ 1.12 return translate(tree, newContext != null ? newContext : context); 1.13 } 1.14 1.15 - public <T extends JCTree> T translate(T tree, TranslationContext<?> newContext) { 1.16 + <T extends JCTree> T translate(T tree, TranslationContext<?> newContext) { 1.17 TranslationContext<?> prevContext = context; 1.18 try { 1.19 context = newContext; 1.20 @@ -176,7 +175,7 @@ 1.21 } 1.22 } 1.23 1.24 - public <T extends JCTree> List<T> translate(List<T> trees, TranslationContext<?> newContext) { 1.25 + <T extends JCTree> List<T> translate(List<T> trees, TranslationContext<?> newContext) { 1.26 ListBuffer<T> buf = ListBuffer.lb(); 1.27 for (T tree : trees) { 1.28 buf.append(translate(tree, newContext)); 1.29 @@ -1303,7 +1302,11 @@ 1.30 1.31 @Override 1.32 public void visitSelect(JCFieldAccess tree) { 1.33 - if (context() != null && lambdaSelectSymbolFilter(tree.sym)) { 1.34 + if (context() != null && tree.sym.kind == VAR && 1.35 + (tree.sym.name == names._this || 1.36 + tree.sym.name == names._super)) { 1.37 + // A select of this or super means, if we are in a lambda, 1.38 + // we much have an instance context 1.39 TranslationContext<?> localContext = context(); 1.40 while (localContext != null) { 1.41 if (localContext.tree.hasTag(LAMBDA)) { 1.42 @@ -1554,13 +1557,6 @@ 1.43 && sym.name != names.init; 1.44 } 1.45 1.46 - private boolean lambdaSelectSymbolFilter(Symbol sym) { 1.47 - return (sym.kind == VAR || sym.kind == MTH) && 1.48 - !sym.isStatic() && 1.49 - (sym.name == names._this || 1.50 - sym.name == names._super); 1.51 - } 1.52 - 1.53 /** 1.54 * This is used to filter out those new class expressions that need to 1.55 * be qualified with an enclosing tree
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/lambda/LambdaWithInterfaceSuper.java Wed May 15 06:53:01 2013 -0700 2.3 @@ -0,0 +1,43 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8010006 2.30 + * @summary NPE in javac with interface super in lambda 2.31 + * @compile LambdaWithInterfaceSuper.java 2.32 + */ 2.33 + 2.34 +class LambdaWithInterfaceSuper { 2.35 + 2.36 + interface Sup { 2.37 + default void m() {} 2.38 + } 2.39 + 2.40 + interface I extends Sup { 2.41 + default void m() { 2.42 + Runnable r = ()-> { Sup.super.m(); }; 2.43 + r.run(); 2.44 + } 2.45 + } 2.46 +}