Skip to content

Commit

Permalink
[FIXED JENKINS-47893] Properly set index for varargs casting
Browse files Browse the repository at this point in the history
8abef0d
fixed GString varargs logic...sort of. For some reason, I put a 0 in
for the start index for the array in the parameters, which
was wrong. Duh. This fixes that by properly using the right index.
  • Loading branch information
abayer committed Nov 8, 2017
1 parent 93ef475 commit 34b9948
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Expand Up @@ -100,7 +100,7 @@ private static Object[] parametersForVarargs(Class<?>[] parameterTypes, Object[]
// not a varargs call
return parameters;
} else {
Object array = DefaultTypeTransformation.castToVargsArray(parameters, 0, parameterTypes[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;
Expand Down
Expand Up @@ -536,6 +536,25 @@ public static String join(String sep, String... vals) {
return StringUtils.join(vals, sep);
}
public static void explode(String... vals) {}
@Whitelisted
public static String varargsMethod(Integer i, Boolean b, StringContainer... s) {
return i.toString() + "-" + b.toString() + "-" + StringUtils.join(s, "-");
}
}

public static final class StringContainer {
final String o;

@Whitelisted
public StringContainer(String o) {
this.o = o;
}

@Whitelisted
@Override
public String toString() {
return o;
}
}

@Test public void templates() throws Exception {
Expand Down Expand Up @@ -934,6 +953,20 @@ public void varArgsWithGString() throws Exception {
String uv = UsesVarargs.class.getName();

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

@Issue("JENKINS-47893")
@Test
public void varArgsWithOtherArgs() throws Exception {
ProxyWhitelist wl = new ProxyWhitelist(new GenericWhitelist(), new AnnotatedWhitelist());
String uv = UsesVarargs.class.getName();
String sc = StringContainer.class.getName();
String script = sc + " a = new " + sc + "(\"a\")\n"
+ sc + " b = new " + sc + "(\"b\")\n"
+ sc + " c = new " + sc + "(\"c\")\n"
+ "return " + uv + ".varargsMethod(4, true, a, b, c)\n";

String expected = "4-true-a-b-c";
assertEvaluate(wl, expected, script);
}
}

0 comments on commit 34b9948

Please sign in to comment.