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

Elements.getTypeElement(String s) does not return null for non-existing classes

    Details

      Description

      The specification for this method says:
      ----
      TypeElement getTypeElement(String name)

          Returns a type element given its fully qualified name.

          Parameters:
              name - fully qualified type name
          Returns:
              the named type element, or *null if it cannot be found*
      ----

      However null is never returned in cases when non-existing type names are passed.
      Here is an example from 6346506:
      ----
      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) {
              Elements elementUtils = processingEnv.getElementUtils();
              TypeElement case2 = elementUtils.getTypeElement("non.existing.Class");
      // Case2 class doesn;t exisit in classpath to construct a Element.
              if ( case2 != null ) {
                  System.out.println(" element received as "+case2.toString());
              }
              return true ;
          }
      }
      ----

      $JAVA_HOME/bin/javac -classpath $CLASSPATH -processor CaseAP Case1.java
       element received as non.existing.Class
       element received as non.existing.Class

      Java(TM) SE Runtime Environment (build 1.6.0-beta2-b77)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sseligmasunw Scott Seligman (Inactive)
                Reporter:
                ashusher Alexander Shusherov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: