Name: dfR10049 Date: 09/17/2002
Javadoc states for java.net.InetAddress.getByAddress(String host, byte[] addr):
For host specified in literal IPv6 address, either the form defined in RFC 2732
or the literal IPv6 address format defined in RFC 2373 is accepted.
But getByAddress(String host, byte[] addr) does not check for the format of 'host'.
It allows to create InetAddress with "1234::2345::3456" hostname.
The following test demonstrates the bug:
--------- Test.java ----------
import java.net.*;
public class Test {
public static void main(String args[]) {
String host = "1234::2345::3456";
byte[] addr = { 0,1,2,3, 4,5,6,7, 8,9,10,11, 12,13,14,15};
try {
InetAddress testAddr = InetAddress.getByAddress(host, addr);
System.out.println("Test failed with: " + host);
System.out.println("Created: " + testAddr);
} catch( UnknownHostException e ) {
System.out.println("Test passed");
}
}
}
-----------------------------------------
output from the test:
#> java Test
Test failed with: 1234::2345::3456
Created: 1234::2345::3456/1:203:405:607:809:a0b:c0d:e0f
I see two possible ways this bug may be fixed:
- getByAddress(host, addr) will check the format of 'host'
- assertion about acceptable hosts will be removed from spec
======================================================================