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

javac AssertionError when invoking MethodHandle.invoke with lambda parameter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u20, 9
    • Fix Version/s: 9
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b86
    • CPU:
      x86_64
    • OS:
      linux_ubuntu
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
        java version "1.8.0_45"
        Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
        Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux attila-pc 3.19.0-21-generic #21-Ubuntu SMP Sun Jun 14 18:31:11 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        A lambda method, returning anything but not void, has 1+ parameters, passed to a method or constructor, can't invoke MethodHandle::invoke passing the lambda's parameter to MethodHandle::invoke. See the example code.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Try compiling the code specified below at the "Source code for an executable test case:" field.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The code compiles.
        ACTUAL -
        The code doesn't compiles.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        ant -f /home/attila/develop/TermLib -Djavac.includes=JavacBug.java -Dnb.internal.action.name=run.single -Drun.class=JavacBug run-single
        init:
        Deleting: /home/attila/develop/TermLib/build/built-jar.properties
        deps-jar:
        Updating property file: /home/attila/develop/TermLib/build/built-jar.properties
        Compiling 1 source file to /home/attila/develop/TermLib/build/classes
        An exception has occurred in the compiler (1.8.0_45). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
        java.lang.AssertionError: typecode ERROR
        at com.sun.tools.javac.jvm.Code.typecode(Code.java:252)
        at com.sun.tools.javac.jvm.Items$Item.coerce(Items.java:269)
        at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:951)
        at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:968)
        at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1909)
        at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
        at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:949)
        at com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1846)
        at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
        at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:739)
        at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:774)
        at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:760)
        at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:811)
        at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1160)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
        at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:739)
        at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:774)
        at com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:1033)
        at com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:996)
        at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
        at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:739)
        at com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2528)
        at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:745)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1572)
        at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1536)
        at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.main.Main.compile(Main.java:381)
        at com.sun.tools.javac.main.Main.compile(Main.java:370)
        at com.sun.tools.javac.main.Main.compile(Main.java:361)
        at com.sun.tools.javac.Main.compile(Main.java:56)
        at sun.reflect.GeneratedMethodAccessor241.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56)
        at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1159)
        at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:935)
        at org.netbeans.modules.java.source.ant.JavacTask.execute(JavacTask.java:145)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor120.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor120.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.GeneratedMethodAccessor120.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
        at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:286)
        at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:555)
        at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
        /home/attila/develop/TermLib/nbproject/build-impl.xml:949: The following error occurred while executing this line:
        /home/attila/develop/TermLib/nbproject/build-impl.xml:265: Compile failed; see the compiler error output for details.
        BUILD FAILED (total time: 0 seconds)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.lang.invoke.MethodHandle;

        class JavacBug {

        private static interface Obj2Obj {

        Object run(Object obj) throws Throwable;
        }

        private static void m(Obj2Obj param) {
        }

        public static void main(String[] args) {
        m((obj) -> {
        MethodHandle mhandle = null;
        mhandle.invoke(obj);
        return null;
        });
        }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        Instead of
        mhandle.invoke(obj);
        use a temp variable:
        Object var = obj;
        mhandle.invoke(var);


          Activity

          Hide
          pardesha Pardeep Sharma added a comment -
          1. Run the attached test case (JavacBug.java) in Linux (64-bit) and Windows 7 (64-bit).

          2. Checked this for JDK 8, 8u11, 8u20, 8u25, 8u31, 8u45, 8u60 ea b21, and 9 ea b70.
          Result:
          -------------
          8: OK
          8u11: OK
          8u20: FAIL
          8u25: FAIL
          8u31: FAIL
          8u40: FAIL
          8u60 ea b21: FAIL
          9 ea b70: FAIL

          3. Output with JDK 8u45:
          ------------------------------------
          > javac JavacBug.java
          An exception has occurred in the compiler (1.8.0_45). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
          java.lang.AssertionError: typecode ERROR
                  at com.sun.tools.javac.jvm.Code.typecode(Code.java:252)
                  at com.sun.tools.javac.jvm.Items$Item.coerce(Items.java:269)
                  at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:951)
                  at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:968)
                  at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1909)
                  at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
                  at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:949)
                  at com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1846)
                  at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)
                  at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:739)
                  at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:774)
                  at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:760)
                  at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:811)
                  at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1160)
                  at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
                  at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:739)
                  at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:774)
          ............................
          .............................

          4. Result:
          ---------------
          This is a regression from 8u20 and onwards. The code compile fine with JDK 8 to 8u11 and threw exception with JDK 8u20 and onwards including JDK 9 ea. Moving this up for further evaluation.
          Show
          pardesha Pardeep Sharma added a comment - 1. Run the attached test case (JavacBug.java) in Linux (64-bit) and Windows 7 (64-bit). 2. Checked this for JDK 8, 8u11, 8u20, 8u25, 8u31, 8u45, 8u60 ea b21, and 9 ea b70. Result: ------------- 8: OK 8u11: OK 8u20: FAIL 8u25: FAIL 8u31: FAIL 8u40: FAIL 8u60 ea b21: FAIL 9 ea b70: FAIL 3. Output with JDK 8u45: ------------------------------------ > javac JavacBug.java An exception has occurred in the compiler (1.8.0_45). Please file a bug at the Java Developer Connection ( http://java.sun.com/webapps/bugreport ) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you. java.lang.AssertionError: typecode ERROR         at com.sun.tools.javac.jvm.Code.typecode(Code.java:252)         at com.sun.tools.javac.jvm.Items$Item.coerce(Items.java:269)         at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:951)         at com.sun.tools.javac.jvm.Gen.genArgs(Gen.java:968)         at com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1909)         at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)         at com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:949)         at com.sun.tools.javac.jvm.Gen.visitExec(Gen.java:1846)         at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1296)         at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:739)         at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:774)         at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:760)         at com.sun.tools.javac.jvm.Gen.genStats(Gen.java:811)         at com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1160)         at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)         at com.sun.tools.javac.jvm.Gen.genDef(Gen.java:739)         at com.sun.tools.javac.jvm.Gen.genStat(Gen.java:774) ............................ ............................. 4. Result: --------------- This is a regression from 8u20 and onwards. The code compile fine with JDK 8 to 8u11 and threw exception with JDK 8u20 and onwards including JDK 9 ea. Moving this up for further evaluation.
          Hide
          sadayapalam Srikanth Adayapalam added a comment -
          Reproduced. I'll follow up.
          Show
          sadayapalam Srikanth Adayapalam added a comment - Reproduced. I'll follow up.
          Hide
          sadayapalam Srikanth Adayapalam added a comment -
          Problems stems from caching non-kosher methods in com.sun.tools.javac.comp.Resolve#findPolymorphicSignatureInstance.
          There is a first lookup before the implicit lambda parameter's eventual type is known which results an erroneous method type which
          gets and cached and picked up subsequently since the types.isSameType call glosses over error types.

          Show
          sadayapalam Srikanth Adayapalam added a comment - Problems stems from caching non-kosher methods in com.sun.tools.javac.comp.Resolve#findPolymorphicSignatureInstance. There is a first lookup before the implicit lambda parameter's eventual type is known which results an erroneous method type which gets and cached and picked up subsequently since the types.isSameType call glosses over error types.
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/21b0862fdd32
          User: sadayapalam
          Date: 2015-10-07 10:23:52 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/21b0862fdd32 User: sadayapalam Date: 2015-10-07 10:23:52 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/langtools/rev/21b0862fdd32
          User: lana
          Date: 2015-10-14 21:52:02 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/langtools/rev/21b0862fdd32 User: lana Date: 2015-10-14 21:52:02 +0000

            People

            • Assignee:
              sadayapalam Srikanth Adayapalam
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: