United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6698625 InetAddress.getLocalHost() failed in returning chinese local host name
JDK-6698625 : InetAddress.getLocalHost() failed in returning chinese local host name

Details
Type:
Bug
Submit Date:
2008-05-07
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
core-libs
OS:
windows_2003
Sub-Component:
java.net
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
c:>java -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
c:> ver
Microsoft Windows [?????? 5.2.3790]

A DESCRIPTION OF THE PROBLEM :
the InetAddress.getLocalHost()  works fine in jre 1.5.0_03, but fails to fetch chinese local host name in jre 1.6.0_03.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
assume the host name is "????????_????????", which have to be a chinese presenting, and the running os is Windows 2003 Standard Edition with SP2


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
with jre 1.5.0_03, it print like:
host    : ????????_????????
-42 -48 -50 -60 95 -78 -30 -54 -44
it corretly presents my host name
ACTUAL -
with jre 1.6.0_03 , it prints like:
host    : ????_???
63 63 63 63 95 63 63 63


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
     try {
            InetAddress localHost = InetAddress.getLocalHost();
            String hostName = localHost.getHostName();
            
            System.out.println("host\t: " + hostName);
            byte[] bytes = hostName.getBytes();
            for(byte b : bytes){
                System.out.print(b + " ");
            }
            System.out.println();

        } catch (Exception ex) {
            ex.printStackTrace(System.out);
        }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I am going to use this localhost name to get all local IP addr later, but with "????", it is sure to throw java.net.UnknownHostException.

downgrade jre environment to 1.5.

Release Regression From : 5.0u3
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

                                    

Comments
EVALUATION

The native implementation of lookupAllHostAddr incorrectly uses NewStringUTF to convert the platform dependant native string to a jstring. It of course should be invoking the String constructor that will use the platforms character encoding. Actually, this is not even necessary as we already have a reference to the jstring being passed as a parameter to this method. Simply use this reference.
                                     
2008-06-09



Hardware and Software, Engineered to Work Together