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

NullPointerException thrown when retrieving bounds for the type parameter

XMLWordPrintable

    • generic
    • generic

      Processing the following source:

      -----
      package tmp;

      import java.util.*;

      public class S_GETBOUNDS<TP1 extends ArrayList & Set> {
      }
      -----


        and retrieving the bounds for TP1 in the following way:


      ----
              // inside the "process" method of the processor

              elements = processingEnv.getElementUtils();
              TypeElement element = elements.getTypeElement("tmp.S_GETBOUNDS");
              List<TypeParameterElement> ltpe = (List<TypeParameterElement>)element.getTypeParameters();
              TypeParameterElement tpe = ltpe.get(0);
              List<TypeMirror> bounds = (List<TypeMirror>)tpe.getBounds(); // (1)
      ----


        the NullPointerException is thrown at (.) 1:


      -----
      java.lang.NullPointerException
              at com.sun.tools.javac.code.Symbol$TypeSymbol.getBounds(Symbol.java:550)
              at com.sun.tools.javac.code.Symbol$TypeSymbol.getBounds(Symbol.java:467)
              at javasoft.sqe.tests.api.javax.lang.model.element.TypeElement.GETBOUNDS.test(GETBOUNDS.java:38)
              at javasoft.sqe.jck.lib.javax.annotation.processing.ProcessorTest.process(ProcessorTest.java:50)
              at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:628)
              at com.sun.tools.javac.processing.JavacProcessingEnvironment.discovery(JavacProcessingEnvironment.java:559)
              at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:698)
              at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:866)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:636)
              at com.sun.tools.javac.main.Main.compile(Main.java:332)
              at com.sun.tools.javac.main.Main.compile(Main.java:255)
              at com.sun.tools.javac.main.Main.compile(Main.java:246)
              at com.sun.tools.javac.Main.compile(Main.java:70)
              at com.sun.tools.javac.Main.main(Main.java:55)
      -----


        If the "& Set" part is removed from source - things go the expected way.

            ahe Peter Ahe
            ashusher Alexander Shusherov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: