JDK-6774166 : ServerSocket.accept().getInetAddress() sometimes returns null
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6u12
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris
  • CPU: x86
  • Submitted: 2008-11-20
  • Updated: 2010-07-29
  • Resolved: 2009-01-06
Related Reports
Relates :  
Description
Using Netbeans 6.5rc2 for Java EE, with GlassFish ur2v2, in which petstore is deployed.
While pointing jvisualvm to the local GlassFish process (local attach) - I could sometimes see an exception in GlassFish log file.
When running glassfish on 6u12 - I could see an NullPointerException in the glassfish log file - and  jvisualvm was not able to display GlassFish threads (thread information are obtained through JMX)
The problem occurs intermitently, and prevents jvisualvm to connect to the target application server using the attach API.

The root cause of the problem seems to be that sometime, for some reason, 
the Socket created on the server (glassfish) side to handle incomminng
JMX RMI connections has a null remote InetAddress:

RMI TCP Accept-0: accept loop for ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=53246] throws
java.lang.NullPointerException
        at sun.management.jmxremote.LocalRMIServerSocketFactory$1.accept(LocalRMIServerSocketFactory.java:40)
        at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:369)
        at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:341)
        at java.lang.Thread.run(Thread.java:619)

In the LocalRMIServerSocketFactory the remoteAddr variable returned by the forelast
line in the code snippet below is null:

    public ServerSocket createServerSocket(int port)
       throws IOException {
        return new ServerSocket(port) {
            @Override
            public Socket accept() throws IOException {
                Socket socket = super.accept();
                InetAddress remoteAddr = socket.getInetAddress();
                if (remoteAddr.isAnyLocalAddress()) {

This problem occurred several times - but not always. If you restart the glassfish appserver it may go away - or remain. 
It looks as if the socket returned by accept() is not always fully initialized?

Note: the code of the LocalRMIServerSocketFactory changed between 6u11 and 6u12.
On 6u11 you get an IOException instead - saying that the remoteAddr is not a local address. It is difficult to assert that this happens because the remoteAddr is null, but I suspect as much,  so this problem (ServerSocket.accept().getInetAddress()) 
is probably older.

Comments
EVALUATION Closing this bug as it appears it's not a JDK bug.
06-01-2009

EVALUATION From the description, and an out of band exchange with Daniel, that this only happens with Glassfish. It may be that Glassfish has its own socket factory that is the cause of this. We have the engineer responsible for this area of Glassfish to see if we can get more information. The JMX/agent should not need to workaround this.
22-11-2008