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

null pointer exception on getDocComment call

XMLWordPrintable

    • apt
    • b43
    • generic
    • generic

      Code is listed below. Simple call to ClassDeclaration's getDocComment();

      /export/jdk150apt//bin/jar -cf testAPF.jar BasicAPFactory.class testAP$classVisitor.class testAP.class META-INF
      Exception caught in classVisitor.visistClassDeclaration calling getDocComment()
      java.lang.NullPointerException
              at com.sun.tools.apt.mirror.declaration.DeclarationImpl.getDocComment(DeclarationImpl.java:70)
              at testAP$classVisitor.visitClassDeclaration(BasicAPFactory.java:42)
              at com.sun.tools.apt.mirror.declaration.ClassDeclarationImpl.accept(ClassDeclarationImpl.java:66)
              at testAP.process(BasicAPFactory.java:55)
              at com.sun.mirror.util.CompositeAnnotationProcessor.process(CompositeAnnotationProcessor.java:51)
              at com.sun.tools.apt.comp.Apt.main(Apt.java:305)
              at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:416)
              at com.sun.tools.apt.main.Main.compile(Main.java:871)
              at com.sun.tools.apt.main.Main.compile(Main.java:753)
              at com.sun.tools.apt.Main.compile(Main.java:41)
              at com.sun.tools.apt.Main.main(Main.java:32)

      -----code---------
      import com.sun.mirror.apt.*;
      import com.sun.mirror.declaration.*;
      import com.sun.mirror.type.*;
      import com.sun.mirror.util.*;
      import java.util.Collection;
      import java.util.Set;

      public class BasicAPFactory implements AnnotationProcessorFactory
      {
          public Collection<String> supportedOptions() {
      return new java.util.HashSet<String>();
          }

          public Collection<String> supportedAnnotationTypes() {
      Collection<String> types = new java.util.HashSet<String>();
      types.add("*");
      return types;
          }

          public AnnotationProcessor getProcessorFor(Set<String> at,
      AnnotationProcessorEnvironment env)
         {
      return new testAP(env);
          }
      }

      class testAP implements AnnotationProcessor
      {
          private AnnotationProcessorEnvironment env;

          public testAP(AnnotationProcessorEnvironment env)
      {
      this.env = env;
          }

          static class classVisitor extends DeclarationScanner
      {
      public void visitClassDeclaration(ClassDeclaration d)
      {
      super.visitClassDeclaration(d);
      try{
      String comments = d.getDocComment();
      }
      catch(Throwable t) {
      System.out.println("Exception caught in classVisitor.visistClassDeclaration calling getDocComment()");
      t.printStackTrace();
      }

      }
          }

          public void process()
      {
              for (TypeDeclaration typedecl: env.getSpecifiedTypeDeclarations())
                  typedecl.accept(new classVisitor());
          }
      }

            sseligmasunw Scott Seligman (Inactive)
            ssides Steve Sides
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: