Skip to content

Commit 85cffce

Browse files
author
Vicente Romero
committed
Merge bworld
2 parents 4b368a0 + 3f65ddd commit 85cffce

File tree

4 files changed

+47
-24
lines changed

4 files changed

+47
-24
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4008,13 +4008,16 @@ void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkCon
40084008
checkContext.report(tree, diags.fragment(Fragments.IncompatibleArgTypesInLambda));
40094009
} else if (allowNullRestrictedTypes) {
40104010
// ok they are equal but what about nullability?
4011-
for (ArgsNullabilityResult incompatibleParam :
4012-
chk.checkArgsNullability(lambdaTypes, argTypes, tree.params)) {
4013-
chk.warnNullableTypes(incompatibleParam.position() != null ?
4014-
incompatibleParam.position().vartype : tree,
4011+
boolean isSpeculativeRound = checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE;
4012+
if (!isSpeculativeRound) {
4013+
for (ArgsNullabilityResult incompatibleParam :
4014+
chk.checkArgsNullability(lambdaTypes, argTypes, tree.params)) {
4015+
chk.warnNullableTypes(incompatibleParam.position() != null ?
4016+
incompatibleParam.position().vartype : tree,
40154017
LintWarnings.IncompatibleNullRestrictions(
40164018
Fragments.LambdaArgumentTypeNullabilityMismatch(incompatibleParam.overridingType(),
4017-
incompatibleParam.overridenType())));
4019+
incompatibleParam.overridenType(), tree.target)));
4020+
}
40184021
}
40194022
}
40204023
}
@@ -4323,7 +4326,7 @@ void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refT
43234326
chk.warnNullableTypes(tree,
43244327
LintWarnings.IncompatibleNullRestrictions(
43254328
Fragments.MethodReferenceArgumentTypeNullabilityMismatch(incompatibleParam.overridingType(),
4326-
incompatibleParam.overridenType())));
4329+
incompatibleParam.overridenType(), tree.target)));
43274330
}
43284331
}
43294332
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,11 +1899,11 @@ void checkOverride(JCTree tree,
18991899
checkArgsNullability(mt.getParameterTypes(), ot.getParameterTypes(), params)) {
19001900
warnNullableTypes(incompatibleParam.position != null ? incompatibleParam.position.vartype : theTree,
19011901
LintWarnings.IncompatibleNullRestrictions(
1902-
Fragments.ArgumentTypeNullabilityMismatch(incompatibleParam.overridingType, incompatibleParam.overridenType)));
1902+
Fragments.ArgumentTypeNullabilityMismatch(incompatibleParam.overridingType, incompatibleParam.overridenType, other.owner, other)));
19031903
}
19041904
if (types.hasNarrowerNullability(ot.getReturnType(), mt.getReturnType())) {
19051905
warnNullableTypes(resultTypePos, LintWarnings.IncompatibleNullRestrictions(
1906-
Fragments.ReturnTypeNullabilityMismatch(mt.getReturnType(), ot.getReturnType())));
1906+
Fragments.ReturnTypeNullabilityMismatch(mt.getReturnType(), ot.getReturnType(), other.owner, other)));
19071907
}
19081908
}
19091909
}

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,21 +4388,25 @@ compiler.warn.incompatible.null.restrictions=\
43884388
incompatible null restrictions in overriding method\n\
43894389
{0}
43904390

4391-
# 0: type, 1: type
4391+
# 0: type, 1: type, 2: symbol, 3: symbol
43924392
compiler.misc.return.type.nullability.mismatch=\
4393-
return type {0} in the overriding does not match the return type {1} in the overridden method
4393+
return type {0} in the overriding does not match the return type {1}\n\
4394+
in the overridden method: {2}.{3}
43944395

4395-
# 0: type, 1: type
4396+
# 0: type, 1: type, 2: symbol, 3: symbol
43964397
compiler.misc.argument.type.nullability.mismatch=\
4397-
parameter type {0} in the overriding does not match the parameter type {1} in the overridden method
4398+
parameter type {0} in the overriding does not match the parameter type {1}\n\
4399+
in the overridden method: {2}.{3}
43984400

4399-
# 0: type, 1: type
4401+
# 0: type, 1: type, 2: type
44004402
compiler.misc.lambda.argument.type.nullability.mismatch=\
4401-
parameter type {0} in lambda expression does not match the parameter type {1} in the target
4403+
parameter type {0} in lambda expression does not match the parameter type {1}\n\
4404+
in target: {2}
44024405

4403-
# 0: type, 1: type
4406+
# 0: type, 1: type, 2: type
44044407
compiler.misc.method.reference.argument.type.nullability.mismatch=\
4405-
parameter type {0} in the referred method does not match the parameter type {1} in the target
4408+
parameter type {0} in the referred method does not match the parameter type {1}\n\
4409+
in target: {2}
44064410

