Skip to content

Commit

Permalink
[FIXED JENKINS-44557] Properly cast GString in vargs.
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Sep 18, 2017
1 parent 244f31e commit 8abef0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Expand Up @@ -37,6 +37,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.apache.commons.lang.ClassUtils;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;

/**
* Assists in determination of which method or other JVM element is actually about to be called by Groovy.
Expand Down Expand Up @@ -99,10 +100,7 @@ private static Object[] parametersForVarargs(Class<?>[] parameterTypes, Object[]
// not a varargs call
return parameters;
} else {
Object array = Array.newInstance(componentType, arrayLength);
for (int i = 0; i < arrayLength; i++) {
Array.set(array, i, parameters[fixedLen + i]);
}
Object array = DefaultTypeTransformation.castToVargsArray(parameters, 0, parameterTypes[fixedLen]);
Object[] parameters2 = new Object[fixedLen + 1];
System.arraycopy(parameters, 0, parameters2, 0, fixedLen);
parameters2[fixedLen] = array;
Expand Down
Expand Up @@ -914,4 +914,14 @@ public void enumWithStringAndVarargs() throws Exception {
String expected = "The first thing";
assertEvaluate(new GenericWhitelist(), expected, script);
}

@Issue("JENKINS-44557")
@Test
public void varArgsWithGString() throws Exception {
ProxyWhitelist wl = new ProxyWhitelist(new GenericWhitelist(), new AnnotatedWhitelist());
String uv = UsesVarargs.class.getName();

assertEvaluate(wl, 3, "def twoStr = 'two'; " + uv + ".len('one', \"${twoStr}\", 'three')");

}
}

0 comments on commit 8abef0d

Please sign in to comment.