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

NPE from RubyUDPSocket.java:483:in `doReceiveMulticast' #619

Closed
ghost opened this issue Mar 31, 2013 · 3 comments
Closed

NPE from RubyUDPSocket.java:483:in `doReceiveMulticast' #619

ghost opened this issue Mar 31, 2013 · 3 comments

Comments

@ghost
Copy link

ghost commented Mar 31, 2013

The following code snippet (extracted from test/test_socket.rb) will raise java.lang.NullPointerException:

require 'socket'
require 'ipaddr'

multicast_addr = "225.4.5.6"
port = 6789
recvsock = UDPSocket.new
ip = IPAddr.new(multicast_addr).hton + IPAddr.new("0.0.0.0").hton
recvsock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
msg, info = recvsock.recvfrom(1024)
RubyUDPSocket.java:483:in `doReceiveMulticast': java.lang.NullPointerException
    from RubyUDPSocket.java:407:in `doReceiveTuple'
    from RubyUDPSocket.java:350:in `recvfrom'
    from MethodHandle.java:599:in `invokeWithArguments'
    from InvocationLinker.java:153:in `invocationFallback'
    from /tmp/udp.rb:9:in `__file__'
    from /tmp/udp.rb:-1:in `load'
    from Ruby.java:807:in `runScript'
    from Ruby.java:800:in `runScript'
    from Ruby.java:669:in `runNormally'
    from Ruby.java:518:in `runFromMain'
    from Main.java:390:in `doRunFromMain'
    from Main.java:279:in `internalRun'
    from Main.java:221:in `run'
    from Main.java:201:in `main'
@ghost
Copy link

ghost commented May 23, 2013

Verified this still occurs on latest master:

RubyUDPSocket.java:483:in `doReceiveMulticast': java.lang.NullPointerException
    from RubyUDPSocket.java:407:in `doReceiveTuple'
    from RubyUDPSocket.java:350:in `recvfrom'
    from RubyIPSocket$INVOKER$i$recvfrom.gen:-1:in `call'
    from CachingCallSite.java:326:in `cacheAndCall'
    from CachingCallSite.java:170:in `call'
    from npe.rb:9:in `__file__'
    from npe.rb:-1:in `load'
    from Ruby.java:813:in `runScript'
    from Ruby.java:806:in `runScript'
    from Ruby.java:675:in `runNormally'
    from Ruby.java:524:in `runFromMain'
    from Main.java:390:in `doRunFromMain'
    from Main.java:279:in `internalRun'
    from Main.java:221:in `run'
    from Main.java:201:in `main'

@ghost
Copy link

ghost commented May 23, 2013

So this NPE is caused by the 'multicastSocket' member of RubyBasicSocket's MulticastStateManager being null. The multicaseSocket is assigned only when MulticastStateManager::rebindToPort is called. This, in turn, is called from RubyUDPSocket in send and bind. In the code above, a call to 'bind' should be used before calling recvfrom, but maybe a more helpful exception would be good here?

Specifically, the following does work:

require 'socket'
require 'ipaddr'

multicast_addr = "225.4.5.6"
port = 6789
recvsock = UDPSocket.new
ip = IPAddr.new(multicast_addr).hton + IPAddr.new("0.0.0.0").hton
recvsock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
recvsock.bind(Socket::INADDR_ANY, port)
msg, info = recvsock.recvfrom(1024)

Though it Would Be Nice If (tm) we threw an informative IllegalStateException or something when an unbound socket is used.

For reference, the current ruby-2.0.0 just hangs when presented with an unbound socket calling recvfrom - probably an implementation detail of the underlying sockets library.

@rtyler rtyler added the beginner label Aug 7, 2015
@enebo enebo added this to the Won't Fix milestone Feb 17, 2017
@enebo
Copy link
Member

enebo commented Feb 17, 2017

This works in 9k and we will never fix this in 1.7.x as it is winding down....resolving.

@enebo enebo closed this as completed Feb 17, 2017
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

3 participants