8009129: Illegal access error when calling method reference
Javac generates method handle referencing non public type Reviewed-by: jjg, rfield
This commit is contained in:
parent
7a28d6291d
commit
e788a0e536
@ -2623,6 +2623,7 @@ public class Attr extends JCTree.Visitor {
|
||||
|
||||
that.sym = refSym.baseSymbol();
|
||||
that.kind = lookupHelper.referenceKind(that.sym);
|
||||
that.ownerAccessible = rs.isAccessible(localEnv, that.sym.enclClass());
|
||||
|
||||
if (desc.getReturnType() == Type.recoveryType) {
|
||||
// stop here
|
||||
|
@ -1775,16 +1775,26 @@ public class LambdaToMethod extends TreeTranslator {
|
||||
}
|
||||
|
||||
boolean isPrivateConstructor() {
|
||||
//hack needed to workaround 292 bug (8005122)
|
||||
//when 292 issue is fixed we should simply remove this
|
||||
return tree.sym.name == names.init &&
|
||||
(tree.sym.flags() & PRIVATE) != 0;
|
||||
}
|
||||
|
||||
boolean receiverAccessible() {
|
||||
//hack needed to workaround 292 bug (7087658)
|
||||
//when 292 issue is fixed we should remove this and change the backend
|
||||
//code to always generate a method handle to an accessible method
|
||||
return tree.ownerAccessible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this reference needs a bridge (i.e. var args need to be
|
||||
* expanded or "super" is used)
|
||||
*/
|
||||
final boolean needsBridge() {
|
||||
return isSuper || needsVarArgsConversion() || isArrayOp() || isPrivateConstructor();
|
||||
return isSuper || needsVarArgsConversion() || isArrayOp() ||
|
||||
isPrivateConstructor() || !receiverAccessible();
|
||||
}
|
||||
|
||||
Type generatedRefSig() {
|
||||
|
@ -766,6 +766,10 @@ compiler.misc.cant.access.inner.cls.constr=\
|
||||
compiler.err.not.def.public.cant.access=\
|
||||
{0} is not public in {1}; cannot be accessed from outside package
|
||||
|
||||
# 0: symbol, 1: symbol
|
||||
compiler.misc.not.def.public.cant.access=\
|
||||
{0} is not public in {1}; cannot be accessed from outside package
|
||||
|
||||
# 0: name
|
||||
compiler.err.not.loop.label=\
|
||||
not a loop label: {0}
|
||||
|
@ -1887,6 +1887,7 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
|
||||
public Symbol sym;
|
||||
public Type varargsElement;
|
||||
public PolyKind refPolyKind;
|
||||
public boolean ownerAccessible;
|
||||
|
||||
/**
|
||||
* Javac-dependent classification for member references, based
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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.
|
||||
*/
|
||||
|
||||
// key: compiler.err.prob.found.req
|
||||
// key: compiler.misc.invalid.mref
|
||||
// key: compiler.misc.not.def.public.cant.access
|
||||
|
||||
class NotDefPublicCantAccessFragment {
|
||||
interface SAM {
|
||||
void m();
|
||||
}
|
||||
|
||||
void test (p.C c) {
|
||||
SAM s = c::m;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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.
|
||||
*/
|
||||
|
||||
package p;
|
||||
|
||||
public class C {
|
||||
void m() { }
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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 8003280
|
||||
* @summary Add lambda tests
|
||||
* check that classfiles with member ref CP entries are read correctly
|
||||
* @compile/fail/ref=InaccessibleMref01.out -XDrawDiagnostics InaccessibleMref01.java
|
||||
*/
|
||||
class InaccessibleMref01 {
|
||||
interface SAM {
|
||||
void m();
|
||||
}
|
||||
|
||||
void test(p1.C c) {
|
||||
SAM s = c::m;
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
InaccessibleMref01.java:37:17: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.method, (compiler.misc.not.def.public.cant.access: m(), p1.C))
|
||||
1 error
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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.
|
||||
*/
|
||||
package p1;
|
||||
|
||||
public class C {
|
||||
void m() { }
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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 8003280
|
||||
* @summary Add lambda tests
|
||||
* check that classfiles with member ref CP entries are read correctly
|
||||
*/
|
||||
public class InaccessibleMref02 {
|
||||
interface SAM {
|
||||
void m();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
p1.C c = new p1.C();
|
||||
SAM s = c::m;
|
||||
s.m();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 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.
|
||||
*/
|
||||
package p1;
|
||||
|
||||
class Sup {
|
||||
public void m() { }
|
||||
}
|
||||
|
||||
public class C extends Sup { }
|
Loading…
x
Reference in New Issue
Block a user