Skip to content

Commit

Permalink
Add debug property for ambiguous Ruby to Java calls. Fixes #4894.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 19, 2018
1 parent e2f9386 commit d8198d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/src/main/java/org/jruby/java/dispatch/CallableSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jruby.javasupport.JavaUtil;
import org.jruby.javasupport.ParameterTypes;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.cli.Options;
import org.jruby.util.collections.IntHashMap;
import static org.jruby.util.CodegenUtils.getBoxType;
import static org.jruby.util.CodegenUtils.prettyParams;
Expand Down Expand Up @@ -279,7 +280,18 @@ else if ( procArity < 0 && methodArity >= -(procArity + 1) ) { // *splat that fi
method = mostSpecific;

if ( ambiguous ) {
runtime.getWarnings().warn("ambiguous Java methods found, using " + ((Member) ((JavaCallable) method).accessibleObject()).getName() + prettyParams(msTypes));
if (Options.DEBUG_AMBIGUOUS_JAVA_CALLS.load()) {
runtime.newRuntimeError(
"multiple Java methods found, dumping backtrace and choosing "
+ ((Member) ((JavaCallable) method).accessibleObject()).getName()
+ prettyParams(msTypes)
).printStackTrace(runtime.getErr());
} else {
runtime.getWarnings().warn(
"multiple Java methods found, use -Xdebug.ambiguous.java.calls for backtrace. Choosing "
+ ((Member) ((JavaCallable) method).accessibleObject()).getName()
+ prettyParams(msTypes));
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public class Options {
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.");
public static final Option<Boolean> DUMP_INSTANCE_VARS = bool(DEBUG, "dump.variables", false, "Dump class + instance var names on first new of Object subclasses.");
public static final Option<Boolean> REWRITE_JAVA_TRACE = bool(DEBUG, "rewrite.java.trace", true, "Rewrite stack traces from exceptions raised in Java calls.");
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");

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

0 comments on commit d8198d9

Please sign in to comment.