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

AssertionError when combining pattern matching and function closure

    XMLWordPrintable

Details

    • b31
    • generic
    • generic

    Backports

      Description

        A DESCRIPTION OF THE PROBLEM :
        The Java compiler crashes with an AssertionError when encountering a program that uses pattern matched variable on a closure.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        javac Test.java

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Compile successfully
        ACTUAL -
        java.lang.AssertionError
                at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
                at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
                at jdk.compiler/com.sun.tools.javac.jvm.Items$LocalItem.<init>(Items.java:392)
                at jdk.compiler/com.sun.tools.javac.jvm.Items.makeLocalItem(Items.java:133)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitIdent(Gen.java:2271)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2584)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:877)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitReturn(Gen.java:1838)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1709)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:610)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:645)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:631)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:682)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1097)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1091)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:610)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:645)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:967)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:930)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:921)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:610)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2415)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:737)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1617)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1585)
                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)


        ---------- BEGIN SOURCE ----------
        import java.util.function.Supplier;

        class Test {
            static A x = null;

            static char tmp = (
                (Test.x instanceof B b) ? ((Supplier<B>) () -> b).get() : null
             ).field;
        }


        class A {}
        class B extends A {
            char field = 'd';
        }
        ---------- END SOURCE ----------

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                gli Guoxiong Li
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: