JDK-5065057 : (reflect) Class.getEnclosingMethod unclear spec for local and anon class in ctor
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2004-06-18
  • Updated: 2012-09-28
  • Resolved: 2004-06-22
Related Reports
Relates :  
Relates :  
Description
This is the current specification of java.lang.Class.getEnclosingMethod():

     * If this <tt>Class</tt> object represents a local or anonymous
     * class within a method, returns a {@link
     * java.lang.reflect.Method Method} object representing the
     * immediately enclosing method of the underlying class. Returns
     * <tt>null</tt> otherwise.
     *
     * In particular, this method returns <tt>null</tt> if the underlying
     * class is a local or anonymous class immediately enclosed by a type
     * declaration, instance initializer or static initializer.
     *
     * @return the immediately enclosing method of the underlying class, if
     *     that class is a local or anonymous class; otherwise <tt>null</tt>.
     * @since 1.5
 
It is not clear what should happen if this class is a local or anonymous class defined within a constructor.  From the first paragraph one can assume that null will be returned, however, that second paragraph does not mention this case.

Currently, the method will throw InternalError("Enclosing method not found").

###@###.### 2004-06-17

Comments
EVALUATION We should clarify the documentation. ###@###.### 2004-06-18 I have no objection to emphasizing that a constructor is not a method, say by adding "constructor, " before "type declaration". However it is not strictly necessary. ###@###.### 2004-06-21
21-06-2004