Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2176949 | 7 | Karen Kinnear | P3 | Closed | Fixed | b14 |
JDK-2171939 | 6u4 | Karen Kinnear | P3 | Closed | Fixed | b03 |
JDK-2152960 | OpenJDK6 | Karen Kinnear | P3 | Closed | Not an Issue |
Consider the following interface and implementor classes:
public interface Intf {
// public void method1();
}
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
public class SubClass implements Intf {
public static void main(String[] args) {
SubClass sc = new SubClass();
Class paramClasses[] = new Class[]{};
for (int i = 0; i < 20; i++) {
try{
System.out.println("Try: " + i);
Method method1 = sc.getClass().getMethod("method1",paramClasses);
method1.invoke(sc);
} catch(NoSuchMethodException nme){
nme.printStackTrace();
} catch(AbstractMethodError ame){
ame.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
Steps to reproduce the issue:
1) Compiled both the classes
2) Uncomment method1() in Intf.java
3) recompile only Intf.java
We get incompatible class set. Now, run
java Subclass
You get AbstractMethodError for the first 15 iterations and then get InvocationTargetException that wraps AbstractMethodError. Actually, AbstractMethodError is expected always -- because "method1()" is not implemented in "SubClass" and therefore the linkage should fail always. Throwing InvocationTargetException seem to suggest that the method was called and resulted in some exception being thrown.
public interface Intf {
// public void method1();
}
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
public class SubClass implements Intf {
public static void main(String[] args) {
SubClass sc = new SubClass();
Class paramClasses[] = new Class[]{};
for (int i = 0; i < 20; i++) {
try{
System.out.println("Try: " + i);
Method method1 = sc.getClass().getMethod("method1",paramClasses);
method1.invoke(sc);
} catch(NoSuchMethodException nme){
nme.printStackTrace();
} catch(AbstractMethodError ame){
ame.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
Steps to reproduce the issue:
1) Compiled both the classes
2) Uncomment method1() in Intf.java
3) recompile only Intf.java
We get incompatible class set. Now, run
java Subclass
You get AbstractMethodError for the first 15 iterations and then get InvocationTargetException that wraps AbstractMethodError. Actually, AbstractMethodError is expected always -- because "method1()" is not implemented in "SubClass" and therefore the linkage should fail always. Throwing InvocationTargetException seem to suggest that the method was called and resulted in some exception being thrown.
- backported by
-
JDK-2152960 Wrong exception from Method.invoke() call
- Closed
-
JDK-2171939 Wrong exception from Method.invoke() call
- Closed
-
JDK-2176949 Wrong exception from Method.invoke() call
- Closed
- relates to
-
JDK-4428861 java.lang.reflect.Method.invoke() throws incorrect exceptions
- Closed
-
JDK-6541507 (reflect spec) Method.invoke() @throws InvocationTargetException
- Closed
-
JDK-6519118 Classes are compiled but java.lang.AbstractMethodError is thrown at runtime
- Closed
(1 relates to)