-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
5.0
-
generic
-
generic
Name: vrR10176 Date: 01/30/2004
The API spec (JDK1.5-b36) for method Class.getEnclosingMethod() says:
"public Method getEnclosingMethod()
If this Class object represents a local or anonymous class within a method,
returns a Method object representing the immediately enclosing method of
the underlying class. Returns null otherwise.
..."
But if this Class object represents a local or anonymous class within a method
the method getEnclosingMethod() returns null.
To reproduce the issue execute the following test.
------------ test.java -------------------------------
import java.lang.reflect.Method;
public class test {
public static void main(String argv[]) {
class Local {}
Class cl = (new Local()).getClass();
Method m = cl.getEnclosingMethod();
System.out.println("Enclosing method for local class: " + m);
m = (new Object () { Method getEncMthd(){return this.getClass().getEnclosingMethod();}}).getEncMthd();
System.out.println("Enclosing method for anonymous class: " + m);
}
}
------------ Logs ---------------------------------------------
$javac -d . test.java
$
$java -version
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b36)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b36, mixed mode)
$
$java test
Enclosing method for local class: null
Enclosing method for anonymous class: null
$
$
-------------------------------------------------------------------
New jck1.5-beta2 tests failed due to this bug:
api/java_lang/Class/index.html#GetEnclosingMethod[getEnclosingMethod003]
api/java_lang/Class/index.html#GetEnclosingMethod[getEnclosingMethod004]
======================================================================
- duplicates
-
JDK-4962341 (reflect) Properly implement Class.getEnclosingMethod
- Resolved
- relates to
-
JDK-4971742 HotSpot must preserve EnclosingMethod attribute
- Closed