44074411
# 0: type
44084412
compiler.err.restricted.array.missing.init =\

test/langtools/tools/javac/nullability/NullabilityCompilationTests.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,23 @@ void m(Impl impl) {
390390
""",
391391
Result.Warning,
392392
"compiler.warn.incompatible.null.restrictions",
393-
2)
393+
2),
394+
new DiagAndCode(
395+
"""
396+
interface I {
397+
String! m();
398+
}
399+
class Test {
400+
public String! m() { return ""; }
401+
}
402+
class Sub extends Test implements I {
403+
@Override
404+
public String m() { return null; }
405+
}
406+
""",
407+
Result.Warning,
408+
"compiler.warn.incompatible.null.restrictions",
409+
2) // one warning per each method in the corresponding parents
394410
)
395411
);
396412
}
@@ -412,7 +428,7 @@ class Sub extends Super {
412428
}
413429
""",
414430
List.of(
415-
"Sub.java:3:5: compiler.warn.incompatible.null.restrictions: (compiler.misc.return.type.nullability.mismatch: java.lang.String, java.lang.String!)",
431+
"Sub.java:3:5: compiler.warn.incompatible.null.restrictions: (compiler.misc.return.type.nullability.mismatch: java.lang.String, java.lang.String!, Super, m(java.lang.String))",
416432
"1 warning"
417433
)
418434
);
@@ -430,8 +446,8 @@ class Sub extends Super {
430446
}
431447
""",
432448
List.of(
433-
"Sub.java:3:14: compiler.warn.incompatible.null.restrictions: (compiler.misc.argument.type.nullability.mismatch: java.lang.String, java.lang.String!)",
434-
"Sub.java:3:24: compiler.warn.incompatible.null.restrictions: (compiler.misc.argument.type.nullability.mismatch: java.lang.Integer, java.lang.Integer!)",
449+
"Sub.java:3:14: compiler.warn.incompatible.null.restrictions: (compiler.misc.argument.type.nullability.mismatch: java.lang.String, java.lang.String!, Super, m(java.lang.String!,java.lang.Integer!))",
450+
"Sub.java:3:24: compiler.warn.incompatible.null.restrictions: (compiler.misc.argument.type.nullability.mismatch: java.lang.Integer, java.lang.Integer!, Super, m(java.lang.String!,java.lang.Integer!))",
435451
"2 warnings"
436452
)
437453
);
@@ -451,8 +467,8 @@ class Sub extends Super {
451467
}
452468
""",
453469
List.of(
454-
"Sub.java:4:14: compiler.warn.incompatible.null.restrictions: (compiler.misc.argument.type.nullability.mismatch: java.util.List, java.util.List<java.lang.String>!)",
455-
"Sub.java:4:22: compiler.warn.incompatible.null.restrictions: (compiler.misc.argument.type.nullability.mismatch: java.util.List, java.util.List<java.lang.Integer>!)",
470+
"Sub.java:4:14: compiler.warn.incompatible.null.restrictions: (compiler.misc.argument.type.nullability.mismatch: java.util.List, java.util.List<java.lang.String>!, Super, m(java.util.List<java.lang.String>!,java.util.List<java.lang.Integer>!))",
471+
"Sub.java:4:22: compiler.warn.incompatible.null.restrictions: (compiler.misc.argument.type.nullability.mismatch: java.util.List, java.util.List<java.lang.Integer>!, Super, m(java.util.List<java.lang.String>!,java.util.List<java.lang.Integer>!))",
456472
"2 warnings"
457473
)
458474
);
@@ -469,8 +485,8 @@ class Sub {
469485
}
470486
""",
471487
List.of(
472-
"Sub.java:2:16: compiler.warn.incompatible.null.restrictions: (compiler.misc.lambda.argument.type.nullability.mismatch: java.lang.String, java.lang.String!)",
473-
"Sub.java:2:26: compiler.warn.incompatible.null.restrictions: (compiler.misc.lambda.argument.type.nullability.mismatch: java.lang.Integer, java.lang.Integer!)",
488+
"Sub.java:2:16: compiler.warn.incompatible.null.restrictions: (compiler.misc.lambda.argument.type.nullability.mismatch: java.lang.String, java.lang.String!, Super)",
489+
"Sub.java:2:26: compiler.warn.incompatible.null.restrictions: (compiler.misc.lambda.argument.type.nullability.mismatch: java.lang.Integer, java.lang.Integer!, Super)",
474490
"2 warnings"
475491
)
476492
);

0 commit comments

Comments
 (0)