FULL PRODUCT VERSION :
java version "1.6.0_07"
ADDITIONAL OS VERSION INFORMATION :
Linux cc.server 2.6.11-uni #1 Sat Jan 29 07:47:43 GMT 2011 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When I have my hostname set to max length, InetAddress.getLocalHost().getCanonicalHostname() always returns 'localhost'.
If I have hostname less than maximum allowed characters, it works fine.
In my system, maximum hostname length is 64 chars. (I got this from getconf HOST_NAME_MAX)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) set your hostname to a string which has less than HOST_NAME_MAX chars (run command 'hostname <string>')
2) Run Java program to print out InetAddress.getLocalHost().getHostName()
3) Verify that output is correct, it prints out whatever you set as hostname
4) set hostname to a string with exactly HOST_NAME_MAX length (by running hostname command)
5) Run Java program to print out InetAddress.getLocalHost().getHostName()
6) Now program prints out just 'localhost' and not what you set by running hostname command
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
InetAddress.getLocalHost().getHostName() should return hostname even when hostname is of max length
ACTUAL -
InetAddress.getLocalHost().getHostName() returns just localhost when hostname is of max length
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String s[]) throws Exception {
System.out.println(InetAddress.getLocalHost().getHostName());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Work around is to always set hostname to less than max allowed length.