Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4480267

ServerSocket.getInetAddress spec misleading

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 1.4.1
    • Component/s: docs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      hopper
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description


      j2se 1.4 beta ServerSocket spec states:

      ------------------------------------------------------
      public InetAddress getInetAddress()
      Returns the local address of this server socket.
      Returns: the address to which this socket is connected, or null if the
      socket is not yet connected.
      ------------------------------------------------------

      This spec is misleading since it is not defined what is "connected"
      for ServerSocket and what is address, to which ServerSocket may be
      connected.

      These words could be understood in the way that ServerSocket.getInetAddress
      must return null if there is no client connections made and ServerSocket
      does not wait for connection. Other possible explanation is that "connected"
      is typo in the spec and "bound" should be used instead. In this case, null
      return is only possible for unbound ServerSocket, that can be only created
      by ServerSocket() constructor. However this constructor appeared only in
      jdk1.4,
      while spec for getInetAddress allows null return since first editions.
      It would also help if spec will clearly state that if other constructors may
      create unbound ServerSocket.
      >From the other point, ServerSocket spec says:
      "The actual work of the server socket is performed by an instance
      of the SocketImpl class."
      If we look at SocketImpl.getInetAddress to find what
      ServerSocket.getInetAddress
      should return, we find:
      ------------------------------------------------------
      protected InetAddress address
                The IP address of the remote end of this socket.
      ...
      protected InetAddress getInetAddress()
      Returns the value of this socket's address field.
      ------------------------------------------------------
      Current ServerSocket.getInetAddress specification does not exaplain what
      InetAddress should be returned by ServerSocket.getInetAddress and when
      this method may return null.
      Here is excerpt from the licensee-support's request:
      > > One of my licensees has run into a problem with two of the
      > > PJCK tests. The tests appear to be correct in relation to the spec, but
      > > the code within them looks to be incorrect.
      > >
      > > ServerSocket1033 and ServerSocket2005 are not correct.
      > > These tests try to compare the server bounded address and the address to
      > > which the server is connected.
      > >
      > > the source code is :
      > >
      > > InetAddress sin = InetAddress.getLocalHost ();
      > > ServerSocket server = new ServerSocket (port, backlog, sin);
      > > if (sin.equals (server.getInetAddress ())) // <<-- not correct
      > > return OKAY;
      > >
      > > getInetAddress () : this method returns the address to which this server
      > > socket is connected, or null if the socket is not yet connected.
      > > sin : the local address to which the server socket is bound.
      > >
      > > is it correct ?

        Attachments

          Activity

            People

            Assignee:
            shommel Scott Hommel (Inactive)
            Reporter:
            avpsunw Avp Avp (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: