# HG changeset patch # User lana # Date 1444411425 25200 # Node ID 9a64fdcb72be61161ae97b6249f505e56b6e15e4 # Parent f36f0202a450e6e109aabdc1cb8833093d52b02a# Parent a098b538296c7b428ac9c26c98577e8b4f2d2b47 Merge diff -r f36f0202a450 -r 9a64fdcb72be langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Thu Oct 08 22:30:46 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Fri Oct 09 10:23:45 2015 -0700 @@ -3733,17 +3733,17 @@ " in tree " + tree); } - // Test (1): emit a `deprecation' warning if symbol is deprecated. - // (for constructors, the error was given when the constructor was - // resolved) - - if (sym.name != names.init) { + // Emit a `deprecation' warning if symbol is deprecated. + // (for constructors (but not for constructor references), the error + // was given when the constructor was resolved) + + if (sym.name != names.init || tree.hasTag(REFERENCE)) { chk.checkDeprecated(tree.pos(), env.info.scope.owner, sym); chk.checkSunAPI(tree.pos(), sym); chk.checkProfile(tree.pos(), sym); } - // Test (3): if symbol is a variable, check that its type and + // If symbol is a variable, check that its type and // kind are compatible with the prototype and protokind. return check(tree, owntype, sym.kind.toSelector(), resultInfo); } diff -r f36f0202a450 -r 9a64fdcb72be langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Oct 08 22:30:46 2015 -0700 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Oct 09 10:23:45 2015 -0700 @@ -290,6 +290,13 @@ } public boolean isAccessible(Env env, TypeSymbol c, boolean checkInner) { + + /* 15.9.5.1: Note that it is possible for the signature of the anonymous constructor + to refer to an inaccessible type + */ + if (env.enclMethod != null && (env.enclMethod.mods.flags & ANONCONSTR) != 0) + return true; + boolean isAccessible = false; switch ((short)(c.flags() & AccessFlags)) { case PRIVATE: @@ -301,13 +308,7 @@ isAccessible = env.toplevel.packge == c.owner // fast special case || - env.toplevel.packge == c.packge() - || - // Hack: this case is added since synthesized default constructors - // of anonymous classes should be allowed to access - // classes which would be inaccessible otherwise. - env.enclMethod != null && - (env.enclMethod.mods.flags & ANONCONSTR) != 0; + env.toplevel.packge == c.packge(); break; default: // error recovery case PUBLIC: @@ -361,6 +362,13 @@ } public boolean isAccessible(Env env, Type site, Symbol sym, boolean checkInner) { if (sym.name == names.init && sym.owner != site.tsym) return false; + + /* 15.9.5.1: Note that it is possible for the signature of the anonymous constructor + to refer to an inaccessible type + */ + if (env.enclMethod != null && (env.enclMethod.mods.flags & ANONCONSTR) != 0) + return true; + switch ((short)(sym.flags() & AccessFlags)) { case PRIVATE: return @@ -2426,7 +2434,9 @@ return spMethod; } }; - polymorphicSignatureScope.enter(msym); + if (!mtype.isErroneous()) { // Cache only if kosher. + polymorphicSignatureScope.enter(msym); + } return msym; } diff -r f36f0202a450 -r 9a64fdcb72be langtools/test/tools/javac/AnonymousClass/CtorAccessBypassTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/AnonymousClass/CtorAccessBypassTest.java Fri Oct 09 10:23:45 2015 -0700 @@ -0,0 +1,45 @@ +/* + * 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 8075799 + * + * @summary Extraneous access checks implemented by javac + * @compile CtorAccessBypassTest.java + * @run main CtorAccessBypassTest + * + */ + +public class CtorAccessBypassTest { + public static void main(String[] args) { + new CtorAccessBypassTest_01(null) {}; + new CtorAccessBypassTest_01<>(null) {}; + } +} + +class CtorAccessBypassTest_01 { + private class Private {} + CtorAccessBypassTest_01(Private p) { + } +} diff -r f36f0202a450 -r 9a64fdcb72be langtools/test/tools/javac/generics/diamond/neg/Neg18.out --- a/langtools/test/tools/javac/generics/diamond/neg/Neg18.out Thu Oct 08 22:30:46 2015 -0700 +++ b/langtools/test/tools/javac/generics/diamond/neg/Neg18.out Fri Oct 09 10:23:45 2015 -0700 @@ -1,3 +1,3 @@ Neg18.java:14:21: compiler.err.prob.found.req: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: pkg.Neg18_01), (compiler.misc.inaccessible.varargs.type: pkg.Neg18_01.PkgPrivate, kindname.class, Neg18)) -Neg18.java:14:26: compiler.err.not.def.public.cant.access: pkg.Neg18_01.PkgPrivate, pkg.Neg18_01 +Neg18.java:14:9: compiler.err.cant.apply.symbol: kindname.constructor, , pkg.Neg18_01.PkgPrivate[], compiler.misc.no.args, kindname.class, compiler.misc.anonymous.class: , (compiler.misc.inaccessible.varargs.type: pkg.Neg18_01.PkgPrivate, kindname.class, Neg18) 2 errors diff -r f36f0202a450 -r 9a64fdcb72be langtools/test/tools/javac/lambda/MethodHandleInvokeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/lambda/MethodHandleInvokeTest.java Fri Oct 09 10:23:45 2015 -0700 @@ -0,0 +1,49 @@ +/* + * 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 8130506 + * @summary javac AssertionError when invoking MethodHandle.invoke with lambda paramterer + * @run main MethodHandleInvokeTest + */ + +import java.lang.invoke.MethodHandle; + +public class MethodHandleInvokeTest { + + private static interface Obj2Obj { + Object run(Object obj) throws Throwable; + } + + private static void m(Obj2Obj param) { + } + + public static void main(String[] args) { + m((obj) -> { + MethodHandle mhandle = null; + mhandle.invoke(obj); + return null; + }); + } +} diff -r f36f0202a450 -r 9a64fdcb72be langtools/test/tools/javac/warnings/DeprecationSE8Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/DeprecationSE8Test.java Fri Oct 09 10:23:45 2015 -0700 @@ -0,0 +1,47 @@ +/** + * @test /nodynamiccopyright/ + * @bug 8065219 + * @summary Deprecated warning in method reference are missing in some cases. + * @compile/ref=DeprecationSE8Test.noLint.out -XDrawDiagnostics DeprecationSE8Test.java + * @compile/ref=DeprecationSE8Test.out -Xlint:deprecation,-options -source 8 -XDrawDiagnostics DeprecationSE8Test.java + */ + + +class DeprecationSE8Test { + @FunctionalInterface + interface I { + DeprecationSE8Test meth(); + } + + @FunctionalInterface + interface J { + int meth(); + } + + @Deprecated + public DeprecationSE8Test() { + } + + @Deprecated + public static int foo() { + return 1; + } + + // Using deprecated entities from within one's own top level class does not merit warning. + void notBadUsages() { + I i = DeprecationSE8Test::new; + new DeprecationSE8Test(); + J j = DeprecationSE8Test::foo; + foo(); + } +} + +class DeprecationSE8_01 { + // Using deprecated entities from outside one's own top level class deserves warning. + void badUsages() { + DeprecationSE8Test.I i = DeprecationSE8Test::new; + new DeprecationSE8Test(); + DeprecationSE8Test.foo(); + DeprecationSE8Test.J j = DeprecationSE8Test::foo; + } +} diff -r f36f0202a450 -r 9a64fdcb72be langtools/test/tools/javac/warnings/DeprecationSE8Test.noLint.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/DeprecationSE8Test.noLint.out Fri Oct 09 10:23:45 2015 -0700 @@ -0,0 +1,2 @@ +- compiler.note.deprecated.filename: DeprecationSE8Test.java +- compiler.note.deprecated.recompile diff -r f36f0202a450 -r 9a64fdcb72be langtools/test/tools/javac/warnings/DeprecationSE8Test.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/warnings/DeprecationSE8Test.out Fri Oct 09 10:23:45 2015 -0700 @@ -0,0 +1,5 @@ +DeprecationSE8Test.java:42:34: compiler.warn.has.been.deprecated: DeprecationSE8Test(), DeprecationSE8Test +DeprecationSE8Test.java:43:9: compiler.warn.has.been.deprecated: DeprecationSE8Test(), DeprecationSE8Test +DeprecationSE8Test.java:44:27: compiler.warn.has.been.deprecated: foo(), DeprecationSE8Test +DeprecationSE8Test.java:45:34: compiler.warn.has.been.deprecated: foo(), DeprecationSE8Test +4 warnings