Search code examples
javaunit-testingrakejrubyjrubyonrails

jruby based Rails3 project, running unit test gives 'java.util.ConcurrentModificationException' error


I've a Rails 3 project based on JRuby, which is running excellent in development mode.

But, running even a basic unit test in it is generating 'java.util.ConcurrentModificationException' error raised 'at java.util.WeakHashMap$HashIterator.nextEntry(WeakHashMap.java:784)'.

It's loading my initialization scripts correctly, and then later this error generates.

I removed my added tests, but its still failing even at the most basic auto-generated 'assert true' test.

Trace gives me:

** Invoke test:units (first_time)
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment 
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment 
** Execute db:schema:load
** Execute test:prepare
** Execute test:units
java.util.ConcurrentModificationException
        at java.util.WeakHashMap$HashIterator.nextEntry(WeakHashMap.java:784)
        at java.util.WeakHashMap$KeyIterator.next(WeakHashMap.java:817)
        at org.jruby.Ruby.eachModule(Ruby.java:780)
        ..........
        at org.jruby.util.ShellLauncher$ScriptThreadProcess.run(ShellLauncher.java:136)
        at java.lang.Thread.run(Thread.java:636)
rake aborted!

Solution

  • If you aren't already using JRuby 1.5.6, try upgrading to this latest version.

    The JRuby guys applied a fix which you can read about here.