mail icon indicating copy to clipboard operation
mail copied to clipboard

JRuby9x, Java::JavaLang::ArrayIndexOutOfBoundsException

Open solsticejc opened this issue 4 years ago • 4 comments

I got below exception when start up a Rails project. Looks like the RubyGem-mail parser has problem

An error occurred while loading ./spec/controllers/application_controller_spec.rb. - Did you mean?
                    rspec ./spec/controllers/ping_controller_spec.rb
                    rspec ./spec/controllers/errors_controller_spec.rb
Failure/Error: require File.expand_path("../../config/environment", __FILE__)
LoadError:
  load error: mail/parsers/address_lists_parser -- java.lang.ArrayIndexOutOfBoundsException: -32624
# ./config/environment.rb:5:in `<main>'
# ./spec/spec_helper.rb:50:in `<main>'
# ./spec/controllers/application_controller_spec.rb:1:in `<main>'
# ------------------
# --- Caused by: ---
# Java::JavaLang::ArrayIndexOutOfBoundsException:
#   -32624
#   org.jruby.parser.ParserConfiguration.coverLine(ParserConfiguration.java:193)
An error occurred while loading ./spec/controllers/errors_controller_spec.rb.
Failure/Error: require File.expand_path("../../config/environment", __FILE__)
FrozenError:
  can't modify frozen Array
# ./config/environment.rb:5:in `<main>'
# ./spec/spec_helper.rb:50:in `<main>'
# ./spec/controllers/errors_controller_spec.rb:1:in `<main>'
An error occurred while loading ./spec/controllers/ping_controller_spec.rb.
Failure/Error: require File.expand_path("../../config/environment", __FILE__)
FrozenError:
  can't modify frozen Array
# ./config/environment.rb:5:in `<main>'
# ./spec/spec_helper.rb:50:in `<main>'
# ./spec/controllers/ping_controller_spec.rb:1:in `<main>'

solsticejc avatar Nov 01 '21 20:11 solsticejc

+1 facing the same issue.

adwsingh avatar Nov 09 '21 11:11 adwsingh

Eventually overcome the build failure. Dive deeper the open source code here https://code.yawk.at/org.jruby/jruby-core/9.2.9.0/org/jruby/parser/ParserConfiguration.java#193

This failure happened to store the code coverage line number. It does not impact the major runtime function. So, we can temporarily disable the code coverage inspection to bypass this failure, though still no idea why the array access would be ArrayIndexOutOfBoundsException. This may need the open source owner to fix the problem.

My solution is to add NO_COVERAGE=true env variable at the Rakefile CLI. For example: sh "cd rails-root && RAILS_ENV=test NO_COVERAGE=true JRUBY_OPTS=--debug rspec --options=.rspec spec/"

And reference this NO_COVERAGE env variable at the Coverage inspection. For example:

unless ENV["NO_COVERAGE"] SimpleCov.start 'rails' do // Code to inspect the covage ... end end

solsticejc avatar Dec 04 '21 20:12 solsticejc

@solsticejc it's an internal limitation on how JRuby stores line numbers for coverage. See https://github.com/jruby/jruby/issues/6984

I agree that an exception is bad and it should be fixed on the JRuby's side. For now as a workaround, just disable coverage, the bug doesn't affect the regular runtime.

ahorek avatar Jan 10 '22 00:01 ahorek

it should be fixed by https://github.com/jruby/jruby/pull/6991

ahorek avatar Mar 07 '22 14:03 ahorek