8144673: Suspect message regarding suitable enclosing instance not being in scope

Javac incorrectly complains about missing enclosing instance while handling method references.

Reviewed-by: vromero
This commit is contained in:
Srikanth Adayapalam 2015-12-08 04:59:19 +05:30
parent 31cdc1ad3d
commit bda66e0df0
3 changed files with 56 additions and 1 deletions

View File

@ -424,6 +424,9 @@ public abstract class Symbol extends AnnoConstruct implements Element {
}
/** The closest enclosing class of this symbol's declaration.
* Warning: this (misnamed) method returns the receiver itself
* when the receiver is a class (as opposed to its enclosing
* class as one may be misled to believe.)
*/
public ClassSymbol enclClass() {
Symbol c = this;

View File

@ -3365,7 +3365,7 @@ public class Resolve {
if (env1 != null) {
while (env1 != null && env1.outer != null) {
if (isStatic(env1)) staticOnly = true;
if (env1.enclClass.sym.isSubClass(member.owner, types)) {
if (env1.enclClass.sym.isSubClass(member.owner.enclClass(), types)) {
Symbol sym = env1.info.scope.findFirst(name);
if (sym != null) {
if (staticOnly) sym = new StaticError(sym);

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2015, 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
* @bug 8144673
* @summary Suspect message regarding suitable enclosing instance not being in scope
* @run main MethodRefToLocalClassMethodTest
*/
import java.util.ArrayList;
import java.util.List;
public class MethodRefToLocalClassMethodTest {
public static void main(String[] args) {
new MethodRefToLocalClassMethodTest().foo();
}
public void foo() {
class LocalFoo {
LocalFoo(String in) {
if (!in.equals("Hello"))
throw new AssertionError("Unexpected data: " + in);
}
}
List<String> ls = new ArrayList<>();
ls.add("Hello");
ls.stream().map(LocalFoo::new).forEach(x->{});
}
}