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

NullPointerException in compiler with stream().reduce

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u31
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_31"
      Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      Attached NullPointerException occurs when trying to compile the attached class.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      $ javac Test.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No NPE and compiled class file
      ACTUAL -
      NPE and no compiled class file

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      An exception has occurred in the compiler (1.8.0_31). 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.NullPointerException
              at com.sun.tools.javac.code.Types.isConvertible(Types.java:290)
              at com.sun.tools.javac.comp.Check.assertConvertible(Check.java:922)
              at com.sun.tools.javac.comp.Check.checkMethod(Check.java:876)
              at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3838)
              at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3615)
              at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3522)
              at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3501)
              at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3488)
              at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3370)
              at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1843)
              at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:649)
              at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1093)
              at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
              at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
              at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
              at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
              at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1035)
              at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
              at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4342)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4252)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4181)
              at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4156)
              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.ArrayList;
      import java.util.List;
      import java.util.concurrent.atomic.AtomicInteger;

      public class Test {

          public static void main(String[] args) {
              // not my real initialization code, just for illustration purposes
              List<AtomicInteger> values = new ArrayList<>();
              for(int i = 0; i < 10; i++) {
                  values.add(new AtomicInteger());
              }

              // this is the problematic reduce
              int total = values
                      .parallelStream()
                      .reduce(0,
                              (currentValue, currentAtomic)
                                      -> currentValue + currentAtomic.get(),
                              (combiner1, combiner2) -> combiner1 + combiner2);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Pulling the declaration of the lambdas out of the method call seems to work fine as shown here: http://stackoverflow.com/questions/28827784/java-8-compiler-bug-with-stream-and-reduce/28827927#28827927

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: