Mercurial > hg > openjdk > jdk9 > langtools
changeset 3145:ab5e0a945e78
8078660: Misleading recommendation from diamond finder.
Summary: javac should recommend diamond usage if that could lead to a change in program behavior.
Reviewed-by: mcimadamore
author | sadayapalam |
---|---|
date | Thu, 26 Nov 2015 17:38:15 +0530 |
parents | 130ae42e6da7 |
children | 853c77f8193c |
files | src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties test/tools/javac/diags/examples/DiamondRedundantArgs1.java test/tools/javac/generics/diamond/6939780/T6939780_7.out test/tools/javac/generics/diamond/6939780/T6939780_8.out test/tools/javac/generics/diamond/6939780/T6939780_9.out test/tools/javac/generics/diamond/7002837/T7002837.java test/tools/javac/generics/diamond/7002837/T7002837.out test/tools/javac/generics/diamond/neg/T8078473.java test/tools/javac/generics/diamond/neg/T8078473.out test/tools/javac/generics/diamond/neg/T8078473_2.java test/tools/javac/generics/diamond/neg/T8078473_2.out |
diffstat | 12 files changed, 84 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java Thu Nov 26 09:33:41 2015 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java Thu Nov 26 17:38:15 2015 +0530 @@ -241,8 +241,6 @@ } for (Type t : inferredArgs) { if (!types.isSameType(t, explicitArgs.head)) { - log.warning(oldTree.clazz, "diamond.redundant.args.1", - oldTree.clazz.type, newTree.clazz.type); return; } explicitArgs = explicitArgs.tail;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Nov 26 09:33:41 2015 +0100 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Nov 26 17:38:15 2015 +0530 @@ -1669,12 +1669,6 @@ compiler.warn.diamond.redundant.args=\ Redundant type arguments in new expression (use diamond operator instead). -# 0: type, 1: list of type -compiler.warn.diamond.redundant.args.1=\ - Redundant type arguments in new expression (use diamond operator instead).\n\ - explicit: {0}\n\ - inferred: {1} - compiler.warn.potential.lambda.found=\ This anonymous inner class creation can be turned into a lambda expression.
--- a/test/tools/javac/diags/examples/DiamondRedundantArgs1.java Thu Nov 26 09:33:41 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2010, 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.warn.diamond.redundant.args.1 -// options: -XDfind=diamond - -class DiamondRedundantArgs1<X> { - DiamondRedundantArgs1<?> fs = new DiamondRedundantArgs1<String>(); -}
--- a/test/tools/javac/generics/diamond/6939780/T6939780_7.out Thu Nov 26 09:33:41 2015 +0100 +++ b/test/tools/javac/generics/diamond/6939780/T6939780_7.out Thu Nov 26 17:38:15 2015 +0530 @@ -1,5 +1,3 @@ T6939780.java:22:28: compiler.warn.diamond.redundant.args -T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number> T6939780.java:31:19: compiler.warn.diamond.redundant.args -T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number> -4 warnings +2 warnings
--- a/test/tools/javac/generics/diamond/6939780/T6939780_8.out Thu Nov 26 09:33:41 2015 +0100 +++ b/test/tools/javac/generics/diamond/6939780/T6939780_8.out Thu Nov 26 17:38:15 2015 +0530 @@ -1,7 +1,5 @@ T6939780.java:21:33: compiler.warn.diamond.redundant.args T6939780.java:22:28: compiler.warn.diamond.redundant.args -T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number> T6939780.java:30:19: compiler.warn.diamond.redundant.args T6939780.java:31:19: compiler.warn.diamond.redundant.args -T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number> -6 warnings +4 warnings
--- a/test/tools/javac/generics/diamond/6939780/T6939780_9.out Thu Nov 26 09:33:41 2015 +0100 +++ b/test/tools/javac/generics/diamond/6939780/T6939780_9.out Thu Nov 26 17:38:15 2015 +0530 @@ -1,13 +1,9 @@ T6939780.java:21:33: compiler.warn.diamond.redundant.args T6939780.java:22:28: compiler.warn.diamond.redundant.args -T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number> T6939780.java:24:33: compiler.warn.diamond.redundant.args T6939780.java:25:28: compiler.warn.diamond.redundant.args -T6939780.java:26:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number> T6939780.java:30:19: compiler.warn.diamond.redundant.args T6939780.java:31:19: compiler.warn.diamond.redundant.args -T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number> T6939780.java:33:19: compiler.warn.diamond.redundant.args T6939780.java:34:19: compiler.warn.diamond.redundant.args -T6939780.java:35:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number> -12 warnings +8 warnings
--- a/test/tools/javac/generics/diamond/7002837/T7002837.java Thu Nov 26 09:33:41 2015 +0100 +++ b/test/tools/javac/generics/diamond/7002837/T7002837.java Thu Nov 26 17:38:15 2015 +0530 @@ -1,10 +1,34 @@ /* - * @test /nodynamiccopyright/ - * @bug 7002837 8064365 + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 7002837 8064365 8078660 * * @summary Diamond: javac generates diamond inference errors when in 'finder' mode * @author mcimadamore - * @compile/fail/ref=T7002837.out -Werror -XDrawDiagnostics -XDfind=diamond T7002837.java + * @compile -Werror -XDrawDiagnostics -XDfind=diamond T7002837.java * */
--- a/test/tools/javac/generics/diamond/7002837/T7002837.out Thu Nov 26 09:33:41 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -T7002837.java:13:19: compiler.warn.diamond.redundant.args.1: T7002837<java.lang.Integer>, T7002837<java.lang.Object&java.io.Serializable&java.lang.Comparable<?>> -- compiler.err.warnings.and.werror -1 error -1 warning
--- a/test/tools/javac/generics/diamond/neg/T8078473.java Thu Nov 26 09:33:41 2015 +0100 +++ b/test/tools/javac/generics/diamond/neg/T8078473.java Thu Nov 26 17:38:15 2015 +0530 @@ -1,8 +1,32 @@ /* - * @test /nodynamiccopyright/ - * @bug 8078473 + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 8078473 8078660 * @summary javac diamond finder crashes when used to build java.base module - * @compile/ref=T8078473.out T8078473.java -XDrawDiagnostics -XDfind=diamond + * @compile -Werror T8078473.java -XDrawDiagnostics -XDfind=diamond */ class T8078473<P, Q> {
--- a/test/tools/javac/generics/diamond/neg/T8078473.out Thu Nov 26 09:33:41 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -T8078473.java:15:14: compiler.warn.diamond.redundant.args.1: T8078473.C<Q,Q>, T8078473.C<java.lang.Object,java.lang.Object> -T8078473.java:16:14: compiler.warn.diamond.redundant.args.1: T8078473.C<Q,Q>, T8078473.C<java.lang.Object,java.lang.Object> -2 warnings
--- a/test/tools/javac/generics/diamond/neg/T8078473_2.java Thu Nov 26 09:33:41 2015 +0100 +++ b/test/tools/javac/generics/diamond/neg/T8078473_2.java Thu Nov 26 17:38:15 2015 +0530 @@ -1,8 +1,32 @@ /* - * @test /nodynamiccopyright/ - * @bug 8078473 + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 8078473 8078660 * @summary javac diamond finder crashes when used to build java.base module - * @compile/ref=T8078473_2.out T8078473_2.java -XDrawDiagnostics -XDfind=diamond + * @compile -Werror T8078473_2.java -XDrawDiagnostics -XDfind=diamond */ package java.util.stream;
--- a/test/tools/javac/generics/diamond/neg/T8078473_2.out Thu Nov 26 09:33:41 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -T8078473_2.java:17:13: compiler.warn.diamond.redundant.args.1: java.util.stream.T8078473_2.C<Q,Q>, java.util.stream.T8078473_2.C<java.lang.Object,java.lang.Object> -T8078473_2.java:18:13: compiler.warn.diamond.redundant.args.1: java.util.stream.T8078473_2.C<Q,Q>, java.util.stream.T8078473_2.C<java.lang.Object,java.lang.Object> -2 warnings