--- old/src/share/classes/com/sun/tools/javac/comp/Resolve.java 2013-05-07 13:11:17.577266081 -0400 +++ new/src/share/classes/com/sun/tools/javac/comp/Resolve.java 2013-05-07 13:11:17.425265122 -0400 @@ -1852,6 +1852,7 @@ Symbol bestSoFar = typeNotFound; Symbol sym; boolean staticOnly = false; + Symbol staticError = null; for (Env env1 = env; env1.outer != null; env1 = env1.outer) { if (isStatic(env1)) staticOnly = true; for (Scope.Entry e = env1.info.scope.lookup(name); @@ -1860,8 +1861,9 @@ if (e.sym.kind == TYP) { if (staticOnly && e.sym.type.hasTag(TYPEVAR) && - e.sym.owner.kind == TYP) return new StaticError(e.sym); - return e.sym; + e.sym.owner.kind == TYP) staticError = e.sym; + else + return e.sym; } } @@ -1880,6 +1882,8 @@ if ((encl.sym.flags() & STATIC) != 0) staticOnly = true; } + if (staticError != null) + return new StaticError(staticError); if (!env.tree.hasTag(IMPORT)) { sym = findGlobalType(env, env.toplevel.namedImportScope, name); --- /dev/null 2013-05-06 18:17:03.846810054 -0400 +++ new/test/tools/javac/7118412/ShadowingTest.java 2013-05-07 13:11:18.151269601 -0400 @@ -0,0 +1,164 @@ +/* + * 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 7118412 + * @summary javac should generate method parameters correctly. + */ +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; + +public class ShadowingTest { + static final String StaticOverTypeVar_name = "StaticOverTypeVar"; + static final String StaticOverTypeVar_contents = + "public class StaticOverTypeVar {\n" + + " static class T {}\n" + + " static T foo;\n" + + " static T bar() { return null; }\n" + + " static void baz(T t) {}\n" + + " static class S extends T {}\n" + + "}\n"; + static final String NonStaticOverTypeVar_name = "NonStaticOverTypeVar"; + static final String NonStaticOverTypeVar_contents = + "public class NonStaticOverTypeVar {\n" + + " class T {}\n" + + " static T foo;\n" + + " static T bar() { return null; }\n" + + " static void baz(T t) { }\n" + + "}\n"; + static final String NonRegression_name = "NonRegression"; + static final String NonRegression_contents = + "public class NonRegression {\n" + + " static public class Y {}\n" + + " static public class Y1 > {\n" + + " }\n" + + "}\n"; + static final String NonShadowStatic_name = "NonShadowStatic"; + static final String NonShadowStatic_contents = + "import java.util.Collection;\n" + + "public class NonShadowStatic {\n" + + " static void test(T t) { t.foo(); }\n" + + "}\n" + + "class T {\n" + + " public void foo() {}\n" + + "}\n"; + static final String NonShadow_name = "NonShadow"; + static final String NonShadow_contents = + "import java.util.Collection;\n" + + "public class NonShadow {\n" + + " void test(T t) { t.iterator(); }\n" + + "}\n" + + "class T {\n" + + " public void foo() {}\n" + + "}\n"; + static final String NonShadowFail_name = "NonShadowFail"; + static final String NonShadowFail_contents = + "import java.util.Collection;\n" + + "public class NonShadowFail {\n" + + " static void test(T t) { t.iterator(); }\n" + + "}\n"; + + static final File classesdir = new File("7118412"); + + private int errors = 0; + + public static void main(String... args) throws Exception { + new ShadowingTest().run(); + } + + void run() throws Exception { + classesdir.mkdir(); + final File StaticOverTypeVar_java = + writeFile(classesdir, StaticOverTypeVar_name + ".java", + StaticOverTypeVar_contents); + final File NonStaticOverTypeVar_java = + writeFile(classesdir, NonStaticOverTypeVar_name + ".java", + NonStaticOverTypeVar_contents); + final File NonRegression_java = + writeFile(classesdir, NonRegression_name + ".java", + NonRegression_contents); + final File NonShadowStatic_java = + writeFile(classesdir, NonShadowStatic_name + ".java", + NonShadowStatic_contents); + final File NonShadow_java = + writeFile(classesdir, NonShadow_name + ".java", + NonShadow_contents); + final File NonShadowFail_java = + writeFile(classesdir, NonShadowFail_name + ".java", + NonShadowFail_contents); + assert_compile_succeed(StaticOverTypeVar_java); + assert_compile_fail(NonStaticOverTypeVar_java); + assert_compile_succeed(NonRegression_java); + assert_compile_succeed(NonShadowStatic_java); + assert_compile_fail(NonShadow_java); + assert_compile_fail(NonShadowFail_java); + if (errors != 0) + throw new Exception("ShadowingTest test failed with " + + errors + " errors."); + } + + int compile(final File file) { + final String filename = file.getPath(); + final String[] args = { filename }; + final StringWriter sw = new StringWriter(); + final PrintWriter pw = new PrintWriter(sw); + final int rc = com.sun.tools.javac.Main.compile(args, pw); + pw.close(); + System.err.println("Compiled " + filename + ", output:\n" + + sw.toString()); + return rc; + } + + void assert_compile_fail(final File file) { + final int rc = compile(file); + if (rc == 0) { + System.err.println("Compilation of " + file.getName() + + " didn't fail as expected."); + errors++; + } + } + + void assert_compile_succeed(final File file) { + final int rc = compile(file); + if (rc != 0) { + System.err.println("Compilation of " + file.getName() + + " didn't succeed as expected."); + errors++; + } + } + + File writeFile(final File dir, + final String path, + final String body) throws IOException { + final File f = new File(dir, path); + f.getParentFile().mkdirs(); + final FileWriter out = new FileWriter(f); + out.write(body); + out.close(); + return f; + } +}