[JAVA-2220] Calls to new ServerAddress(InetAddress) fail with numeric IPv6 addresses Created: 10/Jun/16  Updated: 19/Oct/16  Resolved: 10/Oct/16

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: 3.2.2
Fix Version/s: 3.4.0-rc1, 3.4.0

Type: Bug Priority: Major - P3
Reporter: Mark Paluch Assignee: Ross Lawley
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to JAVA-2245 MongoClient Instantiation Using IPV6 ... Closed

 Description   

Constructing a ServerAddress using IPv6 InetAddress fails if the specified IP address resolves to its address (i.e. no reverse host mapping).

ServerAddress assumes that IPv6 addresses are always specified in brackets which isn't the case for IPv6 addresses without reverse host mapping.

Stack trace:

com.mongodb.MongoException: host and port should be specified in host:port format
 
	at com.mongodb.ServerAddress.<init>(ServerAddress.java:122)
	at com.mongodb.ServerAddress.<init>(ServerAddress.java:58)

Test case:

import static org.junit.Assert.*;
import java.net.InetAddress;
import org.junit.Test;
import com.mongodb.ServerAddress;
 
public class ServerAddressUnitTests {
 
	@Test
	public void hostAndPortStringIPv6AddressShouldWork() throws Exception {
 
		ServerAddress serverAddress = new ServerAddress("[dead:beef:affe::1]:27017");
 
		assertEquals(27017, serverAddress.getPort());
		assertEquals("dead:beef:affe::1", serverAddress.getHost());
	}
 
	@Test
	public void hostAndPortIPv6AddressShouldWork() throws Exception {
 
		ServerAddress serverAddress = new ServerAddress("[dead:beef:affe::1]", 27017);
 
		assertEquals(27017, serverAddress.getPort());
		assertEquals("dead:beef:affe::1", serverAddress.getHost());
	}
 
	@Test
	public void inetAddressIPv6AddressShouldWork() throws Exception {
 
		ServerAddress serverAddress = new ServerAddress(InetAddress.getByName("dead:beef:affe::1"));
 
		assertEquals(27017, serverAddress.getPort());
		assertEquals("dead:beef:affe::1", serverAddress.getHost());
	}
 
	@Test
	public void inetAddressAndPortIPv6AddressShouldWork() throws Exception {
 
		ServerAddress serverAddress = new ServerAddress(InetAddress.getByName("dead:beef:affe::1"), 27017);
 
		assertEquals(27017, serverAddress.getPort());
		assertEquals("dead:beef:affe::1", serverAddress.getHost());
	}
}



 Comments   
Comment by Githook User [ 10/Oct/16 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Improve support for IPv6 addresses (#167)

Add support for IPv6 addresses defined without square brackets.
JAVA-2220
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/0b4a4c15f03259fda61f9310ffb61a1c3afe17e4

Comment by Ross Lawley [ 10/Oct/16 ]

PR: https://github.com/rozza/mongo-java-driver/pull/167

Generated at Thu Feb 08 08:56:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.