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
[FIXED JENKINS-47159] Set proper vargs location #156
Conversation
We shouldn't be starting looking for vargs until we've got to the index of the last parameter type *and* that last parameter type is an array. So...tada.
Verified - fixes JENKINS-47159. |
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
@abayer I think I found another issue, checking now. |
Yep there's an issue. |
if (arrayLength >= 0) { | ||
if (arrayLength == 1 && parameterTypes[fixedLen].isInstance(parameters[fixedLen])) { | ||
// not a varargs call | ||
return parameters; | ||
} else { | ||
Object array = DefaultTypeTransformation.castToVargsArray(parameters, 0, parameterTypes[fixedLen]); | ||
Object array = DefaultTypeTransformation.castToVargsArray(parameters, arrayLength, parameterTypes[fixedLen]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be passing fixedLen and not arrayLength as second argument, as castToVargsArray expects a 'firstVargsPos' here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, that doesn't work in case there's only one parameter...
Brings us back to the previous bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't his be a more correxct way to fix this:
if (arrayLength == 1 && parameterTypes[fixedLen].isInstance(parameters[fixedLen])) {
// not a varargs call
return parameters;
}
else if (componentType.isInstance(parameters[fixedLen])){
Object array = DefaultTypeTransformation.castToVargsArray(parameters, fixedLen, parameterTypes[fixedLen]);
Object[] parameters2 = new Object[fixedLen + 1];
System.arraycopy(parameters, 0, parameters2, 0, fixedLen);
parameters2[fixedLen] = array;
return parameters2;
}
else{
return parameters;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least this works for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh...hey. That looks smarter than me. =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :) took me the whole day to understand how this should work. Any idea why the test is failing? Looks unrelated...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Willing to bet it's related, given that it's varargs. Digging now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not understand the fix at all, but tests look reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see a little more testing of some of the negative cases and odd cases though, like some non-matching varArgs and mixes of types where it can't be legally cast.
@svanoort Reasonable. Will try to do tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess?
ping @svanoort for re-review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now
Conflicts: src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/groovy/GroovyCallSiteSelector.java
JENKINS-47159
Replaces #155
We shouldn't be starting looking for vargs until we've got to the
index of the last parameter type and that last parameter type is an
array. So...tada.
cc @reviewbybees @antweiss