Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException on vararg methods #21

Open
balazsbalazs opened this issue Nov 19, 2013 · 3 comments
Open

IllegalArgumentException on vararg methods #21

balazsbalazs opened this issue Nov 19, 2013 · 3 comments

Comments

@balazsbalazs
Copy link

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

@balazsbalazs
Copy link
Author

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).

@stephanenicolas
Copy link
Owner

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 notifications@github.com

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//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
...........................................................

@balazsbalazs
Copy link
Author

I'll try but as usual I got a hundred other things before this :) It's on my todo list though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants