JDK-8273402 : Use derived NamingExceptions in com.sun.jndi.ldap.Connection#readReply
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: javax.naming
  • Affected Version: 8,11
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2021-09-06
  • Updated: 2021-09-24
  • Resolved: 2021-09-10
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 18
18 b15Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Any OS, Java 8, 11

A DESCRIPTION OF THE PROBLEM :
When an LDAP operation fails for technical reasons (read timeout, broken connection) the aforemetioned class will unfortunately use a general NamingException to signal this to client code. The client code has no way to distinguish this from other NamingExceptions. The CommunicationException has been especially designed for this:
  * This exception is thrown when the client is
  * unable to communicate with the directory or naming service.
  * The inability to communicate with the service might be a result
  * of many factors, such as network partitioning, hardware or interface problems,
  * failures on either the client or server side.
  * This exception is meant to be used to capture such communication problems.

The RFE is to turn:
        if (result == null) {
            throw new NamingException(String.format(TIMEOUT_MSG_FMT, millis));
        }
        // Unexpected EOF can be caused by connection closure or cancellation
        if (result == EOF) {
            throw new NamingException(CLOSE_MSG);
        }
into
        if (result == null) {
            throw new CommunicationException(String.format(TIMEOUT_MSG_FMT, millis));
        }
        // Unexpected EOF can be caused by connection closure or cancellation
        if (result == EOF) {
            throw new CommunicationException(CLOSE_MSG);
        }

which will give the client a change to recover from by retry the operation because it did not fail for LDAP reasons.

This has been reported with Apache Tomcat: https://www.mail-archive.com/users@tomcat.apache.org/msg138297.html



Comments
Requested the submitter verify the fix by downloading the latest version of JDK 18 from https://jdk.java.net/18/
23-09-2021

Changeset: c464f090 Author: Aleksei Efimov <aefimov@openjdk.org> Date: 2021-09-10 14:15:45 +0000 URL: https://git.openjdk.java.net/jdk/commit/c464f09056c239f701b400a5c59c54646f840391
10-09-2021

The exception type needs to be changed in com.sun.jndi.ldap.Connection#readReply (and LdapRequest#getReplyBer(long) needs to be modified too) - only throwing `CommunicationException` from `getReplyBer` for all possible failures is not possible: if request is timed out or closed - it needs to be abandoned; if cancelled - no need to abandon it. It won't change the functionality proposed in this RFE - the CommunicationException will be thrown in all cases. Just updated title to reflect that.
09-09-2021

Moved to JDK for more evaluations of throwing the enhanced exceptions.
07-09-2021