-
Bug
-
Resolution: Fixed
-
P3
-
1.4.2, 5.0, 6, 7, 8
-
b120
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8030320 | 8u5 | Joel Borggrén-Franck | P3 | Resolved | Fixed | b01 |
Since at least jdk4 getMethod(name) and getMethods() called on an interface class does not find/return object methods that are not overridden in a super interface.
---
$ cat TT.java
import java.lang.reflect.*;
public class TT {
public static void main(String[] args) throws Exception {
System.out.println(TT.class.getMethod("equals", new Class[] {Object.class}));
System.out.println(I.class.getMethod("equals", new Class[] {Object.class}));
}
}
interface I {}
$ /localhome/hotspots/old/j2sdk1.4.2/bin/java TT
public boolean java.lang.Object.equals(java.lang.Object)
Exception in thread "main" java.lang.NoSuchMethodException: I.equals(java.lang.Object)
at java.lang.Class.getMethod(Class.java:978)
at TT.main(TT.java:5
---
$ cat T.java
import java.lang.reflect.*;
public class T {
public static void main(String[] args) {
Method[] ms = I.class.getMethods();
for (int i = 0; i < ms.length; i++)
System.out.println(ms[i]);
}
}
interface I {}
$ /localhome/hotspots/old/j2sdk1.4.2/bin/java T
$
The javadoc for these methods should be updated to match the longstanding behavior.
---
$ cat TT.java
import java.lang.reflect.*;
public class TT {
public static void main(String[] args) throws Exception {
System.out.println(TT.class.getMethod("equals", new Class[] {Object.class}));
System.out.println(I.class.getMethod("equals", new Class[] {Object.class}));
}
}
interface I {}
$ /localhome/hotspots/old/j2sdk1.4.2/bin/java TT
public boolean java.lang.Object.equals(java.lang.Object)
Exception in thread "main" java.lang.NoSuchMethodException: I.equals(java.lang.Object)
at java.lang.Class.getMethod(Class.java:978)
at TT.main(TT.java:5
---
$ cat T.java
import java.lang.reflect.*;
public class T {
public static void main(String[] args) {
Method[] ms = I.class.getMethods();
for (int i = 0; i < ms.length; i++)
System.out.println(ms[i]);
}
}
interface I {}
$ /localhome/hotspots/old/j2sdk1.4.2/bin/java T
$
The javadoc for these methods should be updated to match the longstanding behavior.
- backported by
-
JDK-8030320 (reflect) clarify javadoc for getMethod(...) and getMethods()
-
- Resolved
-