Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError raised by JRuby during keyword argument checking while the call is perfectly legit #3760

doudou opened this issue Mar 27, 2016 · 6 comments


Copy link

doudou commented Mar 27, 2016


jruby (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [linux-amd64] on Linux squidock 4.5.0-040500-generic #201603140130 SMP Mon Mar 14 05:32:22 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux (Kubuntu 15.10)

Ran with --debug -G, but the problem also appears with no command line options.

Noteworthy gems: facets (but not only very little of it activated), concurrent-ruby. The code that causes the problem is not multithreaded.

Expected Behaviour

I'm calling a method whose signature is def process_events_synchronous(seeds =, initial_errors =, enable_scheduler: false) The call line is engine.process_events_synchronous(seeds)

Links to the actual called method and the calling site

To reproduce,

git clone -b roby3
cd tools-roby
bundle install
ruby test/test_event_generator.rb -n /test_emit_without_propagation/

I expect to enter the called method.

Actual Behaviour

JRuby raises a TypeError exception complaining that XXXX is not a string where 'XXX' looks like the result of the caller's #inspect. The first line of the TypeError backtrace on the Ruby side is bogus (see #3624). Removing the keyword argument enable_scheduler makes the call pass as expected. The full backtrace reports

    java/lang/ `getStackTrace'
    org/jruby/runtime/backtrace/ `getBacktraceData'
    org/jruby/runtime/backtrace/ `getBacktrace'
    org/jruby/ `prepareBacktrace'
    org/jruby/exceptions/ `preRaise'
    org/jruby/exceptions/ `preRaise'
    org/jruby/exceptions/ `<init>'
    org/jruby/ `newRaiseException'
    org/jruby/ `newTypeError'
    org/jruby/ `asJavaString'
    org/jruby/ir/runtime/ `visit'
    org/jruby/ `visitLimited'
    org/jruby/ `visitAll'
    org/jruby/ir/runtime/ `checkForExtraUnwantedKeywordArgs'
    org/jruby/ir/runtime/ `checkArity'
    org/jruby/ir/instructions/ `checkArity'
    org/jruby/ir/interpreter/ `processBookKeepingOp'
    org/jruby/ir/interpreter/ `interpret'
    org/jruby/ir/interpreter/ `interpret'
    org/jruby/internal/runtime/methods/ `INTERPRET_METHOD'
    /home/doudou/dev/rock/toolchain-devel/jruby/tools-roby/lib/roby/execution_engine.rb:661:in `process_events_synchronous'
    org/jruby/internal/runtime/methods/ `call'
    org/jruby/internal/runtime/methods/ `call'
    org/jruby/runtime/callsite/ `cacheAndCall'
    org/jruby/runtime/callsite/ `call'
    org/jruby/ir/interpreter/ `processCall'
    org/jruby/ir/interpreter/ `interpret'
    org/jruby/ir/interpreter/ `interpret'
    org/jruby/internal/runtime/methods/ `INTERPRET_METHOD'
    /home/doudou/dev/rock/toolchain-devel/jruby/tools-roby/lib/roby/event_generator.rb:661:in `emit'
Copy link

doudou commented Mar 28, 2016

OK, so narrowed it down to JRuby having different rules than MRI when a method is given a hash as argument, and also has keyword arguments.

I've been testing a few cases, and it seems that MRI's rule in this case is that any key that is not a symbol is fed into the argument (that does include strings), any key that is a symbol is interpreted as a keyword argument


def test(argument =, keyword_arg: true)
    puts "ARGS: #{argument.inspect}"
    puts "KW: #{keyword_arg}"
test(Hash[ => 10])


ruby 2.1.6p336 (2015-04-13 revision 50298) [x86_64-linux]
ARGS: {#<Object:0x00000001bace70>=>10}
KW: true


jruby (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [linux-amd64]
TypeError: #<Object:0x6f1fba17> is not a string
  <top> at jruby_bug.rb:5

Copy link

headius commented Mar 28, 2016

Thanks for the reduction, @doudou. I'll poke at this a bit this morning.

Copy link

headius commented Mar 28, 2016

The problem appears to be that we try to coerce keys to a string-like thing when we are walking keys we're not sure should be in the kwargs processing. We need the string for the hash lookup. I believe we should only perform this search for keys that actually are string-like, or perhaps only symbols.

Copy link

headius commented Mar 28, 2016

This is unlikely to make 9.1 because of some key issues we have to fix:

  • Only symbols should ever be processed as kwarg keys. We're processing both symbols and strings currently.
  • Any incoming hash in the proper position to be processed as kwargs (last non-required argument) has potential to be split, with symbolic keys going to kwargs and non-symbolic keys remaining part of the normal arg-passed hash. Currently, once we've decided a hash is in the right position to be used for kwargs, we don't use it for anything else (leading to this error).

The main piece that's missing is that we don't treat an incoming kwarg-able hash as potentially containing both kwarg symbols and non-kwarg pairs. We need a step before arity-checking and argument assignment that breaks apart such hashes into kwargable and non-kwargable parts.

Copy link

headius commented Aug 22, 2016

I think @enebo's nearly-ready args work will probably fix this.

Copy link

enebo commented Aug 22, 2016

Fixed in commit c183943.

@enebo enebo closed this as completed Aug 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

3 participants