Skip to content

Commit

Permalink
[JENKINS-25524] There are cases where Groovy picks one of two incompa…
Browse files Browse the repository at this point in the history
…rable overloads even where javac would report an error; they must be allowed.
  • Loading branch information
jglick committed Nov 14, 2014
1 parent 72c574d commit bb4cafb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -176,7 +176,8 @@ private static boolean isMoreSpecific(Method more, Method less) {
return true;
}
}
throw new IllegalStateException(more + " and " + less + " seem incomparable");
// Incomparable. Arbitrarily pick one of them.
return more.toString().compareTo(less.toString()) > 0;
}

private GroovyCallSiteSelector() {}
Expand Down
Expand Up @@ -35,6 +35,7 @@
import hudson.Functions;

import java.lang.reflect.Method;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -342,6 +343,15 @@ private Unsafe() {}
assertEvaluate(new StaticWhitelist("method java.lang.CharSequence charAt int"), '2', "'123'.charAt(1);");
}

@Test public void ambiguousOverloads() {
// Groovy selects one of these. How, I do not know.
assertEvaluate(new AnnotatedWhitelist(), true, Ambiguity.class.getName() + ".m(null)");
}
public static final class Ambiguity {
@Whitelisted public static boolean m(String x) {return true;}
@Whitelisted public static boolean m(URL x) {return true;}
}

private static void assertEvaluate(Whitelist whitelist, final Object expected, final String script) {
final GroovyShell shell = new GroovyShell(GroovySandbox.createSecureCompilerConfiguration());
assertEquals(expected, GroovySandbox.run(shell.parse(script), whitelist));
Expand Down

0 comments on commit bb4cafb

Please sign in to comment.