-
Bug
-
Resolution: Fixed
-
P3
-
6
-
b78
-
generic
-
generic
-
Verified
I passed a non DECLARED kind to Types.directSupertypes(TypeMirror t) , and it returned a List of Types.
List contains one null element.
Expected a list with 0 elements or 'IllegalArgumentException'.
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) {
Vector<TypeMirror> listArrayElementList = new Vector<TypeMirror>();
for( TypeElement element : renv.getSpecifiedTypeElements()) {
List<? extends Element > list = element.getEnclosedElements();
for( Element e : list) {
listArrayElementList.add(e.asType());
}
listArrayElementList.add(element.asType());
}
System.out.println(" Identified TypeMirror count "+listArrayElementList.size());
for(TypeMirror mirror : listArrayElementList) {
System.out.println(" TypeKind("+mirror.toString()+") = "+mirror.getKind());
List <? extends TypeMirror> list = processingEnv.getTypeUtils().directSupertypes(mirror);
System.out.println(" size(types.directSupertypes("+mirror.toString()+")) = "+list.size());
for(TypeMirror tm : list) {
if ( tm != null ) {
System.out.println(" ->> superType("+mirror.toString()+") = "+tm.toString());
} else {
System.out.println(" **-->>got a null superType for "+mirror.toString());
}
}
}
return true ;
}
}
bash-3.00$ cat Case1.java
public class Case1 {
private int i;
private Float flt;
public void doMethod2_1(String message){
System.out.println(" message "+message);
}
}
bash-3.00$ $JAVA_HOME/bin/javac -classpath $CLASSPATH -processor CaseAP Case1.java
bash-3.00$ ksh compile.sh
Identified TypeMirror count 5
TypeKind(()void) = EXECUTABLE
size(types.directSupertypes(()void)) = 1
**-->>got a null superType for ()void
TypeKind(int) = INT
size(types.directSupertypes(int)) = 1
**-->>got a null superType for int
TypeKind(java.lang.Float) = DECLARED
size(types.directSupertypes(java.lang.Float)) = 2
->> superType(java.lang.Float) = java.lang.Number
->> superType(java.lang.Float) = java.lang.Comparable<java.lang.Float>
TypeKind((java.lang.String)void) = EXECUTABLE
size(types.directSupertypes((java.lang.String)void)) = 1
**-->>got a null superType for (java.lang.String)void
TypeKind(Case1) = DECLARED
size(types.directSupertypes(Case1)) = 1
->> superType(Case1) = java.lang.Object
Identified TypeMirror count 0
bash-3.00$ $JAVA_HOME/bin/java -version
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)
List contains one null element.
Expected a list with 0 elements or 'IllegalArgumentException'.
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) {
Vector<TypeMirror> listArrayElementList = new Vector<TypeMirror>();
for( TypeElement element : renv.getSpecifiedTypeElements()) {
List<? extends Element > list = element.getEnclosedElements();
for( Element e : list) {
listArrayElementList.add(e.asType());
}
listArrayElementList.add(element.asType());
}
System.out.println(" Identified TypeMirror count "+listArrayElementList.size());
for(TypeMirror mirror : listArrayElementList) {
System.out.println(" TypeKind("+mirror.toString()+") = "+mirror.getKind());
List <? extends TypeMirror> list = processingEnv.getTypeUtils().directSupertypes(mirror);
System.out.println(" size(types.directSupertypes("+mirror.toString()+")) = "+list.size());
for(TypeMirror tm : list) {
if ( tm != null ) {
System.out.println(" ->> superType("+mirror.toString()+") = "+tm.toString());
} else {
System.out.println(" **-->>got a null superType for "+mirror.toString());
}
}
}
return true ;
}
}
bash-3.00$ cat Case1.java
public class Case1 {
private int i;
private Float flt;
public void doMethod2_1(String message){
System.out.println(" message "+message);
}
}
bash-3.00$ $JAVA_HOME/bin/javac -classpath $CLASSPATH -processor CaseAP Case1.java
bash-3.00$ ksh compile.sh
Identified TypeMirror count 5
TypeKind(()void) = EXECUTABLE
size(types.directSupertypes(()void)) = 1
**-->>got a null superType for ()void
TypeKind(int) = INT
size(types.directSupertypes(int)) = 1
**-->>got a null superType for int
TypeKind(java.lang.Float) = DECLARED
size(types.directSupertypes(java.lang.Float)) = 2
->> superType(java.lang.Float) = java.lang.Number
->> superType(java.lang.Float) = java.lang.Comparable<java.lang.Float>
TypeKind((java.lang.String)void) = EXECUTABLE
size(types.directSupertypes((java.lang.String)void)) = 1
**-->>got a null superType for (java.lang.String)void
TypeKind(Case1) = DECLARED
size(types.directSupertypes(Case1)) = 1
->> superType(Case1) = java.lang.Object
Identified TypeMirror count 0
bash-3.00$ $JAVA_HOME/bin/java -version
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)
- relates to
-
JDK-6396321 Supertype should never be null, and there should be no infinite supertype chains
- Closed