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

java.lang.NullPointerException when visiting ForeachLoop

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 7, 7u21
    • tools
    • None

      FULL PRODUCT VERSION :
      javac 1.7.0_21

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The compiler throws a NullPointerException during code generation.

      This seems to happen when there is a try(){} statement nested in a foreach-loop without using braces.

      The work-around is using braces.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac Bug.java # Bug.java is included in this report


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      An exception has occurred in the compiler (1.7.0_21). 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.tree.TreeInfo.endPos(TreeInfo.java:248)
              at com.sun.tools.javac.comp.Lower.visitIterableForeachLoop(Lower.java:3285)
              at com.sun.tools.javac.comp.Lower.visitForeachLoop(Lower.java:3141)
              at com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:907)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:70)
              at com.sun.tools.javac.tree.TreeTranslator.visitBlock(TreeTranslator.java:160)
              at com.sun.tools.javac.comp.Lower.visitBlock(Lower.java:3319)
              at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:781)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)
              at com.sun.tools.javac.tree.TreeTranslator.visitMethodDef(TreeTranslator.java:144)
              at com.sun.tools.javac.comp.Lower.visitMethodDefInternal(Lower.java:2627)
              at com.sun.tools.javac.comp.Lower.visitMethodDef(Lower.java:2546)
              at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:669)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)
              at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:2291)
              at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:591)
              at com.sun.tools.javac.tree.TreeTranslator.translate(TreeTranslator.java:58)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2160)
              at com.sun.tools.javac.comp.Lower.translate(Lower.java:2180)
              at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:3659)
              at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1395)
              at com.sun.tools.javac.main.JavaCompiler.desugar(JavaCompiler.java:1273)
              at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:870)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:829)
              at com.sun.tools.javac.main.Main.compile(Main.java:439)
              at com.sun.tools.javac.main.Main.compile(Main.java:353)
              at com.sun.tools.javac.main.Main.compile(Main.java:342)
              at com.sun.tools.javac.main.Main.compile(Main.java:333)
              at com.sun.tools.javac.Main.compile(Main.java:76)
              at com.sun.tools.javac.Main.main(Main.java:61)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Bug {
      public void f () throws Exception {
      for (Object inputFile: (Iterable<?>) null)
      try (AutoCloseable ac = (AutoCloseable) null) {
      }
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      public class Bug {
      public void f () throws Exception {
      for (Object inputFile: (Iterable<?>) null) {
      try (AutoCloseable ac = (AutoCloseable) null) {
      }

      }
      }

            darcy Joe Darcy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: