boundbox
boundbox copied to clipboard
IllegalArgumentException on vararg methods
Sample class:
public class ClassA {
public void foo(String ...args) {
}
}
Code generated by boundbox:
public void foo(String[] arg0) {
try {
Method methodToInvoke = ClassA.class.getDeclaredMethod("foo", String[].class);
methodToInvoke.setAccessible(true);
methodToInvoke.invoke(object, arg0);
}
...
When invoked this results in an IllegalArgumentException.
The correct code would be either:
methodToInvoke.invoke(object, (Object)arg0);
or
methodToInvoke.invoke(object, new Object[] {arg0});
More details can be found here: http://stackoverflow.com/questions/2600854/how-to-work-with-varargs-and-reflection
I'm going to look into the code and try to submit a pull request (I wanted to look into compile time annotations anyway, so it's a good exercise anyway).
Thx very much. I got no time to enhance BoundBox before Xmas. If you find a workaround, and add tests for it, a pull request would be accepted cheerfully.
S.
2013/11/19 balazsbalazs [email protected]
I'm going to look into the code and try to submit a pull request (I wanted to look into compile time annotations anyway, so it's a good exercise anyway).
— Reply to this email directly or view it on GitHubhttps://github.com/stephanenicolas/boundbox/issues/21#issuecomment-28807954 .
Stéphane NICOLAS, OCTO Technology Développeur & Consultant Android / Java .......................................................... 50, Avenue des Champs-Elysées 75008 Paris +33 (0)6.26.32.34.09 www.octo.com - mobilite.octo.com blog.octo.com - www.usievents.com ...........................................................
I'll try but as usual I got a hundred other things before this :) It's on my todo list though.