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

Compile-time AssertionError in pattern switch statement on null

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      Trying to use a pattern in a switch statement (as outlined in JEP 406) when switching on `null` results in a compile-time assertion error, "java.lang.AssertionError: unexpected type: <nulltype>"

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the provided source code with

      javac Bug.java --enable-preview --release 17

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      javac should exit successfully without error after having compiled the file
      ACTUAL -
      Note: Bug.java uses preview features of Java SE 17.
      Note: Recompile with -Xlint:preview for details.
      An exception has occurred in the compiler (17-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
      java.lang.AssertionError: unexpected type: <nulltype>
              at jdk.compiler/com.sun.tools.javac.tree.TreeMaker.Type(TreeMaker.java:860)
              at jdk.compiler/com.sun.tools.javac.tree.TreeMaker.VarDef(TreeMaker.java:882)
              at jdk.compiler/com.sun.tools.javac.comp.TransPatterns.handleSwitch(TransPatterns.java:384)
              at jdk.compiler/com.sun.tools.javac.comp.TransPatterns.visitSwitch(TransPatterns.java:259)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCSwitch.accept(JCTree.java:1294)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransPatterns.visitBlock(TransPatterns.java:685)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:150)
              at jdk.compiler/com.sun.tools.javac.comp.TransPatterns.visitMethodDef(TransPatterns.java:632)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.visitClassDef(TreeTranslator.java:139)
              at jdk.compiler/com.sun.tools.javac.comp.TransPatterns.visitClassDef(TransPatterns.java:712)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:819)
              at jdk.compiler/com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at jdk.compiler/com.sun.tools.javac.comp.TransPatterns.translateTopLevelClass(TransPatterns.java:741)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1535)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1408)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
              at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)
      printing javac parameters to: C:\Users\user\Java\foo\javac.20210708_191807.args

      ---------- BEGIN SOURCE ----------
      class Bug {
          public static void main(String[] args) {
              switch (null) {
                  case Integer i: return;
              }
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jlahoda Jan Lahoda
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: