Skip to content

Conversation

@trinistr
Copy link
Contributor

I've been having intermittent problems running RSpec tests on JRuby, with an ArrayIndexOutOfBoundsException happening all of a sudden.

Stacktrace shows that coverage is the problem:

An error occurred while loading spec_helper.
Failure/Error: Unable to find org.jruby.dist/org.jruby.util.collections.IntList.get(IntList.java to read failed line
Java::JavaLang::ArrayIndexOutOfBoundsException:
  Index 213 out of bounds for length 213
# org.jruby.dist/org.jruby.util.collections.IntList.get(IntList.java:25)
# org.jruby.dist/org.jruby.ext.coverage.CoverageData.mergeLines(CoverageData.java:206)
# org.jruby.dist/org.jruby.ext.coverage.CoverageData.prepareCoverage(CoverageData.java:184)
# org.jruby.dist/org.jruby.parser.RubyParserBase.finishCoverage(RubyParserBase.java:2417)
# org.jruby.dist/org.jruby.parser.RubyParserBase.addRootNode(RubyParserBase.java:473)
# org.jruby.dist/org.jruby.parser.RubyParser.lambda$static$1(RubyParser.java:2028)
# org.jruby.dist/org.jruby.parser.RubyParser.yyparse(RubyParser.java:1972)
# org.jruby.dist/org.jruby.parser.RubyParser.yyparse(RubyParser.java:1840)
# org.jruby.dist/org.jruby.parser.RubyParserBase.parse(RubyParserBase.java:2205)
# org.jruby.dist/org.jruby.parser.Parser.parse(Parser.java:129)
# org.jruby.dist/org.jruby.parser.Parser.parse(Parser.java:89)
# org.jruby.dist/org.jruby.parser.ParserManager.parseEval(ParserManager.java:95)

It also looks like enabling coverage for evaled code may be the problem, as not enabling it solved it at least in most recent case. However, in a different project it makes no difference, so not sure. Also, in this case I was only using class_eval with a block, not a string 🤷

Anyway, I looked in the code and found the problem. In mergeLines there is logic for increasing the size of the list, but the main merging loop was getting values from the original list instead, going out of bounds.

This PR solves the problem. I ran this against my RSpec suite, and there is no longer an error.

@trinistr trinistr marked this pull request as draft November 30, 2025 14:23
@trinistr
Copy link
Contributor Author

trinistr commented Nov 30, 2025

Actually, I'm not sure if this works correctly, as the array is unintialized. I've added filling the extra part of the array with -1's.

@trinistr trinistr force-pushed the fix-coverage-merge-lines branch from d55de8a to f5d1783 Compare November 30, 2025 14:38
@trinistr trinistr force-pushed the fix-coverage-merge-lines branch from f5d1783 to f523ed1 Compare November 30, 2025 14:39
@trinistr trinistr marked this pull request as ready for review November 30, 2025 14:39
@headius
Copy link
Member

headius commented Dec 2, 2025

Great, thank you! I've approved CI to run and I'll review.

If you haven't already, please submit a PR to update https://github.com/jruby/jruby/blob/master/USERS.md with your use case. It really helps us show others what JRuby is capable of!

Copy link
Member

@headius headius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good... silly mistake!

@headius headius merged commit 73c8e4d into jruby:master Dec 2, 2025
76 checks passed
@trinistr trinistr deleted the fix-coverage-merge-lines branch December 2, 2025 16:36
@trinistr
Copy link
Contributor Author

trinistr commented Dec 2, 2025

If you haven't already, please submit a PR to update https://github.com/jruby/jruby/blob/master/USERS.md with your use case. It really helps us show others what JRuby is capable of!

I'm really not much of a user, regrettably. I've taken to running CI of personal projects with easily available Ruby implementations (via ruby/setup-ruby), which helps surface incompatibilities.

trinistr added a commit to trinistr/browser_of_babel that referenced this pull request Dec 2, 2025
@headius headius added this to the JRuby 10.0.3.0 milestone Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants