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

JSR269: The javac Null Pointer Exception when getDefaultValue() operates with methods

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 6
    • core-libs

      The getDefaultValue() method throws an un caught Null Pointer Exception when annotation processor operates against the methods. Pasted the lines from API specification:

      <paste>
      'javax.lang.model.element.ExecutableElement.getDefaultValue()' method
      " Returns the default value if this executable is an annotation type element. Returns 'null' if this method is not an annotation type element, or if it is an annotation type element with no default value. "
      </paste>

      Steps to reproduce:
      1 -> javac -cp /jdk/sol/392/jdk1.6.0/lib/tools.jar:. defaultValue.java
      2 -> javac -processor defaultValue -proc:only testclass.java

      <Error>

      An annotation processor threw an uncaught exception.
      Consult the following stack trace for details.
      java.lang.NullPointerException
      at defaultValue$testVisitor.visitType(defaultValue.java:30)
      at defaultValue$testVisitor.visitType(defaultValue.java:25)
      at com.sun.tools.javac.code.Symbol$ClassSymbol.accept(Symbol.java:806)
      at defaultValue.process(defaultValue.java:46)
      at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:499)
      at com.sun.tools.javac.processing.JavacProcessingEnvironment.discovery(JavacProcessingEnvironment.java:423)
      at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:572)
      at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:844)
      at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:629)
      at com.sun.tools.javac.main.Main.compile(Main.java:761)
      at com.sun.tools.javac.main.Main.compile(Main.java:686)
      at com.sun.tools.javac.main.Main.compile(Main.java:675)
      at com.sun.tools.javac.Main.compile(Main.java:70)
      at com.sun.tools.javac.Main.main(Main.java:55)
      </Error>

      <defaultValue>

      import javax.annotation.*;
      import javax.annotation.processing.*;
      import javax.lang.model.*;
      import javax.lang.model.element.*;
      import javax.lang.model.type.*;
      import javax.lang.model.util .*;
      import static javax.lang.model.util.ElementFilter.*;
      import java.util.*;
      import java.io.*;

      @SupportedAnnotationTypes({"*"})
      @SupportedOptions({"-verbose"})
      public class defaultValue extends AbstractProcessor {

          private ProcessingEnvironment penv;

          public void init(ProcessingEnvironment env) { this.penv = env; }

          static class testVisitor extends SimpleElementVisitor6<Boolean,Void> {
      public Boolean visitType(TypeElement te, Void v) {
      for(ExecutableElement exec : methodsIn(te.getEnclosedElements()) ) {
      System.out.println(exec.getDefaultValue().getValue());
      }
      return true;
      }//visitType
          }//testVisitor

      public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
      for (TypeElement typeEle : renv.getSpecifiedTypeElements()) {
         System.out.println("PROCESSING: " + typeEle.getQualifiedName());
                 typeEle.accept((new testVisitor()), null);
      }
      return true;
          }
      }

      </defaultvalue>

      <testclass>
      public class testclass {
      public int method2() {}
      }
      </testclass>

      Provided the defaultValue.java and testclass.java files as attachments.

            sseligmasunw Scott Seligman (Inactive)
            bkondepusunw Bala Kondepudi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: