[JAVA-4963] isIpLiteral check for server address resolution is incorrect Created: 11/May/23  Updated: 28/Oct/23  Resolved: 31/May/23

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: None
Fix Version/s: 4.10.0

Type: Bug Priority: Unknown
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

As part of JAVA-4911, the InetAddressResolver interface was added, and, if configured, the driver is supposed to use it to resolve host names to IP addresses. However, it's not supposed to use it to if the address is an IP literal. To detect this, the driver makes the following check:

    // If this returns true, it's either an IP literal or a malformed hostname.  But either way, skip lookup via resolver
    private boolean isIpLiteral() {
        return getHost().charAt(0) == '[' || Character.digit(getHost().charAt(0), 16) != -1 || (getHost().charAt(0) == ':');
    }

This check is incorrect, as it will treat any host name starting with the characters 'a' through 'f' as IP literals.

Looking at the JDK source more closely, it's not such a simple check to see if a string is an IP literal, as it involves parsing the whole string, and there is also a system property, "jdk.net.allowAmbiguousIPAddressLiterals", which figures into the determination.

But the check in the driver is wrong, so we either need to:

  1. Fully and properly implement the check for IP literals
  2. Delegate that determination to the configured InetAddressResolver.

It was decided to implement the second option



 Comments   
Comment by Githook User [ 31/May/23 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Remove IP literal check for InetAddressResolver (#1120)

JAVA-4963
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/103eb333b89a17b585ad1815f764c03a9b89b052

Generated at Thu Feb 08 09:03:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.