--- /dev/null 2013-05-21 07:29:47.963806054 -0400 +++ new/test/tools/javac/8013357/ObjectZeroCompare.java 2013-05-29 15:45:33.559263314 -0400 @@ -0,0 +1,260 @@ +/* + * 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 8013357 + * @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 ObjectZeroCompare { + static final String LeftObject_name = "LeftObject"; + static final String LeftObject_contents = + "public class LeftObject {\n" + + " LeftObject() {}\n" + + " boolean foo0(Object o) {\n" + + " return o == 0;\n" + + " }\n" + + "}\n"; + static final String RightObject_name = "RightObject"; + static final String RightObject_contents = + "public class RightObject {\n" + + " RightObject() {}\n" + + " boolean foo0(Object o) {\n" + + " return 0 == o;\n" + + " }\n" + + "}\n"; + static final String LeftUncastable_name = "LeftUncastable"; + static final String LeftUncastable_contents = + "public class LeftUncastable {\n" + + " LeftUncastable() {}\n" + + " boolean foo0(String o, Integer i) {\n" + + " return o == i;\n" + + " }\n" + + "}\n"; + static final String RightUncastable_name = "RightUncastable"; + static final String RightUncastable_contents = + "public class RightUncastable {\n" + + " RightUncastable() {}\n" + + " boolean foo0(String o, Integer i) {\n" + + " return i == o;\n" + + " }\n" + + "}\n"; + static final String LeftCastable_name = "LeftCastable"; + static final String LeftCastable_contents = + "public class LeftCastable {\n" + + " LeftCastable() {}\n" + + " boolean foo0(Number n, Integer i) {\n" + + " return n == i;\n" + + " }\n" + + "}\n"; + static final String RightCastable_name = "RightCastable"; + static final String RightCastable_contents = + "public class RightCastable {\n" + + " RightCastable() {}\n" + + " boolean foo0(Number n, Integer i) {\n" + + " return i == n;\n" + + " }\n" + + "}\n"; + static final String LeftNumber_name = "LeftNumber"; + static final String LeftNumber_contents = + "public class LeftNumber {\n" + + " LeftNumber() {}\n" + + " boolean bar0(Number o) {\n" + + " return o == 0;\n" + + " }\n" + + "}\n"; + static final String RightNumber_name = "RightNumber"; + static final String RightNumber_contents = + "public class RightNumber {\n" + + " RightNumber() {}\n" + + " boolean bar0(Number o) {\n" + + " return 0 == o;\n" + + " }\n" + + "}\n"; + static final String LeftInteger_name = "LeftInteger"; + static final String LeftInteger_contents = + "public class LeftInteger {\n" + + " LeftInteger() {}\n" + + " boolean baz0(Integer o) {\n" + + " return 0 == o;\n" + + " }\n" + + "}\n"; + static final String RightInteger_name = "RightInteger"; + static final String RightInteger_contents = + "public class RightInteger {\n" + + " RightInteger() {}\n" + + " boolean baz0(Integer o) {\n" + + " return 0 == o;\n" + + " }\n" + + "}\n"; + static final String LeftDouble_name = "LeftDouble"; + static final String LeftDouble_contents = + "public class LeftDouble {\n" + + " LeftDouble() {}\n" + + " boolean qux0(Double o) {\n" + + " return o == 0.0;\n" + + " }\n" + + "}\n"; + static final String RightDouble_name = "RightDouble"; + static final String RightDouble_contents = + "public class RightDouble {\n" + + " RightDouble() {}\n" + + " boolean qux0(Double o) {\n" + + " return o == 0.0;\n" + + " }\n" + + "}\n"; + static final String LeftBoolean_name = "LeftBoolean"; + static final String LeftBoolean_contents = + "public class LeftBoolean {\n" + + " LeftBoolean() {}\n" + + " boolean quux0(Boolean b) {\n" + + " return true == b;\n" + + " }\n" + + "}\n"; + static final String RightBoolean_name = "RightBoolean"; + static final String RightBoolean_contents = + "public class RightBoolean {\n" + + " RightBoolean() {}\n" + + " boolean quux0(Boolean b) {\n" + + " return true == b;\n" + + " }\n" + + "}\n"; + static final File classesdir = new File("8013357"); + + private int errors = 0; + + public static void main(String... args) throws Exception { + new ObjectZeroCompare().run(); + } + + void run() throws Exception { + classesdir.mkdir(); + final File LeftObject_java = + writeFile(classesdir, LeftObject_name + ".java", + LeftObject_contents); + final File RightObject_java = + writeFile(classesdir, RightObject_name + ".java", + RightObject_contents); + final File LeftUncastable_java = + writeFile(classesdir, LeftUncastable_name + ".java", + LeftUncastable_contents); + final File RightUncastable_java = + writeFile(classesdir, RightUncastable_name + ".java", + RightUncastable_contents); + final File LeftNumber_java = + writeFile(classesdir, LeftNumber_name + ".java", + LeftNumber_contents); + final File RightNumber_java = + writeFile(classesdir, RightNumber_name + ".java", + RightNumber_contents); + final File LeftCastable_java = + writeFile(classesdir, LeftCastable_name + ".java", + LeftCastable_contents); + final File RightCastable_java = + writeFile(classesdir, RightCastable_name + ".java", + RightCastable_contents); + final File LeftInteger_java = + writeFile(classesdir, LeftInteger_name + ".java", + LeftInteger_contents); + final File RightInteger_java = + writeFile(classesdir, RightInteger_name + ".java", + RightInteger_contents); + final File LeftDouble_java = + writeFile(classesdir, LeftDouble_name + ".java", + LeftDouble_contents); + final File RightDouble_java = + writeFile(classesdir, RightDouble_name + ".java", + RightDouble_contents); + final File LeftBoolean_java = + writeFile(classesdir, LeftBoolean_name + ".java", + LeftBoolean_contents); + final File RightBoolean_java = + writeFile(classesdir, RightBoolean_name + ".java", + RightBoolean_contents); + assert_compile_fail(LeftObject_java); + assert_compile_fail(RightObject_java); + assert_compile_fail(LeftUncastable_java); + assert_compile_fail(RightUncastable_java); + assert_compile_succeed(LeftNumber_java); + assert_compile_succeed(RightNumber_java); + assert_compile_succeed(LeftCastable_java); + assert_compile_succeed(RightCastable_java); + assert_compile_succeed(LeftInteger_java); + assert_compile_succeed(RightInteger_java); + assert_compile_succeed(LeftDouble_java); + assert_compile_succeed(RightDouble_java); + assert_compile_succeed(LeftBoolean_java); + assert_compile_succeed(RightBoolean_java); + if (errors != 0) + throw new Exception("ObjectZeroCompare 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; + } + +}