java.net.URL.openStream() throws UnknownHostException when java.exe is used

XMLWordPrintable

    • Type: Bug
    • Resolution: Cannot Reproduce
    • Priority: P4
    • None
    • Affects Version/s: 6
    • Component/s: core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_01"
      Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      java.net.URL.openStream() throws java.net.UnknownHostException when java.exe is used. The problem doesn't happen when javaw.exe is used.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile the example from Java Tutorial:

      import java.net.*;
      import java.io.*;

      public class URLReader {
        public static void main(String[] args) throws Exception {
          URL yahoo = new URL("http://www.yahoo.com/");
          BufferedReader in = new BufferedReader(
                new InputStreamReader(
                yahoo.openStream()));

          String inputLine;

          while ((inputLine = in.readLine()) != null) {
              System.out.println(inputLine);
          }
          in.close();
        }
      }

      2. Open Command Prompt.

      3. Run it with java.exe:
      <JAVA_HOME>\bin\java.exe URLReader > java.log

      4. Run again with javaw.exe:
      <JAVA_HOME>\bin\javaw.exe URLReader > javaw.log

      Result:

      java.log is 0 byte. The stack trace is printed on the console when java.exe is used.

      javaw.log contains the index.html of www.yahoo.com. There is no stack trace when javaw.exe is used.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The home page of www.yahoo.com is printed on the console.
      ACTUAL -
      No output. Stack trace is printed instead.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.net.UnknownHostException: www.yahoo.com
              at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
              at java.net.Socket.connect(Socket.java:519)
              at java.net.Socket.connect(Socket.java:469)
              at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
              at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
              at sun.net.www.http.HttpClient.openServer(HttpClient.java:515)
              at sun.net.www.http.HttpClient.&lt;init&gt;(HttpClient.java:233)
              at sun.net.www.http.HttpClient.New(HttpClient.java:306)
              at sun.net.www.http.HttpClient.New(HttpClient.java:318)
              at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLC
      onnection.java:792)
              at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
      ction.java:733)
              at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
      .java:658)
              at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
      nection.java:981)
              at java.net.URL.openStream(URL.java:1009)
              at URLReader.main(URLReader.java:7)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.net.*;
      import java.io.*;

      public class URLReader {
        public static void main(String[] args) throws Exception {
          URL yahoo = new URL("http://www.yahoo.com/");
          BufferedReader in = new BufferedReader(
                new InputStreamReader(
                yahoo.openStream()));

          String inputLine;

          while ((inputLine = in.readLine()) != null) {
              System.out.println(inputLine);
          }
          in.close();
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No known workaround.

            Assignee:
            Jean-Christophe Collet (Inactive)
            Reporter:
            Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: