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

NPE at at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop

    XMLWordPrintable

Details

    • b09
    • 17
    • b29
    • x86_64
    • generic

    Backports

      Description

        A DESCRIPTION OF THE PROBLEM :
        javac crashes at "jdk.compiler/com.sun.tools.javac.jvm.Code.emitop0" with NPE when trying to compile a correct program. The program compiles successfully with 16.0.1 compiler, but crashes with 17.ea.22.

        Pasting the error messages below. Also attached the source code with the bug report.

        java.lang.NullPointerException: Cannot read field "sym" because "this.lvar[2]" is null
                at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop0(Code.java:574)
                at jdk.compiler/com.sun.tools.javac.jvm.Items$LocalItem.load(Items.java:399)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitTypeTest(Gen.java:2233)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCInstanceOf.accept(JCTree.java:2172)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:877)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genCond(Gen.java:783)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genCond(Gen.java:696)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBinary(Gen.java:2136)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBinary.accept(JCTree.java:2114)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:877)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitParens(Gen.java:2005)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCParens.accept(JCTree.java:1972)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:877)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genCond(Gen.java:783)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genCond(Gen.java:696)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitConditional(Gen.java:1878)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCConditional.accept(JCTree.java:1475)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:877)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitLetExpr(Gen.java:2368)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$LetExpr.accept(JCTree.java:3120)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:877)
                at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitParens(Gen.java:2005)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCParens.accept(JCTree.java:1972)
                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:1830)
                at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1667)
                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:1055)
                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:901)
                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:2407)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:756)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1644)
                at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1612)
                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)

        REGRESSION : Last worked in version 16.0.1

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

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        compile successfully
        ACTUAL -
        javac crashes

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

        class Main {
          public Integer foo(Object x) {
            Integer bar = 1;
            return ((x instanceof Number y) ?
                ((Supplier<Integer>) (() -> {
                  return ((y instanceof Integer z) ? z : bar);
                })).get() : bar);
          }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        Remove the bar variable and use an integer value directly.

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: