Skip to content

Commit ff4018b

Browse files
author
Vicente Romero
committed
8268148: unchecked warnings handle ? and ? extends Object differently
Reviewed-by: jlahoda
1 parent 8c37909 commit ff4018b

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,9 @@ public boolean isExtendsBound() {
877877
kind == UNBOUND;
878878
}
879879
public boolean isUnbound() {
880-
return kind == UNBOUND;
880+
// is it `?` or `? extends Object`?
881+
return kind == UNBOUND ||
882+
(kind == EXTENDS && type.tsym.flatName() == type.tsym.name.table.names.java_lang_Object);
881883
}
882884

883885
@Override
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
T8176534.java:12:43: compiler.warn.unchecked.meth.invocation.applied: kindname.method, forEnumeration, java.util.Enumeration<T>, java.util.Enumeration, kindname.class, T8176534
22
T8176534.java:12:44: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.util.Enumeration, java.util.Enumeration<T>
33
T8176534.java:12:28: compiler.warn.unchecked.meth.invocation.applied: kindname.method, newArrayList, java.util.Iterator<? extends E>, java.util.Iterator, kindname.class, T8176534
4-
T8176534.java:12:43: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.util.Iterator, java.util.Iterator<? extends E>
54
T8176534.java:12:28: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.util.ArrayList, java.util.List<java.lang.String>
65
- compiler.err.warnings.and.werror
76
1 error
8-
5 warnings
7+
4 warnings
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8268148
27+
* @summary unchecked warnings handle ? and ? extends Object differently
28+
* @compile -Xlint:all -Werror UnboundAndBoundByObjectTest.java
29+
*/
30+
31+
import java.util.List;
32+
33+
class UnboundAndBoundByObjectTest {
34+
void f(List<? extends Object> x) {}
35+
void g(List<?> x) {}
36+
37+
void h(List<String> x) {
38+
f((List) x);
39+
g((List) x);
40+
}
41+
}

0 commit comments

Comments
 (0)