-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b85
-
generic
-
generic
-
Verified
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)
----
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)
- relates to
-
JDK-6375016 Elements.getTypeElement() sometimes returns null.
- Resolved
-
JDK-6346506 jsr 269 Elements.getTypeElement(String s) will throw NPE for a unknown class.
- Closed