Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1310

MethodUtils.invokeMethod throws ArrayStoreException if using varargs arguments and smaller types than the method defines

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.5
    • 3.6
    • lang.reflect.*
    • None

    Description

      Since release 3.5 and due to the changes of LANG-1115 an ArrayStoreException occurs on MethodUtils.invokeMethod if using varargs arguments and smaller types than the method defines (e.g. int vs long).

        @Test
        public void testMethodUtilsInvokeMethodVarArgs () throws Exception {
          MyObject object = new MyObject ();
          MethodUtils.invokeMethod (object, "doSomething", 1);
        }
      
        public static class MyObject {
          public void doSomething (long... args) {
            System.out.println ("doSomething");
          }
        }
      

      throws

      java.lang.ArrayStoreException
      	at java.lang.System.arraycopy(Native Method)
      	at org.apache.commons.lang3.reflect.MethodUtils.getVarArgs(MethodUtils.java:497)
      	at org.apache.commons.lang3.reflect.MethodUtils.toVarArgs(MethodUtils.java:463)
      	at org.apache.commons.lang3.reflect.MethodUtils.invokeMethod(MethodUtils.java:234)
      	at org.apache.commons.lang3.reflect.MethodUtils.invokeMethod(MethodUtils.java:270)
      	at org.apache.commons.lang3.reflect.MethodUtils.invokeMethod(MethodUtils.java:147)
      

      In 3.4. a NoSuchMethodException had been thrown, but in 3.5 the code now finds the matching method but fails then with above exception.

      Attachments

        Issue Links

          Activity

            People

              pascalschumacher Pascal Schumacher
              eicki Eickvonder
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: