RFR: [bworld] Emit lint warnings if overriding method does not have same nullability

Chen Liang liach at openjdk.org
Fri Feb 6 00:44:44 UTC 2026


On Fri, 6 Feb 2026 00:23:01 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> emit a lint warning for cases like:
> 
> class Test {
>     String! m(String s) { return ""; }
> }
> class Sub extends Test {
>     @Override
>     String m(String s) { return null; }
> }
> 
> or:
> 
> class Test {
>     String m(String! s) { return ""; }
> }
> class Sub extends Test {
>     @Override
>     String m(String s) { return null; }
> }

test/langtools/tools/javac/nullability/NullabilityCompilationTests.java line 319:

> 317:                                 class Sub extends Test {
> 318:                                     @Override
> 319:                                     String m(String s) { return null; }

I think this should be no-warning, instead we should emit warning if Test.m does not have ! but Sub.m has, meaning test.m(null) call will fail on Sub.

-------------

PR Review Comment: https://git.openjdk.org/valhalla/pull/2058#discussion_r2771741078


More information about the valhalla-dev mailing list