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

InetAddress.getCanonicalHostName may return ip address if reverse lookup fails

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 22
    • None
    • core-libs
    • b11
    • x86_64
    • os_x

    Description

      FULL PRODUCT VERSION:

      java -version
      java version "1.8.0_361"
      Java(TM) SE Runtime Environment (build 1.8.0_361-b09)
      Java HotSpot(TM) 64-Bit Server VM (build 25.361-b09, mixed mode)

      OS VERSION:

      sw_vers
      ProductName: macOS
      ProductVersion: 13.3.1
      ProductVersionExtra: (a)
      BuildVersion: 22E772610a


      A DESCRIPTION OF THE PROBLEM :
      getCanonicalHostName returns ip address in macOS instead of fully qualified domain name.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      Followed these documents to check the macOS machine host name
      https://support.apple.com/en-in/guide/mac-help/mchlp2322/mac
      https://support.apple.com/en-in/guide/mac-help/mh27452/13.0/mac/13.0

      If we verify the macOS machine name it with scutil command we can see the host name.

       scutil --get HostName
      bishnaya-mac
       scutil --get LocalHostName
      bishnaya-mac
       scutil --get ComputerName
      bishnaya-mac

      If we run the below code it returns ip address
      ============code==================
      import java.net.InetAddress;
      import java.net.UnknownHostException;

      public class MachineName {

          public static void main(String arg[]) throws UnknownHostException {

              String canHostName = InetAddress.getLocalHost().getCanonicalHostName();
              System.out.println("Canonical Host Name : "+canHostName);

          }
      }

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

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED - Canonical Host Name : bishnaya-mac
      ACTUAL - Canonical Host Name : ip_address_of_machine


      Attachments

        Issue Links

          Activity

            People

              jpai Jaikiran Pai
              bnayak Bishwa Nayak
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: