Posts in bug

JRuby Bug Fixed With Regexp Class

I have had some days funny playing with JRuby, specifically I’m working in a DSL verbal_expressions to parser URL.

verbal_expressions is so sexy, very verbose as way it was built and as you can use it. I tested it in MRI and works fine, but in my current project, we need developing a set new features upon JVM, by this reason JRuby plays an important role.

When I made tests using JRuby, I found an weird behaviour, assuming that JRuby allow carry (almost) the whole Ruby code wrote using MRI.

Basically, I made the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Foo < Regexp
  def initialize(&amp;block)</p>

<pre><code>instance_eval &amp;block
super('/some_regex/')
</code></pre>

<p>  end
  def some_method(value)</p>

<pre><code>puts "Output: #{value}"
</code></pre>

<p>  end
end

Because I went to use the previous code just like this.

1
Foo.new { some_method &lsquo;Hi!&rsquo; }

As you can see is very simple what I want, just inherit from Regexp, nothing out of usual here. But when I ran the previous code get the following output.

1
2
3
4
5
6
7
8
9
10
11
12
13
ArgumentError: block not supplied</p>

<pre><code>from org/jruby/RubyBasicObject.java:1709:in `instance_eval'
from (irb):10:in `initialize'
from org/jruby/RubyRegexp.java:729:in `new'
from (irb):17:in `evaluate'
from org/jruby/RubyKernel.java:1066:in `eval'
from org/jruby/RubyKernel.java:1409:in `loop'
from org/jruby/RubyKernel.java:1174:in `catch'
from org/jruby/RubyKernel.java:1174:in `catch'
</code></pre>

<p>

With idea to discard some problem in my code I decided test it with a dummy code like follow:

1
2
3
4
5
6
7
8
class Dummy
  def initialize(&amp;block)</p>

<pre><code>instance_eval &amp;block
</code></pre>

<p>  end
end

When I run the previous code:

1
2
3
4
</p>

<blockquote><blockquote><p>Dummy.new { puts “yay #{self.inspect}” }
yay #<Dummy:0x54bbb2d0>

Works as expected. In JRuby’s IRC I explained the previous ones, after ratnikov made the tests, he confirms it was an issue in RubyRegexp implementation.

Basically, RubyRegexp was ignoring the new’s block

written in bug, fixed, jruby