Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6408241
Votes 0
Synopsis Elements.getTypeElement(String s) does not return null for non-existing classes
Category java:classes_annot_processing
Reported Against b77
Release Fixed mustang(b85)
State 10-Fix Delivered, Verified, bug
Priority: 3-Medium
Related Bugs 6346506 , 6375016
Submit Date 04-APR-2006
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)
Posted Date : 2006-04-04 12:48:23.0
Work Around
N/A
Evaluation
The bogus TypeElement that's returned is a time bomb.  Call getKind on that
element and the processor crashes.

Elements.getTypeElement calls ClassReader.enterClass, which does not
complete the resulting ClassSymbol before returning it.
Could fix by calling loadClass instead, which completes the symbol and
undoes the enter on failure.  Then catch the CompletionFailure and return
null as spec'ed.
Posted Date : 2006-04-26 05:08:45.0

Fixed as a result of the fix for 
6308351: Apt causes NullPointerException running on a Simplified Chinese testcase.

This CR will now be used as a vehicle for doing some additional
testing of this fix.
Posted Date : 2006-05-08 22:22:25.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang