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

Javac fails with assertion error when lambda types are not specified

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u40, 8u45
    • tools
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      Reproduced on

      java version "1.8.0_25"
      Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

      java version "1.8.0_40"
      Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

      openjdk version "1.8.0_45-internal"
      OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
      OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7600]

      A DESCRIPTION OF THE PROBLEM :
      When compiling the supplied source file, Javac fails with assertion error

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the supplied CompilationBug.java file

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Successful compilation
      ACTUAL -
      Compiler crashes with AssertionError

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      An exception has occurred in the compiler (1.8.0_40). 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: attribution shouldn't be happening here
      at com.sun.tools.javac.util.Assert.error(Assert.java:133)
      at com.sun.tools.javac.util.Assert.check(Assert.java:94)
      at com.sun.tools.javac.comp.DeferredAttr$DeferredAttrNode.process(DeferredAttr.java:591)
      at com.sun.tools.javac.comp.DeferredAttr$DeferredAttrContext.complete(DeferredAttr.java:479)
      at com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:177)
      at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:567)
      at com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:604)
      at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3797)
      at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3584)
      at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3491)
      at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3470)
      at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3457)
      at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3339)
      at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
      at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1806)
      at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
      at com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:386)
      at com.sun.tools.javac.comp.DeferredAttr$2.complete(DeferredAttr.java:279)
      at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:245)
      at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:232)
      at com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:1003)
      at com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:829)
      at com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:734)
      at com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:838)
      at com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:162)
      at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:567)
      at com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1441)
      at com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1628)
      at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1699)
      at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1672)
      at com.sun.tools.javac.comp.Resolve$9.doLookup(Resolve.java:2425)
      at com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3084)
      at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3335)
      at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2422)
      at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2416)
      at com.sun.tools.javac.comp.Attr.selectSym(Attr.java:3364)
      at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3246)
      at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
      at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1806)
      at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
      at com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:1667)
      at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1384)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
      at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:635)
      at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:651)
      at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1105)
      at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
      at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:635)
      at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:994)
      at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566)
      at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:635)
      at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4330)
      at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4240)
      at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4169)
      at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4144)
      at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
      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 com.sun.tools.javac.Main.main(Main.java:42)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Optional;
      import java.util.stream.Stream;

      public class CompilationBug {
          static class Box<A> {
              A a;
              
              Box(A obj) {
                  this.a = obj;
              }

              static <A> Optional<A> asOptional(Box<A> box) {
                  return box == null ? Optional.empty() : Optional.of(box.a);
              }
          }

          public static <T> Optional<T> test(Stream<T> source) {
      return Box.asOptional(source.reduce(null,
      (Box<T> acc, T t) -> acc == null ? new Box<>(t) : acc,
      (acc1, acc2) -> acc1));
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Specify arguments types in line#20:

      (Box<T> acc1, Box<T> acc2) -> acc1));

      This way it compiles fine

            pardesha Pardeep Sharma
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: