Skip to content

Problem when method returns Regexp capture group using special variable $1 #5503

@jbaiza

Description

@jbaiza

Environment

Initially we found the problem using Jruby 9.2.1.0, but it's also actual in 9.1.7.0 and in the latest version.

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc)
jruby 9.2.5.0 (2.5.0) 2018-12-06 6d5a228 Java HotSpot(TM) 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [darwin-x86_64]
  • Operating system and platform (e.g. uname -a)
Darwin JBA-MacBook-Pro.local 18.2.0 Darwin Kernel Version 18.2.0: Fri Oct  5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64

Other relevant info you may wish to add:

  • Installed or activated gems
    N/A
  • Application/framework version (e.g. Rails, Sinatra)
    N/A
  • Environment variables
    N/A

Test code:

def test_match(string)
  if string =~ /(.)/
    $1
  end
end

1000000.times { test_match("a") } 

test_match("b")

Expected Behavior

  • function test_match call always returns value (as in Ruby MRI or if match is used instead of =~):
jruby-9.2.5.0 :026 > test_match("b")
 => "b"

Actual Behavior

After some iterations returned result always is nil:

jruby-9.2.5.0 :009 > test_match("b")
 => nil
jruby-9.2.5.0 :010 > test_match("b")
 => nil

Full console output:
test_script.log

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions