-
Notifications
You must be signed in to change notification settings - Fork 239
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
ArrayIndexOutOfBoundsException when using @Tested (was: "Method parameter names counting counts double for reference types") #243
Comments
Without a description of the problem (from the user's perspective), a failing example test, or sufficient information for me to write a failing test, there isn't much else to go on. |
In the description I state: The following call, will reproduce the bug: If that is not enough I can craft a class and a unit test using jmockit that will break, but is easy enough to inspect the implementation of ParameterNames.getSumOfArgumentSizes() and realize that it doesn't properly parse a method descriptor, as I explained as well in the description. |
Here it is a test that causes an ArrayIndexOutOfBoundException:
And the following is a class that test for the expected parameter slots count for reference types:
|
Hello Rogerio, Regards, On Sat, 5 Dec 2015 at 02:21 Rogério Liesenfeld notifications@github.com
"Any system like Eternity, which allows men to choose their own future, The End of Eternity - Isaac Asimov |
Thanks. |
The failure occurs whenever the parameter names of a method or constructor are extracted, provided there's at least one parameter of a reference type and the first local variable is of type long or double. For example, if the test class has a @tested class like the following, any test will fail with an ArrayIndexOutOfBoundsException:
|
The new
ParameterNames.getSumOfArgumentSizes
method counts double when a parameter is a non array reference type, because, when the code finds the';'
character, it does not increase'i'
again after the loop, causing the main loop to read it again and treat it as another parameter.The following call, will reproduce the bug:
ParameterNames.registerName("A", PUBLIC, "m1", "(Ljava/lang/String;)", "J", "local", 2);
I also believe that the case for the array would not properly handle arrays of reference types.
I suggest using the following implementation:
The text was updated successfully, but these errors were encountered: