[ 
https://issues.apache.org/jira/browse/LANG-1310?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15931188#comment-15931188
 ] 

ASF GitHub Bot commented on LANG-1310:
--------------------------------------

Github user Claudenw commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/256#discussion_r106778971
  
    --- Diff: 
src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java ---
    @@ -357,16 +369,23 @@ public void testInvokeMethod() throws Exception {
             assertEquals("foo(int)", MethodUtils.invokeMethod(testBean, "foo",
                     NumberUtils.BYTE_ONE));
             assertEquals("foo(double)", MethodUtils.invokeMethod(testBean, 
"foo",
    -                NumberUtils.LONG_ONE));
    -        assertEquals("foo(double)", MethodUtils.invokeMethod(testBean, 
"foo",
                     NumberUtils.DOUBLE_ONE));
             assertEquals("foo(String...)", MethodUtils.invokeMethod(testBean, 
"foo",
                     "a", "b", "c"));
             assertEquals("foo(String...)", MethodUtils.invokeMethod(testBean, 
"foo",
                     "a", "b", "c"));
             assertEquals("foo(int, String...)", 
MethodUtils.invokeMethod(testBean, "foo",
                     5, "a", "b", "c"));
    -
    +        assertEquals("foo(long...)", MethodUtils.invokeMethod(testBean, 
"foo",
    +                1L, 2L));
    +        
    +        try {
    +            MethodUtils.invokeMethod(testBean, "foo",
    +                    1, 2);
    +            fail("should throw NoSuchMethodException");
    +        } catch (final NoSuchMethodException e) {
    --- End diff --
    
    I find that the expect exception works well only with very short tests.  In 
this case if any of the earlier method calls throws the NoSuchMethodException 
the test will not fail.  In my opinion the current construct is the better one.


> MethodUtils.invokeMethod throws ArrayStoreException
> ---------------------------------------------------
>
>                 Key: LANG-1310
>                 URL: https://issues.apache.org/jira/browse/LANG-1310
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.reflect.*
>    Affects Versions: 3.5
>            Reporter: Eickvonder
>
> 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).
> {code}
>   @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");
>     }
>   }
> {code}
> throws 
> {code}
> 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)
> {code}
> 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.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to