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

1.7.21: getScriptSource -> isSymLink raises NullPointerException when script source is stdin #3901

Open
bg opened this issue May 18, 2016 · 4 comments

Comments

@bg
Copy link

bg commented May 18, 2016

Hi,

Ever since JRuby 1.7.21, when you specify stdin explicitly as the filepath for the script source, which we do in order to execute a heredoc that takes command line arguments, it results in a NullPointerException in getScriptSource -> isSymLink as detailed below.

Background

We're stuck on JRuby 1.7 for the time being on OpenVMS, as there is only Java 6 for this platform. The issue I'm reporting, however, is not VMS-only, but is also reproducible on Linux.

Environment

The issue is reproducible in all of these JRuby versions:

  • jruby 1.7.25 (ruby-1.8.7p376) 2016-04-13 867cb81 on Java HotSpot(TM) 64-Bit Server VM 1.6.0-6 +jit [OpenVMS-ia64]
  • jruby 1.7.21 (ruby-1.8.7p376) 2015-07-07 a741a82 on OpenJDK 64-Bit Server VM 1.7.0_101-b00 +jit [linux-amd64]
  • jruby 1.7.25 (ruby-1.8.7p376) 2016-04-13 867cb81 on OpenJDK 64-Bit Server VM 1.7.0_101-b00 +jit [linux-amd64]

The issue is not reproducible in these versions:

  • jruby 1.7.20 (ruby-1.8.7p376) 2015-05-04 3086e6a on Java HotSpot(TM) 64-Bit Server VM 1.6.0-6 +jit [OpenVMS-ia64]
  • jruby 1.7.20 (ruby-1.8.7p376) 2015-05-04 3086e6a on OpenJDK 64-Bit Server VM 1.7.0_101-b00 +jit [linux-amd64]
  • Operating system and platform (e.g. uname -a)
    • HP rx2600 (1.50GHz/6.0MB) running OpenVMS V8.4 (ia64)
    • Linux dvis2 3.16.0-4-amd64 break script engine #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64 GNU/Linux

Expected Behavior

In JRuby 1.7.20 on both OSes, this was the previous behaviour when specifying stdin as the script source so that arguments can also be passed to a heredoc script. I have reproduced this in a simple one-liner to illustrate the issue more concisely:

echo "p ARGV" | ruby /dev/stdin a b
["a", "b"]

On VMS, the shell syntax is different, but this is the equivalent construct and it gives the same result under 1.7.20:

pipe write sys$output "p ARGV" | ruby /sys$input a b
["a", "b"]

Actual Behavior

In JRuby 1.7.25 on Linux, this is the result:

$ echo "p ARGV" | ruby /dev/stdin a b
RegularFileResource.java:91:in `isSymLink': java.lang.NullPointerException
        from RubyInstanceConfig.java:415:in `getScriptSource'
        from Main.java:246:in `internalRun'
        from Main.java:217:in `run'
        from Main.java:197:in `main'

The same error occurs in 1.7.25 on OpenVMS ia64, and 1.7.21 on Linux, when the regression seems to have been introduced.

Impact & Workaround

The impact on us is minimal. We only have one occurrence of the failing construct, and we can easily work around it by passing the arguments to the heredoc ruby script from DCL (OpenVMS default shell) by setting environment variables, read by the heredoc script through ENV.

Thanks,
Ben

@headius
Copy link
Member

headius commented May 18, 2016

So the problem here is that isSymlink – called by RubyInstanceConfig.getScriptSource after it realizes /dev/stdin is not a regular file – tries to use a null POSIX instance to call lstat. This failure is reproducible on OS X with both 1.7 and 9k.

The fix seems to be pretty simple: use the pure-Java POSIX. The behavior of lstat won't be as correct, but it should still generally work well enough for isSymLink.

Might be a weird one to write a test for, though :-)

@bg
Copy link
Author

bg commented May 18, 2016

That commit didn't do it for me, unfortunately. Tested on Linux:

bg@dvis2:~$ rvm jruby-1.7.20
bg@dvis2:~$ echo "p ARGV" | ruby /dev/stdin a b
["a", "b"]
bg@dvis2:~$ rvm jruby-head
bg@dvis2:~$ echo "p ARGV" | ruby /dev/stdin a b
Error opening script file: /dev/stdin (Not a file)
bg@dvis2:~$ ruby --version
jruby 1.7.26-SNAPSHOT (ruby-1.8.7p376) 2016-05-18 9f0e3d9 on OpenJDK 64-Bit Server VM 1.7.0_101-b00 +jit [linux-amd64]

@headius
Copy link
Member

headius commented May 18, 2016

Ok, figured out the additional error: on OS X, /dev/stdin is a symlink for /dev/fd/0, so I pass the isSymLink test in RubyInstanceConfig. If I instead use /dev/fd/0 I can reproduce your error. BIt more work needed!

headius added a commit to headius/jruby that referenced this issue May 18, 2016
Additional fix for issue exposed by jruby#3901. Devices, like ttys,
pipes, fifos and the like may be neither file nor symlink, but
still readable as script source. The restriction here is
unnecessary.
@headius
Copy link
Member

headius commented May 18, 2016

Note that 9k still needs a fix after d0325d9 and #3902 since 1.7 doesn't merge cleanly to master right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants