JDK-6391649 : javax.lang.model.util.Elements.getAllMembers() does not return initializers
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.annotation.processing
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-02-28
  • Updated: 2017-05-16
  • Resolved: 2006-04-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b79Fixed
Related Reports
Relates :  
Relates :  
Description
The spec for method javax.lang.model.util.Elements.getAllMembers() says:
...
Returns all members of a type element, whether inherited or declared directly. For a class the result also includes its constructors and *initializers*, but not local or anonymous classes.
...

But, in fact, getAllMembers() does not return initializers. For example, the following TestProc processor does not print out initializers defined in Source.

-- 
public class Source {
     static {}
     {}
}
-- 
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.Element;
import java.util.Set;

@SupportedAnnotationTypes("*")
public class TestProc extends AbstractProcessor {
     public boolean process(Set<? extends TypeElement> set, RoundEnvironment re) {
         if(re.processingOver()) return true;

         TypeElement te =
                 re.getSpecifiedTypeElements().toArray(new TypeElement[0])[0];
         for(Element e: processingEnv.getElementUtils().getAllMembers(te)) {
             System.out.println("e: " + e + " " + e.getKind());
         }
         return true;
     }
}
-- 

The result is something like the following (there are no any initializers):
e: getClass() METHOD
e: hashCode() METHOD
e: equals(java.lang.Object) METHOD
e: clone() METHOD
e: toString() METHOD
e: notify() METHOD
e: notifyAll() METHOD
e: wait(long) METHOD
e: wait(long,int) METHOD
e: wait() METHOD
e: finalize() METHOD
e: Source() CONSTRUCTOR 

It looks like the implementation does not comply to spec.

Comments
SUGGESTED FIX src/share/classes/javax/lang/model/util>sccs sccsdiff -r1.4 -r1.5 Elements.java ------- Elements.java ------- 76,78c76,78 < * Returns all members of a type element, whether inherited or declared < * directly. For a class the result also includes its constructors < * and initializers, but not local or anonymous classes. --- > * Returns all members of a type element, whether inherited or > * declared directly. For a class the result also includes its > * constructors, but not local or anonymous classes.
28-03-2006

EVALUATION Specification and implementation should agree before GA.
28-02-2006