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

Java.net.InetAddress.getLocalHost().getHostName() return the canonical host name

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 8u31
    • core-libs
    • x86
    • linux

      FULL PRODUCT VERSION :
      1.8.0_31

      A DESCRIPTION OF THE PROBLEM :
      Description of the problem:
      Java.net.InetAddress.getLocalHost().getHostName() return the canonical host name instead of the short host name.

      Case:
      OS: Linux.
      Java version: 1.8.0_31
      When running java application with pipe line before the command, Java.net.InetAddress.getLocalHost().getHostName() return canonical host name.
      When running java application without pipe line, Java.net.InetAddress.getLocalHost().getHostName() return the short host name.

      When running the code on java 1.7.0_72, both cases return the short host name.

      My code looks as follow:

                    String host;
                    try
                    {
                           host = InetAddress.getLocalHost().getHostName();
                    }
                    catch (UnknownHostException e)
                    {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                    }


      REGRESSION. Last worked in version 7u75

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_31"
      Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
       - make java application via Linux with
      InetAddress.getLocalHost().getHostName(); command
       - run echo something | ecexute(java application)
       
      InetAddress.getLocalHost().getHostName(); will return the canocinal host name instead of the short host name.

      when run the java application without the pipe line the result wil be as excepted

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      short host name
      ACTUAL -
      canconial host name

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      String host;
                    try
                    {
                           host = InetAddress.getLocalHost().getHostName();
                    }
                    catch (UnknownHostException e)
                    {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                    }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      don't use pipe line

        1. Main.java
          0.5 kB
          Pardeep Sharma

            robm Robert Mckenna
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: