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

IllegalArgumentException: while calling a method using reflection

XMLWordPrintable

      While trying to load jar file at run time we are getting
      following exception:
      java.lang.IllegalArgumentException: object is not an instance of declaring
      class at
      jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-ea/Native
      Method) at
      jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-ea/NativeMeth
      odAccessorImpl.java:62) at
      jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-ea/Delega
      tingMethodAccessorImpl.java:43) at
       java.lang.reflect.Method.invoke(java.base@9-ea/Method.java:533)
      The exception is seen only with JDK9, code was working fine with the previous
      versions of JDKs i.e. JDK 8, JDK 7, JDK 6, etc.
      Please note, Code does not throw any compile time error when compiled with
      JDK 9, but it fails at runtime with above exception.
      ***********************
      JDK Version:
      java version "9-ea"
      Java(TM) SE Runtime Environment (build 9-ea+123)
      Java HotSpot(TM) 64-Bit Server VM (build 9-ea+123, mixed mode)

      Attached a test program, it tries to load a given jar file to
      system class loader at run time.
      Code throws exception (IllegalArgumentException) when running it against
      JDK 9 but works fine with earlier versions of JDKs(i.e. 8/7/6).
      Compile attached program and invoke it as:
      java LoadMyJar "my.pack.MyPackage" c:\mypack.jar
      First argument it takes is a class name which should be the part of jar file
      and second argument is the jar file itself.
      Note: You could use any jar file though I have attached a sample mypack.jar
      with the bug.

        1. LoadMyJar.java
          2 kB
          Abdul Kolarkunnu

            mchung Mandy Chung
            shadowbug Shadow Bug
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: