Skip to content

Commit d8198d9

Browse files
committedMar 19, 2018
Add debug property for ambiguous Ruby to Java calls. Fixes #4894.
1 parent e2f9386 commit d8198d9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/java/dispatch/CallableSelector.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.jruby.javasupport.JavaUtil;
2323
import org.jruby.javasupport.ParameterTypes;
2424
import org.jruby.runtime.builtin.IRubyObject;
25+
import org.jruby.util.cli.Options;
2526
import org.jruby.util.collections.IntHashMap;
2627
import static org.jruby.util.CodegenUtils.getBoxType;
2728
import static org.jruby.util.CodegenUtils.prettyParams;
@@ -279,7 +280,18 @@ else if ( procArity < 0 && methodArity >= -(procArity + 1) ) { // *splat that fi
279280
method = mostSpecific;
280281

281282
if ( ambiguous ) {
282-
runtime.getWarnings().warn("ambiguous Java methods found, using " + ((Member) ((JavaCallable) method).accessibleObject()).getName() + prettyParams(msTypes));
283+
if (Options.DEBUG_AMBIGUOUS_JAVA_CALLS.load()) {
284+
runtime.newRuntimeError(
285+
"multiple Java methods found, dumping backtrace and choosing "
286+
+ ((Member) ((JavaCallable) method).accessibleObject()).getName()
287+
+ prettyParams(msTypes)
288+
).printStackTrace(runtime.getErr());
289+
} else {
290+
runtime.getWarnings().warn(
291+
"multiple Java methods found, use -Xdebug.ambiguous.java.calls for backtrace. Choosing "
292+
+ ((Member) ((JavaCallable) method).accessibleObject()).getName()
293+
+ prettyParams(msTypes));
294+
}
283295
}
284296
}
285297
}

Diff for: ‎core/src/main/java/org/jruby/util/cli/Options.java

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public class Options {
188188
public static final Option<String> LOGGER_CLASS = string(DEBUG, "logger.class", new String[]{"class name"}, "org.jruby.util.log.StandardErrorLogger", "Use specified class for logging.");
189189
public static final Option<Boolean> DUMP_INSTANCE_VARS = bool(DEBUG, "dump.variables", false, "Dump class + instance var names on first new of Object subclasses.");
190190
public static final Option<Boolean> REWRITE_JAVA_TRACE = bool(DEBUG, "rewrite.java.trace", true, "Rewrite stack traces from exceptions raised in Java calls.");
191+
public static final Option<Boolean> DEBUG_AMBIGUOUS_JAVA_CALLS = bool(DEBUG, "debug.ambiguous.java.calls", false, "Toggle verbose reporting of all ambiguous calls to Java objects");
191192

192193
// TODO: Replace flag that's false on 9 with proper module checks
193194
public static final Option<Boolean> JI_SETACCESSIBLE = bool(JAVA_INTEGRATION, "ji.setAccessible", calculateSetAccessibleDefault(), "Try to set inaccessible Java methods to be accessible.");

0 commit comments

Comments
 (0)
Please sign in to comment.