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

Redirecting $stdout to an object fails with: Errno::EBADF: Bad file descriptor - Bad file descriptor #2373

Closed
headius opened this Issue Dec 29, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@headius
Member

headius commented Dec 29, 2014

From http://jira.codehaus.org/browse/JRUBY-7051

Note that the given script (at bottom) now produces NPE when run.

What steps will reproduce the problem?
Run the attached script test.rb

What is the expected output? What do you see instead?
I would expect output to be redirected like in MRI.

Additional information

jruby 1.6.7.2
Errno::EBADF: Bad file descriptor - Bad file descriptor
(root) at test.rb:14

jruby 1.6.7.2 --1.9
Errno::EBADF: Bad file descriptor - Bad file descriptor
(root) at test.rb:14

jruby 1.7.1 (1.9.3p327)
Errno::EBADF: Bad file descriptor - Bad file descriptor
(root) at test.rb:14

jruby 1.7.2.dev (1.9.3p327) 2013-01-02 (rvm install jruby-head) fffffff on Java HotSpot(TM) 64-Bit Server VM 1.6.0_37-b06-434-11M3909 [darwin-x86_64]
Errno::EBADF: Bad file descriptor - Bad file descriptor
(root) at test.rb:14

ruby 1.9.3-p194
I, [2013-01-02T14:10:19.076856 #53379] INFO -- : INTERCEPTED: Should be intercepted
I, [2013-01-02T14:10:19.077363 #53379] INFO -- : INTERCEPTED:

Should not be intercepted

ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]
I, [2013-01-02T14:14:51.521904 #53685] INFO -- : INTERCEPTED: Should be intercepted
I, [2013-01-02T14:14:51.553957 #53685] INFO -- : INTERCEPTED:

Should not be intercepted

Script from original issue: https://gist.github.com/headius/e0ecd58485e2b4ca4938

@headius headius added this to the JRuby 1.7.19 milestone Dec 29, 2014

@enebo enebo modified the milestones: JRuby 1.7.19, JRuby 1.7.20 Jan 28, 2015

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius May 4, 2015

Member

This is confirmed working properly on master (9k) but still broken in JRuby 1.7. Because the original report was so long ago and it works on the newer branch, I'm going to mark this fixed in 9k.pre2.

Member

headius commented May 4, 2015

This is confirmed working properly on master (9k) but still broken in JRuby 1.7. Because the original report was so long ago and it works on the newer branch, I'm going to mark this fixed in 9k.pre2.

@headius headius closed this May 4, 2015

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius May 4, 2015

Member

Finished my backlog so I'm looking at this :-)

The NPE is caused by our $stdout assignment logic, which sees that the incoming object is an IO, so it tries to treat it like an IO. However, it has not been initialized with proper streams and is not really a functional IO in any way other than that it has a working #write method.

This sort of masquerading as a native class will always lead to trouble, especially when you're short-circuiting the initialization process and preventing the superclass from properly setting the object up. I dare say this is also a violation of LSP, since the reporter's specialized IO subclass could no longer be fully functional as an IO.

Nevertheless, we shouldn't fail to hook up the fake stream here, and I'll see if I can't improve that.

Member

headius commented May 4, 2015

Finished my backlog so I'm looking at this :-)

The NPE is caused by our $stdout assignment logic, which sees that the incoming object is an IO, so it tries to treat it like an IO. However, it has not been initialized with proper streams and is not really a functional IO in any way other than that it has a working #write method.

This sort of masquerading as a native class will always lead to trouble, especially when you're short-circuiting the initialization process and preventing the superclass from properly setting the object up. I dare say this is also a violation of LSP, since the reporter's specialized IO subclass could no longer be fully functional as an IO.

Nevertheless, we shouldn't fail to hook up the fake stream here, and I'll see if I can't improve that.

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius May 4, 2015

Member

With the NPE fixed, it appears JRuby 1.7 actually does the right thing now too. Hooplah!

[] ~/projects/jruby-1.7 $ jruby ../jruby/blah.rb
I, [2015-05-04T15:19:55.640000 #14373]  INFO -- : INTERCEPTED: Should be intercepted
I, [2015-05-04T15:19:55.837000 #14373]  INFO -- : INTERCEPTED: 

Should not be intercepted
Member

headius commented May 4, 2015

With the NPE fixed, it appears JRuby 1.7 actually does the right thing now too. Hooplah!

[] ~/projects/jruby-1.7 $ jruby ../jruby/blah.rb
I, [2015-05-04T15:19:55.640000 #14373]  INFO -- : INTERCEPTED: Should be intercepted
I, [2015-05-04T15:19:55.837000 #14373]  INFO -- : INTERCEPTED: 

Should not be intercepted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment