JDK-8325579 : Inconsistent behavior in com.sun.jndi.ldap.Connection::createSocket
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.naming
  • Affected Version: 11,17,21,22,23
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-02-09
  • Updated: 2024-05-07
  • Resolved: 2024-03-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 21 JDK 22 JDK 23
11.0.24Fixed 17.0.12Fixed 21.0.4Fixed 22.0.2Fixed 23 b16Fixed
Related Reports
CSR :  
Relates :  
Description
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

Comments
Fix request (21u, 17u, 11u) Requesting approval for this consistency fix in the LDAP client. It has a CSR attached that was approved for the backport releases already when we did this in head. Tests pass, both GHA and SAP testing.
07-05-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/2699 Date: 2024-05-06 08:25:43 +0000
06-05-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/2396 Date: 2024-04-11 15:50:23 +0000
11-04-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u-dev/pull/466 Date: 2024-04-05 17:29:55 +0000
05-04-2024

[jdk22u-fix-request] Approval Request from Christoph Langer Requesting approval for this consistency fix in the LDAP client. It has a CSR attached that was approved for the backport releases already when we did this in head. Tests pass, both GHA and SAP testing.
31-03-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk22u/pull/114 Date: 2024-03-25 17:04:21 +0000
25-03-2024

Changeset: 907e30ff Author: Christoph Langer <clanger@openjdk.org> Date: 2024-03-25 16:31:52 +0000 URL: https://git.openjdk.org/jdk/commit/907e30ff00abd6cd4935987810d282f46ec07704
25-03-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/17797 Date: 2024-02-09 21:29:28 +0000
09-02-2024