Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8086015

Different return value of InetAddress.getLocalHost().getHostName() between JRE 7

XMLWordPrintable




      We found that the return value of InetAddress.getLocalHost().getHostName() in
      JRE 8 is different with JRE 7. Our OS is Solaris 10. How does Java determine
      the return value? In JRE 8, how get the same return value as JRE 7?

      Here is a test case:
      import java.net.InetAddress;
      public class t {
         public static void main(String[]args) throws Exception {
             System.out.println(InetAddress.getLocalHost());
             System.out.println(InetAddress.getLocalHost().getHostName());
         }
      }

      In JRE 8, the test result is:

      # java t
      bsm1b-qfe0/192.168.100.26
      bsm1b-qfe0

      In JRE 7, the test result is:

      # /usr/jdk/instances/jdk1.7.0/bin/java t
      cnbjbcmuas76o5/192.168.100.26
      cnbjbcmuas76o5



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

      Orginal /etc/hosts entry:

      192.168.100.26 bsm1b-qfe0 bsm1b cnbjbcmuas76o5 cnbjbcmuas76o5.localdomain
      localunit localunit.localdomain

      After changing the /etc/hosts as
      192.168.100.26 cnbjbcmuas76o5 bsm1b bsm1b-qfe0 cnbjbcmuas76o5.localdomain
      localunit localunit.localdomain

      the result in JRE 8 is same as the result in JRE 7.

      With JRE 8:

      [root@cnbjbcmuas76o5 /tmp]# java t
      cnbjbcmuas76o5/192.168.100.26
      cnbjbcmuas76o5



      With JRE 7:
      [root@cnbjbcmuas76o5 /tmp]# /usr/jdk/instances/jdk1.7.0/bin/java t
      cnbjbcmuas76o5/192.168.100.26
      cnbjbcmuas76o5

            robm Robert Mckenna
            shadowbug Shadow Bug
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: