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

java.lang.reflect.Method.invoke() throws incorrect exceptions

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      generic, x86, sparc
    • OS:
      generic, linux, solaris_2.6, solaris_7, solaris_8, windows_95, windows_2000
    • Verification:
      Verified

      Description



      Name: vrR10176 Date: 03/22/2001



      Api spec says about method invoke (java.lang.reflect.Method):

      "public Object invoke(Object obj, Object[] args)
                     throws IllegalAccessException,
                            IllegalArgumentException,
                            InvocationTargetException
      ... skip ...
      Control transfers to the invoked method. If the method completes
      abruptly by throwing an exception, the exception is placed in an
      InvocationTargetException and thrown in turn to the caller of invoke.
      ... skip ...
      Throws:
      InvocationTargetException - if the underlying method throws an exception.
      ... skip ..."

      And JVMS-2 says (chapter 2.16, Exceptions, p.40):
      "Every exception is represented by an instance of the class Throwable
      or one of its subclasses"

      Therefore, if the method completes abruptly by throwing LinkageError
      (for example NoSuchFieldError), this error should be placed in an
      InvocationTargetException and thrown in turn to the caller of invoke,
      as this error is exception and subclass of Throwable. But JVM
      (jdk1.4.0beta-b54,b55,b56) does not place LinkageError to
      InvocationTargetException and throws it immediately. This is jdk
      regression, all previous jdk throws InvocationTargetException
      instead of LinkageError.

      The bug affects a lot of jck vm tests.

      To reproduce the issue execute following test.
      Compile first test.java and then test2.java
      ------------ test.java ------------------------
      package invoke_test;

      import java.lang.reflect.*;

      abstract class testA{
      static int f;
      }

      class test1 extends testA{
      static void run(){
      f = 2;
      }
      }

      public class test {
      public static void main(String args[]) {
      try {
      Class test_class = Class.forName("invoke_test.test1");
      Method runMethod = test_class.getDeclaredMethod("run", new Class[]{});
      Object ignore = runMethod.invoke(null, new Object[]{});
      } catch (InvocationTargetException e) {
      Throwable ee = e.getTargetException();
      System.out.println("Exception " + e + " wraps: " + ee);
      System.out.println("Test passed");
      } catch (Throwable e) {
      System.out.println("Failed with unexpected exception: " + e);
      }
      }
      }
      ------------ test2.java ------------------------
      package invoke_test;

      abstract class testA{
      }
      ------------ Logs -----------------------------

      $ javac -d . test.java

      $ javac -d . test2.java

      $ java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b56)
      Java HotSpot(TM) Client VM (build 1.4-beta-B56, mixed mode)

      $ java -Xfuture invoke_test.test
      Failed with unexpected exception: java.lang.NoSuchFieldError: f

      ------------ Logs , some previous jdks----------
      ----jdk1.4.0beta-b53----
      $ java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b53)
      Java HotSpot(TM) Client VM (build 1.4beta-B53, mixed mode)

      $ java -Xfuture invoke_test.test
      Exception java.lang.reflect.InvocationTargetException wraps: java.lang.NoSuchFieldError: f
      Test passed

      ----jdk1.3.0fcsC----
      $ java -version
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)

      $java -Xfuture invoke_test.test
      Exception java.lang.reflect.InvocationTargetException wraps: java.lang.NoSuchFieldError: f
      Test passed

      ----jdk1.2fcsV----
      $ java -version
      java version "1.2"
      Classic VM (build JDK-1.2-V, green threads, sunwjit)

      $ java -Xfuture invoke_test.test
      Exception java.lang.reflect.InvocationTargetException wraps: java.lang.NoSuchFieldError: invoke_test.testA: field f not found
      Test passed

      -----------------------------------------------

      ======================================================================

      Name: dkR10014 Date: 04/03/2001


      This bug affects the following test from testbase_nsk:

         nsk/stress/except/except001

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kbr Kenneth Russell (Inactive)
              Reporter:
              rslasunw Rsla Rsla (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: