Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6531596

Wrong exception from Method.invoke() call

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: hs10
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b14
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        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.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  acorn Karen Kinnear (Inactive)
                  Reporter:
                  sundar Sundararajan Athijegannathan
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: