Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8348901

14.11.1: Allow 'null' case label for 'switch (null)'

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • None
    • specification

      Reported on compiler-dev:
      https://mail.openjdk.org/pipermail/compiler-dev/2025-January/029306.html

      This rule says that a 'null' case label is only allowed for a switch block if the selector expression has a reference type:

      "If a null literal is associated with the switch block, then T is a reference type."

      4.1 considers the null type as something distinct from the set of reference types. Other parts of JLS use "reference type" to refer to a set of types that *excludes* the null type (e.g., the typing rule for synchronized statements in 14.19).

      The 14.11.1 rule should say

      If a null literal is associated with the switch block, then T is a reference type **or the null type**.

            gbierman Gavin Bierman
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: