Skip to content

Occasional ArrayIndexOutOfBoundsException from a line of Ruby that isn't doing array lookups #3729

@hakanai

Description

@hakanai

Environment

JRuby: JRuby 9.0.5.0
OS: OSX 10.11.1

We don't set JRUBY_OPTS. For a change we're running this using the command-line instead of embedding it. We're basically firing up rspec as part of functional testing. None of our command-line options are for changing behaviour in JRuby, other than deliberately setting file.encoding=UTF-8 for the benefit of Windows, which is not relevant for this run here as I'm on OSX.

Gems: rspec-core, rspec-mocks, ci-reporter.

Other environment variables of Ruby relevance:

RBENV_ROOT=/Users/tester/DevEnv/rbenv
RBENV_SHELL=bash

rbenv is indeed present, although we are not using it when running the tests - the tests run by <java classname="org.jruby.Main"> from an Ant task.

Expected Behaviour

I have a spec written as follows:

it 'notifies the callback of each result' do
  callback = double(:callback)
  expect(callback).to receive(:found).exactly(24).times
  @thing.search('mime-type:message/rfc822', callback)
end

Of note, this Thing#search method internally performs work in a thread pool, so the callback gets called from multiple threads, possibly all simultaneously. So the issue I'm about to describe could be a thread safety bug.

Of course I expect this test to pass. ;)

(But due to other circumstances, the test fails about half the time, because this search method ultimately calls the callback on multiple threads and rspec-mocks is not thread-safe. That's another issue and not what I'm reporting here.)

Actual Behaviour

Occasionally (1 per 20 runs or so, based on today's runs), I get this failure instead:

 [java] Failures:
 [java] 
 [java]   1) Thing#search when a callback is provided notifies the callback of each result
 [java]      Failure/Error: Unable to find org.jruby.RubyArray.map(org/jruby/RubyArray.java to read failed line
 [java] 
 [java]      Java::JavaLang::ArrayIndexOutOfBoundsException:
 [java]        7
 [java]      # org.jruby.RubyArray.map(org/jruby/RubyArray.java:2300)
 [java]      # RUBY.(root)(/path/to/project/functional-tests/src/test/rspec/lib/case/search_unsorted_spec.rb:42)
 [java]      # RUBY.run(uri:classloader:/gems/rspec-core-3.4.3/lib/rspec/core/example.rb:236)
 [java]      # RUBY.with_around_and_singleton_context_hooks(uri:classloader:/gems/rspec-core-3.4.3/lib/rspec/core/example.rb:478)
 [java]      # RUBY.block in with_around_example_hooks(uri:classloader:/gems/rspec-core-3.4.3/lib/rspec/core/example.rb:435)
  ...

Line 42 is this one:

      @thing.search('mime-type:message/rfc822', callback)

No call to Array#map on that line, no array lookups either, no idea what is going on.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions