Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor 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 :
      0

      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.

        Activity

        Hide
        Hiro Asari added a comment -

        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.

        $ jruby -ve 'ENV["HOME"]=nil; ENV["LOGDIR"]="/tmp"; Dir.chdir; p Dir.pwd'
        jruby 1.7.0.dev (ruby-1.8.7-p352) (2011-12-22 5dfa654) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
        "/private/tmp"
        $ jruby -ve 'ENV["HOME"]=ENV["LOGDIR"]=nil; Dir.chdir; p Dir.pwd'
        jruby 1.7.0.dev (ruby-1.8.7-p352) (2011-12-22 5dfa654) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
        "/Users/asari"
        $ jruby -J-Duser.home="" -ve 'ENV["HOME"]=ENV["LOGDIR"]=nil; Dir.chdir; p Dir.pwd'
        jruby 1.7.0.dev (ruby-1.8.7-p352) (2011-12-22 5dfa654) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
        Errno::ENOENT: No such file or directory - 
           chdir at org/jruby/RubyDir.java:448
          (root) at -e:1
        

        I'm inclined to resolve this ticket, but I also welcome feedback.

        Show
        Hiro Asari added a comment - 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. $ jruby -ve 'ENV["HOME"]=nil; ENV["LOGDIR"]="/tmp"; Dir.chdir; p Dir.pwd' jruby 1.7.0.dev (ruby-1.8.7-p352) (2011-12-22 5dfa654) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java] "/private/tmp" $ jruby -ve 'ENV["HOME"]=ENV["LOGDIR"]=nil; Dir.chdir; p Dir.pwd' jruby 1.7.0.dev (ruby-1.8.7-p352) (2011-12-22 5dfa654) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java] "/Users/asari" $ jruby -J-Duser.home="" -ve 'ENV["HOME"]=ENV["LOGDIR"]=nil; Dir.chdir; p Dir.pwd' jruby 1.7.0.dev (ruby-1.8.7-p352) (2011-12-22 5dfa654) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java] Errno::ENOENT: No such file or directory - chdir at org/jruby/RubyDir.java:448 (root) at -e:1 I'm inclined to resolve this ticket, but I also welcome feedback.
        Hide
        Hiro Asari added a comment -

        I pushed the change to the 1.6 branch (a09126b).

        I also spoke with Tom; we agree that it is OK to default to user.home in our case. (It is conceivable that the underlying JVM doesn't have the system property, in which case we do throw ArgumentError.)

        Show
        Hiro Asari added a comment - I pushed the change to the 1.6 branch (a09126b). I also spoke with Tom; we agree that it is OK to default to user.home in our case. (It is conceivable that the underlying JVM doesn't have the system property, in which case we do throw ArgumentError.)

          People

          • Assignee:
            Hiro Asari
            Reporter:
            Daniel Berger
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: