Skip to content

Commit b0450ed

Browse files
author
Vicente Romero
committedFeb 18, 2022
clean up to warnings related code
1 parent aef8323 commit b0450ed

File tree

5 files changed

+66
-8
lines changed

5 files changed

+66
-8
lines changed
 

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,11 @@ public boolean isConvertible(Type t, Type s, Warner warn) {
613613
boolean sValue = s.isPrimitiveClass();
614614
if (allowUniversalTVars && ((s.hasTag(TYPEVAR)) && ((TypeVar)s).isValueProjection() &&
615615
(t.hasTag(BOT) || t.hasTag(TYPEVAR) && !((TypeVar)t).isValueProjection()))) {
616-
warn.warn(LintCategory.UNIVERSAL);
616+
if (t.hasTag(BOT)) {
617+
chk.warnUniversalTVar(warn.pos(), Warnings.UniversalVariableCannotBeAssignedNull);
618+
} else {
619+
chk.warnUniversalTVar(warn.pos(), Warnings.UniversalVariableCannotBeAssignedNull2);
620+
}
617621
return true;
618622
}
619623

@@ -627,7 +631,7 @@ public boolean isConvertible(Type t, Type s, Warner warn) {
627631
if (result && (allowUniversalTVars && !t.hasTag(BOT) &&
628632
s.isPrimitiveClass() && !t.isPrimitiveClass() &&
629633
s.referenceProjectionOrSelf().tsym == t.tsym)) {
630-
chk.warnValueConversion(warn.pos(), Warnings.PrimitiveValueConversion);
634+
chk.warnUniversalTVar(warn.pos(), Warnings.PrimitiveValueConversion);
631635
}
632636
return result;
633637
}

‎src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java

-5
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,6 @@ public void warnUniversalTVar(DiagnosticPosition pos, Warning warnKey) {
300300
log.warning(LintCategory.UNIVERSAL, pos, warnKey);
301301
}
302302

303-
public void warnValueConversion(DiagnosticPosition pos, Warning warnKey) {
304-
if (lint.isEnabled(LintCategory.UNIVERSAL))
305-
log.warning(LintCategory.UNIVERSAL, pos, warnKey);
306-
}
307-
308303
/** Warn about unsafe vararg method decl.
309304
* @param pos Position to be used for error reporting.
310305
*/

‎src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties

+4-1
Original file line numberDiff line numberDiff line change
@@ -4028,7 +4028,10 @@ compiler.err.var.not.initialized.in.default.constructor=\
40284028
variable {0} not initialized in the default constructor
40294029

40304030
compiler.warn.universal.variable.cannot.be.assigned.null=\
4031-
variables of type universal type variable cannot be assigned null
4031+
universal type variables cannot be assigned null
4032+
4033+
compiler.warn.universal.variable.cannot.be.assigned.null.2=\
4034+
probable null assigment to a universal type variable
40324035

40334036
compiler.warn.primitive.value.conversion=\
40344037
primitive value conversion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2022, 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+
// key: compiler.warn.universal.variable.cannot.be.assigned.null.2
25+
// options: -Xlint:universal
26+
27+
import java.util.function.*;
28+
29+
class UniversalCantBeAssignedNull2<__universal K, __universal V> {
30+
K getKey(K k) { return k; }
31+
V getValue(V v) { return v; }
32+
33+
void m(BiFunction<? super K, ? super V, ? extends V> f, K k1, V v1) {
34+
K k = getKey(k1);
35+
V v = getValue(v1);
36+
v = f.apply(k, v);
37+
}
38+
}
39+

‎test/langtools/tools/javac/valhalla/lworld-values/universal-type-variables/UniversalTVarsCompilationTests.java

+17
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ class Box<__universal T> {
9393
"""
9494
);
9595

96+
assertOKWithWarning("compiler.warn.universal.variable.cannot.be.assigned.null.2",
97+
"""
98+
import java.util.function.*;
99+
100+
class MyMap<__universal K, __universal V> {
101+
K getKey(K k) { return k; }
102+
V getValue(V v) { return v; }
103+
104+
void m(BiFunction<? super K, ? super V, ? extends V> f, K k1, V v1) {
105+
K k = getKey(k1);
106+
V v = getValue(v1);
107+
v = f.apply(k, v);
108+
}
109+
}
110+
"""
111+
);
112+
96113
setCompileOptions(EMPTY_OPTIONS);
97114
assertOK(
98115
"""

0 commit comments

Comments
 (0)
Please sign in to comment.