JDK-4748544 : Spec for InetAddress.getByAddress(host,addr) does not go with implementation
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.4.1,5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-09-17
  • Updated: 2017-05-16
  • Resolved: 2003-11-03
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 Availabitlity Release.

To download the current JDK release, click here.
Other
5.0 b28Fixed
Description

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 

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b28 tiger-beta VERIFIED IN: tiger-rc
2004-09-13

EVALUATION Yes, the spec needs to be clarified either way. There is a plan to add some checks in tiger to validite the given hostname, before looking up the name server. This will be worked out in tiger along with other specification issues with InetAddress. ###@###.### 2002-10-28 Actually we need to update the javadoc. There never an intent to do any check in there, or name service lookup for that matter. But this should be specified in the doc. Will do so for Tiger. ###@###.### 2003-06-27
2003-06-27