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

Inconsistent behavior in com.sun.jndi.ldap.Connection::createSocket

XMLWordPrintable

    • b16
    • Verified

        The method documentation of com.sun.jndi.ldap.Connection::createSocket [0] states:
        "If a timeout is supplied but unconnected sockets are not supported then the timeout is ignored and a connected socket is created."

        This, however does not happen. If a SocketFactory would not support unconnected sockets, it would likely throw a SocketException in SocketFactory::createSocket() [1]. And since the code does not check for this behavior [2], a connection with timeout value through a SocketFactory that does not support unconnected sockets would just always fail with an IOException.

        So we should either make the code adhere to what is documented or adapt the documentation to the actual behavior.

        The current behavior is present since JDK 9, introduced with JDK-8048175. Before, in JDK 8, it was not checked by the code whether the supplied Socket Factory was of type javax.net.SocketFactory at all and the SocketFactory::createSocket() method could be unimplemented which would then lead to a NoSuchMethodException which in turn would make the code try to connect without a timeout. A SocketFactory that would throw a SocketException in SocketFactory::createSocket() was probably never handled correctly in the sense of the documentation.

        [0] https://github.com/openjdk/jdk/blob/3ebe6c192a5dd5cc46ae2d263713c9ff38cd46bb/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java#L281
        [1] https://github.com/openjdk/jdk/blob/6303c0e7136436a2d3cb6043b88edf788c0067cc/src/java.base/share/classes/javax/net/SocketFactory.java#L123
        [2] https://github.com/openjdk/jdk/blob/3ebe6c192a5dd5cc46ae2d263713c9ff38cd46bb/src/java.naming/share/classes/com/sun/jndi/ldap/Connection.java#L336

              clanger Christoph Langer
              clanger Christoph Langer
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: