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

Dir.home is no longer compatible with CRuby after JRuby 9.3 #7735

Closed
h-r-k-matsumoto opened this issue Mar 25, 2023 · 3 comments · Fixed by #7738
Closed

Dir.home is no longer compatible with CRuby after JRuby 9.3 #7735

h-r-k-matsumoto opened this issue Mar 25, 2023 · 3 comments · Fixed by #7738
Milestone

Comments

@h-r-k-matsumoto
Copy link

h-r-k-matsumoto commented Mar 25, 2023

Environment Information

JRuby version:
jruby 9.4.2.0 (3.1.0) 2023-03-08 90d2913 OpenJDK 64-Bit Server VM 25.362-b09 on 1.8.0_362-b09 +jit [x86_64-linux]

Operating system and platform:
Linux 96d20f512b68 5.15.0-67-generic #74-Ubuntu SMP Wed Feb 22 14:14:39 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

I use docker images jruby:9.4 and jruby:9.3

Expected Behavior

Dir.home with nil returns home directory of current user.
I expect JRuby to be the same behavior.

$ docker run -it --rm ruby:3.2
irb(main):001:0> Dir.home nil
=> "/root"
irb(main):002:0>

https://ruby-doc.org/3.2.1/Dir.html#method-c-home

Actual Behavior

After JRuby 9.3, Dir.home returns an error if user is nil.

$ docker run -it --rm jruby:9.4
irb(main):001:0> Dir.home nil
org/jruby/RubyDir.java:635:in `home': no implicit conversion of nil into String (TypeError)
	from (irb):1:in `evaluate'
	from org/jruby/RubyKernel.java:1143:in `eval'
	from org/jruby/RubyKernel.java:1586:in `loop'
	from org/jruby/RubyKernel.java:1292:in `catch'
	from org/jruby/RubyKernel.java:1292:in `catch'
	from /opt/jruby/lib/ruby/gems/shared/gems/irb-1.4.2/exe/irb:11:in `<main>'
	from org/jruby/RubyKernel.java:1091:in `load'
	from /opt/jruby/bin/irb:23:in `<main>'
irb(main):002:0>
@h-r-k-matsumoto h-r-k-matsumoto changed the title Dir.home is no longer compatible with CRuby after JRuby 9.2 Dir.home is no longer compatible with CRuby after JRuby 9.3 Mar 25, 2023
@h-r-k-matsumoto
Copy link
Author

This changes impact codes such as below.
https://github.com/fakefs/fakefs/blob/v2.4.0/lib/fakefs/dir.rb#L156-L158

@headius
Copy link
Member

headius commented Mar 29, 2023

Reproduced. It seems like we check for a null/nil home dir for the zero-argument form but not for the one-argument form.

static RubyString getHomeDirectoryPath(ThreadContext context, IRubyObject home) {
final Ruby runtime = context.runtime;
if (home == null || home == context.nil) {
IRubyObject ENV_JAVA = runtime.getObject().getConstant("ENV_JAVA");
home = ENV_JAVA.callMethod(context, "[]", RubyString.newString(runtime, user_home, UTF8));
}
if (home == null || home == context.nil) {
home = context.runtime.getENV().op_aref(context, runtime.newString("LOGDIR"));
}
if (home == null || home == context.nil) {
throw runtime.newArgumentError("user.home/LOGDIR not set");
}
return (RubyString) home.dup();
}

@headius
Copy link
Member

headius commented Mar 29, 2023

Introduced by me in a950772. Fix coming.

headius added a commit to headius/jruby that referenced this issue Mar 29, 2023
headius added a commit to headius/jruby that referenced this issue Mar 29, 2023
@headius headius linked a pull request Mar 29, 2023 that will close this issue
@headius headius added this to the JRuby 9.4.3.0 milestone Mar 29, 2023
eregon pushed a commit to ruby/spec that referenced this issue Apr 25, 2023
seven1m pushed a commit to seven1m/ruby_spec that referenced this issue Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants