Fix off-by-one error causing Dir.glob("foo" + "{bar}") to fail if Java asserts are enabled#5612
Fix off-by-one error causing Dir.glob("foo" + "{bar}") to fail if Java asserts are enabled#5612ikaronen-relex wants to merge 2 commits intojruby:masterfrom
Conversation
Probably because it launches a subprocess. The You're right, we should run asserts in the specs. That would be tweakable under rakelib/spec.rake I think? Thanks for the work on this one! |
|
I pushed a tweak to the build that enables assertions across the board: 21e4663. |
|
Master is green again with assertions enabled. Perhaps now you can merge or rebase and add specs for the behaviors you fixed? |
fe11a3a to
e65a9a4
Compare
|
Well, I wrote what I thought would be a reasonable basic regression test, but when I try to run it using the instructions at https://github.com/jruby/jruby/blob/master/BUILDING.md, i.e. with the command: all I get is: It looks as if the modern |
|
Ah, don't run mspec for those specs. mspec is only for the "Ruby specs" under spec/ruby. Install rspec and run that for spec/regression, or |
|
@ikaronen-relex We have not had time to follow up on this, so punting it for this release. If it's ready to go, we can merge it into 9.2.8.0, due out in May. |
it did not work for a while (was noticed at jrubyGH-5612) assertions are enabled in tests since: 21e4663
|
okay, so I fixed the |
|
@kares Wow! Ok, I thought I had fixed -ea stuff previously, but I think I only did it for rubyspec (which seems half ok). These all need to be fixed, obviously! |
it did not work for a while (was noticed at jrubyGH-5612) assertions are enabled in tests since: 21e4663
|
the relevant commit is now on master, there were several ByteList failures (as explained here) wout it |
When Java asserts are enabled,
Dir.globandDir[]crash if given a pattern that ends in a curly brace. However, this only happens if the pattern string has not been interned. (Specifically, the underlying ByteList must havebytes.length == realSizefor the bug to trigger. Apparently that's not usually the case for interned string literals.)Here is a simple command-line test case:
(I have no idea why both
JAVA_OPTS=-eaand-J-eaare needed to enable Java asserts, but that seems to be the case. That might be a separate issue.)On JRuby 9.2.6.0, running the command above produces the following output:
As it happens, this assertion error is also triggered by running RSpec with no arguments (and with Java asserts enabled), since the glob pattern it uses to find spec files (
"spec/{**{,/*/**}/*_spec.rb}"by default) ends in a curly brace (and is constructed via concatenation at runtime, and thus not interned). In particular, running:fails with:
The cause of this bug is a simple off-by-one error in the assert at ByteList.java line 524 (which was formerly commented out due to CI failures, and reintroduced into JRuby 9.2.6.0 by commit 607998c). Instead of:
the correct assertion would simply be:
This change permits the degenerate but valid use case of appending 0 bytes starting at the end of a non-empty byte array.
Ps. Here's one more direct test case that doesn't depend on the specific behavior of the Dir class:
I would include this (and the first test case above) as specs in the PR, but it would seem that JRuby specs are currently run with Java asserts disabled by default, and I'm not sure how to change or work around that.