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

Improve handling of direct use of accept with TreePathScanner

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b140
    • Verification:
      Not verified

      Description

      Run following code to reproduce
      {code}
      import com.sun.source.util.TreePathScanner;
      import com.sun.tools.javac.api.JavacTaskImpl;

      import java.io.*;
      import javax.tools.*;


      public class Sample {
          static final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
          static final StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

          public static void main(String[] args) throws IOException {
              File javaFile = new File("Sample.java");
              JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null, null, null, fm.getJavaFileObjects(javaFile));
              ct.parse().iterator().next().accept(new TreePathScanner<>(), 1);
          }
      }
      {code}

      StackTrace:
      Exception in thread "main" java.lang.NullPointerException
      at com.sun.source.util.TreePath.<init>(TreePath.java:102)
      at com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:66)
      at com.sun.source.util.TreeScanner.scan(TreeScanner.java:91)
      at com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:99)
      at com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:118)
      at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:551)
      at Sample.main(Sample.java:15)

        Attachments

          Activity

            People

            Assignee:
            jjg Jonathan Gibbons
            Reporter:
            anazarov Andrey Nazarov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: