Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.5
-
Fix Version/s: JRuby 1.6.6, JRuby 1.7.0.pre1
-
Component/s: Core Classes/Modules
-
Labels:None
-
Environment:jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
-
Testcase included:yes
-
Number of attachments :
Description
This is a followup to jruby-673. In MRI, Dir.chdir defaults to $HOME if no directory is specified. That was fixed. However, if $HOME is not set, it should default to $LOGDIR. If neither $HOME nor $LOGDIR are set, it should raise an error with a specific error message. Take a look at dir_s_chdir in dir.c for more information.
test "chdir without an argument defaults to LOGDIR if HOME is not set" do
ENV['HOME'] = nil
ENV['LOGDIR'] = Dir.pwd
Dir.chdir
assert_equal(ENV['LOGDIR'], Dir.pwd)
end
test "chdir raises an error if both the HOME and LOGDIR env variables are nil" do
ENV['HOME'] = nil
ENV['LOGDIR'] = nil
assert_raise(ArgumentError){ Dir.chdir }
assert_raise_message("HOME/LOGDIR not set"){ Dir.chdir }
end
Courtesy of berger_spec. ![]()
I pushed https://github.com/jruby/jruby/commit/5dfa65455ae6ab31c6a3f80c64f970e697e4c86a to partially address this issue. (This can probably be pushed to 1.6 branch, but I didn't.)
The fix is partial, since we look up JVM's system property user.home if ENV["HOME"] is not set. This seems to be a reasonable assumption, and once we have a system property set in JVM, we can't remove it form the command line invocation of the JVM; i.e., jruby -J-Duser.home="" ... doesn't raise the Ruby exception, since JRuby will look for directory named "".
Also, the exception's error message is different. It is an implementation detail for which deviation from MRI is justified, in my opinion.
I'm inclined to resolve this ticket, but I also welcome feedback.