Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.0.0, JRuby 1.0.1, JRuby 1.0.2, JRuby 1.1b1
-
Fix Version/s: JRuby 1.1RC3
-
Component/s: Core Classes/Modules
-
Labels:None
-
Environment:Mac OS X 10.4.10 with Java 1.5, Linux with IBM Java 1.4.2
-
Testcase included:yes
-
Number of attachments :
Description
Attached is a test case that uses backquotes to invoke a Ruby program named 'arguments.' The arguments program prints the contents of ARGV. This test case assumes the ruby and jruby commands are on your path.
Paste of the test case:
require "test/unit"
class BackquotesWithShellRedirectsTest < Test::Unit::TestCase
def test_backquotes_with_redirects_pass_through_shell
assert_equal "arguments: one two", `./arguments one two 2> /dev/null`, "wrong arguments when run straight up"
assert_equal "arguments: three four", `ruby ./arguments three four 2> /dev/null`, "wrong arguments when run with ruby prefix"
assert_equal "arguments: five six", `jruby ./arguments five six 2> /dev/null`, "wrong arguments when run with jruby prefix"
end
end
Paste of the arguments program:
#!/usr/bin/env ruby
print "arguments: #{ARGV.join(' ')}"
This test case passes in MRI. It fails in JRuby, but at different points depending on which version of JRuby you're running. Here are some results.
JRuby 1.0, 1.0.1
fletcher@nugent ~/svn/jruby_bugs $ jruby test_backquotes_with_shell_redirects.rb Loaded suite test_backquotes_with_shell_redirects Started F Finished in 0.2 seconds. 1) Failure: test_backquotes_with_redirects_pass_through_shell(BackquotesWithShellRedirectsTest) [test_backquotes_with_shell_redirects.rb:6]: wrong arguments when run with ruby prefix. <"arguments: three four"> expected but was <"arguments: three four 2> /dev/null">. 1 tests, 2 assertions, 1 failures, 0 errors
JRuby 1.0.2, 1.1b1
fletcher@nugent ~/svn/jruby_bugs $ jruby test_backquotes_with_shell_redirects.rb Loaded suite test_backquotes_with_shell_redirects Started F Finished in 0.132 seconds. 1) Failure: test_backquotes_with_redirects_pass_through_shell(BackquotesWithShellRedirectsTest) [test_backquotes_with_shell_redirects.rb:5]: wrong arguments when run straight up. <"arguments: one two"> expected but was <"arguments: one two 2> /dev/null">. 1 tests, 1 assertions, 1 failures, 0 errors
This particular regression is preventing me from upgrading from JRuby 1.0 to 1.0.2. My acceptance test suite is using the first form of invocation (line 5 of the test case) to run my application, which is sensitive to the passed arguments. I'd rather not change my code to work around incorrect behavior if I don't have to, so I'm going to stick with 1.0 for now.
Attachments
Issue Links
| This issue relates to: | ||||
| JRUBY-2235 | Minor regression: Kernel.system('non-existing-file') produces some output but shouldn't |
|
|
|
I spent a little time looking through JRuby 1.0.2 code; in ShellLauncher.java, it looks like my case is falling in 'don't run in process, don't run in shell' category (line 212). This uses Java's Runtime#exec method to launch the program, which certainly isn't going to interpret shell redirects.
It looks like the reason my case is failing the shouldRunInShell check (line 308) is because the first argument (the program name) does exist. But I'm not clear on what this check is for so I'm not certain.