Skip to content

Commit

Permalink
[FIXED JENKINS-38908] Incorrect specificity calculation when varargs …
Browse files Browse the repository at this point in the history
…are involved.
  • Loading branch information
jglick committed Oct 11, 2016
1 parent 94eabc2 commit fa6f8e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -224,7 +224,15 @@ private static void visitTypes(@Nonnull Set<Class<?>> types, @Nonnull Class<?> c
private static boolean isMoreSpecific(Method more, Method less) {
Class<?>[] moreParams = more.getParameterTypes();
Class<?>[] lessParams = less.getParameterTypes();
assert moreParams.length == lessParams.length;
if (less.isVarArgs() && !more.isVarArgs()) {
return true; // main() vs. main(String...) on []
} else if (!less.isVarArgs() && more.isVarArgs()) {
return false;
}
// TODO what about passing [arg] to log(String...) vs. log(String, String...)?
if (moreParams.length != lessParams.length) {
throw new IllegalStateException("cannot compare " + more + " to " + less);
}
for (int i = 0; i < moreParams.length; i++) {
Class<?> moreParam = Primitives.wrap(moreParams[i]);
Class<?> lessParam = Primitives.wrap(lessParams[i]);
Expand Down
Expand Up @@ -25,11 +25,14 @@
package org.jenkinsci.plugins.scriptsecurity.sandbox.groovy;

import com.google.common.io.NullOutputStream;
import groovy.lang.Binding;
import groovy.lang.GString;
import groovy.lang.Script;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import org.codehaus.groovy.runtime.GStringImpl;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.EnumeratingWhitelistTest;
import org.jenkinsci.plugins.scriptsecurity.scripts.ApprovalContext;
import static org.junit.Assert.*;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
Expand Down Expand Up @@ -71,4 +74,11 @@ public static void m2(int x) {}
public static void m2(long x) {}
}

@Issue("JENKINS-38908")
@Test public void main() throws Exception {
Script receiver = (Script) new SecureGroovyScript("def main() {}; this", true, null).configuring(ApprovalContext.create()).evaluate(GroovyCallSiteSelectorTest.class.getClassLoader(), new Binding());
assertEquals(receiver.getClass().getMethod("main"), GroovyCallSiteSelector.method(receiver, "main", new Object[0]));
assertEquals(receiver.getClass().getMethod("main", String[].class), GroovyCallSiteSelector.method(receiver, "main", new Object[] {"somearg"}));
}

}

0 comments on commit fa6f8e3

Please sign in to comment.