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

java.lang.AssertionError: E.value - compiler crashes when using Type parameter with enhanced switch

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Fedora Linux, Oracle Java build 19.0.1+10-21

      $ java -version
      java version "19.0.1" 2022-10-18
      Java(TM) SE Runtime Environment (build 19.0.1+10-21)
      Java HotSpot(TM) 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)

      $ uname -a
      Linux neumann 5.19.16-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Oct 16 22:50:04 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Compilation of the following program fails with an java.lang.AssertionError thrown within the Java compiler.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Compile via javac --enable-preview -source 19 -cp . *.java
      2) Observe output

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Program should compile.
      ACTUAL -
      java: An exception has occurred in the compiler (19.0.1). 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: java.lang.AssertionError: E.value
      java: at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:162)
      java: at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.<init>(Symbol.java:1920)
      java: at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol$1.<init>(Symbol.java:1926)
      java: at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.clone(Symbol.java:1926)
      java: at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.clone(Symbol.java:1896)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.binaryQualifier(Gen.java:261)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitSelect(Gen.java:2340)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2530)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:881)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1879)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1799)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitNewArray(Gen.java:1989)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCNewArray.accept(JCTree.java:1910)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:906)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1884)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1752)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1586)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:610)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:645)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:631)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:682)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:666)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.handleSwitch(Gen.java:1377)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitSwitch(Gen.java:1197)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCSwitch.accept(JCTree.java:1287)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1101)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1082)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:971)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:934)
      java: at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
      java: at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2424)
      java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:737)
      java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1635)
      java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1603)
      Writing classes… [java19]
      java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:946)
      java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
      java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
      java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
      java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
      java: at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:237)
      java: at org.jetbrains.jps.javac.ExternalJavacProcess.compile(ExternalJavacProcess.java:195)
      java: at org.jetbrains.jps.javac.ExternalJavacProcess.access$400(ExternalJavacProcess.java:30)
      java: at org.jetbrains.jps.javac.ExternalJavacProcess$CompilationRequestsHandler$1.run(ExternalJavacProcess.java:268)
      java: at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
      java: at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
      java: at java.base/java.lang.Thread.run(Thread.java:1589)
      java: Compilation failed: internal java compiler error

      ---------- BEGIN SOURCE ----------
      class ExtensiblePseudoEnums {

          static final CustomEnum CUSTOM = "custom"::toString;

          public static void main(String[] args) {
              consumeCustomEnum(CustomEnum.DEFAULT);
              consumeCustomEnum(CUSTOM);
          }

          static <E extends CustomEnum> void consumeCustomEnum(E customEnum) {
              System.out.println(customEnum.value());

              switch (customEnum) {
                  case E e when e == CUSTOM -> System.out.printf("handle %s%n", e.value());
                  default -> System.out.printf("handle %s%n", customEnum.value());
              }
          }

          interface CustomEnum {

              CustomEnum DEFAULT = "default"::toString;

              String value();
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: