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

Compiler dies with NullPointerException with stream and lambda on initializing static final field

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      javac 1.8.0_131
      and
      javac 1.8.0_102

      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.13.0-116-generic #163-Ubuntu SMP Fri Mar 31 14:13:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Complie the class Bugcode.java with javac, and compiler dies with NullPointerException.
      Bugcode.java is pasted on test case field.

      ADDITIONAL REGRESSION INFORMATION:
      Tested on Java

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run 'javac Bugcode.java'
      Reproduced on javac 1.8.0_131 and javac 1.8.0_102

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compile succeeds without exception.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      $ LANG=EN_US ./javac ~/Bugcode.java
      An exception has occurred in the compiler (1.8.0_131). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.AssertionError: java.lang.NullPointerException
      at com.sun.tools.javac.code.Symbol$VarSymbol.getConstValue(Symbol.java:1284)
      at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1058)
      at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
      at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4364)
      at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4272)
      at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4201)
      at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4176)
      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)
      Caused by: java.lang.NullPointerException
      at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1048)
      at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:645)
      at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:661)
      at com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2316)
      at com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1624)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:387)
      at com.sun.tools.javac.comp.DeferredAttr$2.complete(DeferredAttr.java:280)
      at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:246)
      at com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:233)
      at com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:1008)
      at com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:835)
      at com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:735)
      at com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:844)
      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:1446)
      at com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1633)
      at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1704)
      at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1677)
      at com.sun.tools.javac.comp.Resolve$9.doLookup(Resolve.java:2436)
      at com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3097)
      at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3348)
      at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2433)
      at com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2427)
      at com.sun.tools.javac.comp.Attr.selectSym(Attr.java:3396)
      at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3278)
      at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1825)
      at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3250)
      at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1825)
      at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3250)
      at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1825)
      at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:625)
      at com.sun.tools.javac.comp.Attr.visitBinary(Attr.java:3057)
      at com.sun.tools.javac.tree.JCTree$JCBinary.accept(JCTree.java:1785)
      at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:576)
      at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:618)
      at com.sun.tools.javac.comp.Attr.attribLazyConstantValue(Attr.java:760)
      at com.sun.tools.javac.code.Symbol$VarSymbol$2.call(Symbol.java:1250)
      at com.sun.tools.javac.code.Symbol$VarSymbol.getConstValue(Symbol.java:1282)
      ... 17 more

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.List;
      import java.util.ArrayList;
      import java.util.stream.Collectors;

      public class Bugcode {
          private static final List<String> LIST_OF_STRING = new ArrayList();
          private static final String JAVA8_131KILLER =
                  "this string is necessary" +
              LIST_OF_STRING.stream().map((String s) -> s).collect(Collectors.toList()).toString();

          public String avoidDeadcodeElimination() {
              return JAVA8_131KILLER;
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Substitute stream with Lists.transform from com.google.common.collect libraries for meanwhile.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                fmatte Fairoz Matte
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: