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

javac AssertionError when invoking MethodHandle.invoke with lambda parameter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8u20, 9
    • tools
    • b86
    • x86_64
    • linux_ubuntu
    • Verified

        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);


              sadayapalam Srikanth Adayapalam (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: