JDK-6346983 : jsr269 Types.getDeclaredType(TypElement, TypeMirror ...) create's invalid DecalaredType.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.lang.model
  • Affected Version: 6
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2005-11-07
  • Updated: 2022-08-10
Related Reports
Relates :  
Relates :  
Description
This following example shows, how to create a invalid 'DeclaredType' instance.
Case1<java.lang.String,java.lang.String> is invalid as Case1<T extends List, T1 extends List> was declared.

I am not completely sure, what other complications can cause while using a invalid 'DeclaredType'.

bash-3.00$ ksh compile.sh
 element received as Case1
 declared type Case1<java.lang.String,java.lang.String>
 element received as Case1
 declared type Case1<java.lang.String,java.lang.String>
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)
bash-3.00$ cat Case1.java
import java.util.List;
public class Case1 <T extends List, T1 extends List> {
}
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) {
        Elements elementUtils = processingEnv.getElementUtils();
        Types types = processingEnv.getTypeUtils();
        TypeElement case2 = elementUtils.getTypeElement("Case1");
        TypeElement type = elementUtils.getTypeElement("java.lang.String");
        if ( case2 != null ) {
            System.out.println(" element received as "+case2.toString());
            DeclaredType  dt = types.getDeclaredType(case2, type.asType(), type.asType());
            System.out.println(" declared type "+dt.toString());
        }
        return true ;
    }
}
bash-3.00$

Comments
EVALUATION CR 6394614 requests that javac provide more comprehensive ways to validate newly generated types. Once that is done Types.getDeclaredType can do full validation. Until then, we can at least have Types.getDeclaredType do some simple validation which should catch a large number of the most obvious sorts of error conditions.
06-03-2006