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

javac fails with an exception when processing broken lambda

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 23
    • 23
    • tools
    • None
    • b26

      Consider this code:
      ---
      import java.util.List;

      public class Dummy {

          private void main() {
              List<String> l = null;
              l.stream().map(a -> {
                  l.stream().map(a -> {
                      return null;
                  });
              });
          }
      }
      ---

      Compiling this leads to:
      ---
      $ javac -XDdev /tmp/Dummy.java
      /tmp/Dummy.java:7: error: method map in interface Stream<T> cannot be applied to given types;
              l.stream().map(a -> {
                        ^
        required: Function<? super String,? extends R>
        found: (a)->{ l.s[...]}); }
        reason: cannot infer type-variable(s) R
          (argument mismatch; bad return type in lambda expression
            missing return value)
        where R,T are type-variables:
          R extends Object declared in method <R>map(Function<? super T,? extends R>)
          T extends Object declared in interface Stream
      1 error
      An exception has occurred in the compiler (23-internal). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://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.NullPointerException: Cannot invoke "com.sun.tools.javac.tree.JCTree.accept(com.sun.tools.javac.tree.JCTree$Visitor)" because "tree" is null
              at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.attribArg(ArgumentAttr.java:198)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribArgs(Attr.java:756)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2613)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1857)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:708)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:2334)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1644)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:729)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:748)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:3208)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:2034)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredType.complete(DeferredAttr.java:316)
              at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:355)
              at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:339)
              at jdk.compiler/com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:1073)
              at jdk.compiler/com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:900)
              at jdk.compiler/com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:788)
              at jdk.compiler/com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:909)
              at jdk.compiler/com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:175)
              at jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:618)
              at jdk.compiler/com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:657)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:4920)
              at jdk.compiler/com.sun.tools.javac.comp.AttrRecover.doRecovery(AttrRecover.java:193)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:731)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:748)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1433)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1133)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:729)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1222)
              at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:957)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:729)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5605)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5493)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5317)
              at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:5256)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1358)
              at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:977)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
              at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
              at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:66)
              at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:52)
      printing javac parameters to: /tmp/javac.20240528_200458.args
      ---

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: