Skip to content

Incorrect case tree selection when comparing long Symbols during compiled Ruby code execution #8421

@jbaiza

Description

@jbaiza

Environment Information

  • JRuby versions 9.4.7.0 till 9.4.9.0 with empty JRUBY_OPTS
  • MacOS Sequoia 15.0.1 with Apple M3 Max
  • Java versions:
    • OpenJDK Runtime Environment (Zulu 8.74.0.17-CA-macos-aarch64) (build 1.8.0_392-b08)
    • OpenJDK Runtime Environment Temurin-11.0.21+9 (build 11.0.21+9)
    • OpenJDK Runtime Environment Zulu17.38+21-CA (build 17.0.5+8-LTS)

Other relevant info you may wish to add:

  • Plain JRuby without any gems

Expected Behavior

Use the following files:

  • test.rb:
class TestClass
  def select_case(a)
    case a
    when :zxcvbnmzxcvbnm
      1
    when :qwertyuiopqwertyuiop
      2
    when :asdfghjklasdfghjkl
      3
    when :a
      4
    when :z
      5
    end
  end
end

puts TestClass.new.select_case(:zxcvbnmzxcvbnm)
puts TestClass.new.select_case(:a)
puts TestClass.new.select_case(:z)
  • test1.rb:
load 'test.class'

Compile the test.rb file using jrubyc test.rb.

Executing both files (test.rb and test1.rb), the same output should be displayed:

1
4
5

Actual Behavior

When the ruby file is executed using jruby test.rb, the expected lines are printed.
When the compiled class via the test1.rb file is executed using jruby test1.rb, the output is:

1
4

During our testing, we found that different symbol lengths gave different results. We faced this issue in our compiled app on customer environments where, in most cases, app restart fixes the issue.

A similar issue was previously #8157, but the sample test in it works with the latest versions.

If a quick fix isn't available for the issue, maybe there are recommendations on what we should avoid in case statements to bypass the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions