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

JDK 17ea: Crash compiling instanceof check involving sealed interface

XMLWordPrintable

    • b31
    • x86_64
    • generic
    • Not verified

        ADDITIONAL SYSTEM INFORMATION :
        openjdk version "17-ea" 2021-09-14
        OpenJDK Runtime Environment (build 17-ea+2-51)
        OpenJDK 64-Bit Server VM (build 17-ea+2-51, mixed mode, sharing)

        macOS 11.0.1 x86_64

        A DESCRIPTION OF THE PROBLEM :
        The source provided will crash when compiled. Removing the `sealed` keyword from interface `I` stops the crash from occurring.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        javac --enable-preview --source 17 Crash.java

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Compiles.
        ACTUAL -
        > javac --enable-preview --source 17 Crash.java
        Note: Crash.java uses preview language features.
        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.ClassCastException: class com.sun.tools.javac.code.Symbol$TypeVariableSymbol cannot be cast to class com.sun.tools.javac.code.Symbol$ClassSymbol (com.sun.tools.javac.code.Symbol$TypeVariableSymbol and com.sun.tools.javac.code.Symbol$ClassSymbol are in module jdk.compiler of loader 'app')
                at jdk.compiler/com.sun.tools.javac.code.Types.isCastable(Types.java:1662)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.visitTypeTest(Attr.java:3977)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCInstanceOf.accept(JCTree.java:2162)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:671)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.visitParens(Attr.java:3793)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCParens.accept(JCTree.java:1962)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:671)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:717)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.visitIf(Attr.java:2071)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1501)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:671)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:745)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:764)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1442)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1047)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:671)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:745)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1232)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:893)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:671)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:745)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5329)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5220)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5056)
                at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5001)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1344)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
                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)

        ---------- BEGIN SOURCE ----------
        class Crash {

          // The crash only occurs if `I` is marked `sealed`.
          sealed interface I<T> {
            final class C implements I<Object> { }
          }

          static <T extends I<Object>> void f(T x) {
            if (x instanceof I<Object>) {
            }
          }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Do not mark `I` as `sealed`.

        FREQUENCY : always


              vromero Vicente Arturo Romero Zaldivar
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: