changeset 52755:ad90da891ae0 concise-method-declarations

NPE when a method reference qualifier is a method call
author vromero
date Tue, 02 Oct 2018 10:34:29 -0700
parents fbed49487ec4
children 36302405aa09 35841735961c
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java test/langtools/tools/javac/concise_methods/NPEQualifierIsCall.java
diffstat 2 files changed, 41 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Mon Oct 01 19:37:00 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Tue Oct 02 10:34:29 2018 -0700
@@ -2541,19 +2541,20 @@
                     JCMemberReference reference = (JCMemberReference)tree.conciseMethodRef;
                     switch (reference.kind) {
                         case STATIC:
-                            qualifier = make.Select(make.QualIdent(reference.expr.type.tsym), reference.name);
+                            qualifier = make.Select(access(make.QualIdent(reference.expr.type.tsym)), reference.name);
                             apply = make.at(tree.body.pos).Apply(List.nil(), qualifier, make.Idents(tree.params));
                             break;
                         case UNBOUND:
-                            qualifier = make.Select(make.QualIdent(tree.params.head.sym), reference.name);
+                            qualifier = make.Select(access(make.QualIdent(tree.params.head.sym)), reference.name);
                             apply = make.at(tree.body.pos).Apply(List.nil(), qualifier, List.nil());
                             break;
                         case BOUND: case SUPER:
-                            qualifier = make.Select(make.Ident(TreeInfo.symbol(reference.expr)), reference.name);
+                            qualifier = make.Select(access(reference.expr), reference.name);
                             apply = make.at(tree.body.pos).Apply(List.nil(), qualifier, make.Idents(tree.params));
                             break;
                         case TOPLEVEL: case IMPLICIT_INNER:
-                            expr = makeNewClass(reference.expr.type, make.Idents(tree.params));
+                            Symbol constSym = accessConstructor(reference, reference.expr.type.tsym);
+                            expr = makeNewClass(constSym.type, make.Idents(tree.params));
                             break;
                         case ARRAY_CTOR:
                             expr = make.NewArray(
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/concise_methods/NPEQualifierIsCall.java	Tue Oct 02 10:34:29 2018 -0700
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary the verifier is failing when a field of the enclosing class is accessed from a concise method
+ * @compile NPEQualifierIsCall.java
+ */
+
+public class NPEQualifierIsCall implements Runnable {
+    public void run() -> null;
+
+    Runnable f(Runnable r) -> r;
+
+    void m() = f(this)::run;
+}