RFR: generate null checks for intersections for which at least one component is null restricted

Vicente Romero vromero at openjdk.org
Fri Jan 9 23:40:52 UTC 2026


javac should generate a null check for code like:


class Test {
    public static void main(String... args) {
        Object s = null;
        Object o = (String & Runnable!) s; // NPE, cast
    }
}

the idea of the fix is to consider an intersection null restricted if at least one of its components is null restricted

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

Commit messages:
 - generate null checks for intersections for which at least one component is null restricted

Changes: https://git.openjdk.org/valhalla/pull/1881/files
  Webrev: https://webrevs.openjdk.org/?repo=valhalla&pr=1881&range=00
  Stats: 18 lines in 2 files changed: 18 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/valhalla/pull/1881.diff
  Fetch: git fetch https://git.openjdk.org/valhalla.git pull/1881/head:pull/1881

PR: https://git.openjdk.org/valhalla/pull/1881


More information about the valhalla-dev mailing list