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

[FIXED JENKINS-47159] Set proper vargs location #156

Merged
merged 9 commits into from Nov 27, 2017

Conversation

abayer
Copy link
Member

@abayer abayer commented Sep 28, 2017

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

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.
@antweiss
Copy link

Verified - fixes JENKINS-47159.
Thanks @abayer 👍

@ghost
Copy link

ghost commented Sep 28, 2017

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.

@antweiss
Copy link

@abayer I think I found another issue, checking now.

@antweiss
Copy link

antweiss commented Sep 28, 2017

Yep there's an issue.
I added a comment.

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]);

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

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.

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;
}

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.

Copy link
Member Author

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

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

Copy link
Member Author

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.

Copy link
Member

@jglick jglick left a 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.

Copy link
Member

@svanoort svanoort left a 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.

@abayer
Copy link
Member Author

abayer commented Oct 3, 2017

@svanoort Reasonable. Will try to do tomorrow.

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess?

@abayer
Copy link
Member Author

abayer commented Oct 23, 2017

ping @svanoort for re-review?

Copy link
Member

@svanoort svanoort left a 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
@abayer abayer merged commit 6c6da93 into jenkinsci:master Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants