-
Bug
-
Resolution: Fixed
-
P4
-
1.2.0
-
kestrel
-
generic, sparc
-
generic, solaris_2.5.1, solaris_2.6
Name: laC46010 Date: 11/05/98
If an interface contains <clinit> method then Class.getMethods()
returns it along with other public methods although <clinit>
is not public.
In the Java Platform 1.2 API Specification reads:
"public Method[] getMethods()throws SecurityException
Returns an array containing Method objects reflecting all the public
member methods of the class or interface represented by this Class
object, including those declared by the class or interface and and
those inherited from superclasses and superinterfaces."
This bug is reproduced under all JDK versions from jdk1.1 to jdk1.2fcsP
The example below produces the following output.
-----------------output------------------
static <clinit>
---------------Test.java-----------------
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
interface TestedInterface {
String s = System.getProperty("Test");
}
public class Test {
public static void main(String args[]) {
try {
Class c = Class.forName("TestedInterface");
Method meth[] = c.getMethods();
for (int i = 0; i < meth.length; i++)
System.out.println(Modifier.toString(meth[i].getModifiers()) +
" " + meth[i].getName());
} catch (Throwable t) {
t.printStackTrace();
}
}
}
======================================================================
- duplicates
-
JDK-4192217 (reflection) Class.getMethods() allows access to <clinit> of interfaces
- Closed