Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutating result of Module#to_s changes Module#to_s on JRuby 9.2 #5229

Closed
ivoanjo opened this Issue Jun 23, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@ivoanjo
Copy link
Contributor

ivoanjo commented Jun 23, 2018

Hello there!

I've found this one while adding JRuby 9.2 to concurrent-ruby's travis CI config, see ħere and ruby-concurrency/concurrent-ruby#733 .

Environment

  • JRuby: jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.71-b00 on 1.8.0-internal-jenkins_2017_07_04_16_04-b00 [linux-x86_64]
  • Kernel: Linux maruhime 4.13.0-45-generic #50-Ubuntu SMP Wed May 30 08:23:18 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Distro: Ubuntu 17.10

Expected Behavior

On MRI when getting the to_s of a class or module, the resulting string is a copy and so is safe to be mutated at will, and changing it will have no impact on the to_s of the class/module.

Testcase:

puts RUBY_DESCRIPTION

class A
end

A.to_s.downcase!

puts A.to_s

MRI output:

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
A

Actual Behavior

On JRuby 9.2, mutating the result of to_s wrongly changes the actual to_s of the class/module.

JRuby output:

jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.71-b00 on 1.8.0-internal-jenkins_2017_07_04_16_04-b00 [linux-x86_64]
a 

@kares kares added this to the JRuby 9.2.1.0 milestone Jun 24, 2018

@headius

This comment has been minimized.

Copy link
Member

headius commented Jun 25, 2018

Yeah probably an easy fix; just clone it. Though I'd argue it should be returning an immutable string instead.

@headius

This comment has been minimized.

Copy link
Member

headius commented Jun 25, 2018

s/clone/dup

@kares kares closed this in #5231 Jun 26, 2018

ivoanjo added a commit to ivoanjo/concurrent-ruby that referenced this issue Jul 6, 2018

Workaround struct inspect bug on JRuby 9.2.0.0
Due to a bug in JRuby 9.2.0.0, mutating the result of `Module#to_s`
actually changes the result of other `Module#to_s` calls to the same
module or class, rather than returning a new `String`.

This broke `AbstractStruct#pr_underscore` which is used when rendering
`#inspect` for structures.

This was already fixed upstream, but as a workaround, let's dup the
String before we mutate it, so as to not trip anyone using this JRuby
version (and to restore Travis to beautiful green).

Issue jruby/jruby#5229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.