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

Socket.pack_sockaddr_in fails for nil port (MRI doesn't) #3156

Closed
grddev opened this Issue Jul 21, 2015 · 0 comments

Comments

Projects
None yet
3 participants
@grddev
Copy link
Contributor

commented Jul 21, 2015

JRuby raises a TypeError when the port is nil, whereas MRI treats nil the same way as zero.

> ruby-2.2.2 -rsocket -e 'p Socket.pack_sockaddr_in(nil, "127.0.0.1")'
"\x10\x02\x00\x00\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"

> jruby-1.7.19 -rsocket -e 'p Socket.pack_sockaddr_in(nil, "127.0.0.1")'
TypeError: no implicit conversion from nil to integer
  pack_sockaddr_in at org/jruby/ext/socket/RubySocket.java:272
            (root) at -e:1

I'm using 1.7.19 in my example, but it seems the code in SocketUtils hasn't changed since 2012 in master, so I'm guessing it still applies to both 1.7.x and 9k. See https://github.com/jruby/jruby/blame/26d0b20ca324d082468bbcbc9d71709b142aa77b/core/src/main/java/org/jruby/ext/socket/SocketUtils.java#L131-L140

reuben-sutton added a commit to reuben-sutton/jruby that referenced this issue Aug 3, 2015

treat port nil as 0 for pack_sockaddr_in
Ensure compatability with MRI Ruby

closes jruby#3156

@kares kares closed this in #3219 Aug 6, 2015

@enebo enebo added this to the JRuby 1.7.22 milestone Aug 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.