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

jsr 269 getDeclaredType(TypeElement, TypeMirror) throws NPE.

XMLWordPrintable

      The element Case2 was passed to javac, Element.getTypeElement(String ), can get TypeElement and it could pass next layer,
      It was tried to compile and fails as Case2.java was not passed in , but Case2.java exisit in the current directory.


      NullPointerException Trace::
      ----------------------------
      bash-3.00$ ksh compile.sh
       TypeElement = Case2


      An annotation processor threw an uncaught exception.
      Consult the following stack trace for details.
      java.lang.NullPointerException
              at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:429)
              at com.sun.tools.javac.main.JavaCompiler.complete(JavaCompiler.java:572)
              at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:1534)
              at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1471)
              at com.sun.tools.javac.code.Symbol.complete(Symbol.java:370)
              at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:740)
              at com.sun.tools.javac.code.Type$ClassType.complete(Type.java:681)
              at com.sun.tools.javac.code.Type$ClassType.getTypeArguments(Type.java:619)
              at com.sun.tools.javac.model.JavacTypes.getDeclaredType0(JavacTypes.java:210)
              at com.sun.tools.javac.model.JavacTypes.getDeclaredType(JavacTypes.java:187)
              at CaseAP.process(CaseAP.java:26)
              at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:497)
              at com.sun.tools.javac.processing.JavacProcessingEnvironment.discovery(JavacProcessingEnvironment.java:421)
              at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:569)
              at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:843)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:629)
              at com.sun.tools.javac.main.Main.compile(Main.java:756)
              at com.sun.tools.javac.main.Main.compile(Main.java:681)
              at com.sun.tools.javac.main.Main.compile(Main.java:670)
              at com.sun.tools.javac.Main.compile(Main.java:70)
              at com.sun.tools.javac.Main.main(Main.java:55)
      java version "1.6.0-auto"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-auto-292b)
      Java HotSpot(TM) Server VM (build 1.6.0-ea-b56, mixed mode)

      Code ::
      -------
      bash-3.00$ cat CaseAP.java
      import java.util.*;
      import javax.annotation.processing.*;
      import javax.lang.model.element.*;
      import javax.lang.model.type.*;
      import javax.lang.model.util.*;
      import static javax.lang.model.SourceVersion.*;
      import static javax.lang.model.type.TypeKind.*;

      @SupportedAnnotationTypes("*")
      @SupportedSourceVersion(RELEASE_6)
      @SupportedOptions("-verbose")
      public class CaseAP extends AbstractProcessor {
          public void init(ProcessingEnvironment penv) {
              super.init(penv);
          }
          public boolean process(Set<? extends TypeElement> typeElementSet,
                  RoundEnvironment renv) {
              TypeElement typeElement =processingEnv.getElementUtils().getTypeElement("Case2");
              if ( typeElement == null ) {
                  System.out.println(" TypeElement got is null ");
                  return true;
              }else {
                  System.out.println(" TypeElement = "+typeElement.toString());
              }
              TypeMirror type =processingEnv.getElementUtils().getTypeElement("java.lang.String").asType();
              DeclaredType dtype = processingEnv.getTypeUtils().getDeclaredType(typeElement, type);
              System.out.println(" "+dtype);
              return true ;
          }
      }
      bash-3.00$ cat Case1.java
      public class Case1<T>{
          T myT;
          public T getT() {
              return myT;
          }
          Void myVoid;
      }
      bash-3.00$
      How to reproduce.
      ----------------
      PROCESSOR=CaseAP
      $JAVA_HOME/bin/javac -d . -classpath $CLASSPATH $PROCESSOR.java
      $JAVA_HOME/bin/javac -classpath $CLASSPATH -processor $PROCESSOR Case1.java
      $JAVA_HOME/bin/java -version

            sseligmasunw Scott Seligman (Inactive)
            vvegurusunw Viswadeep Veguru (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: