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

Regression: java.net.URL.getContent() works wrong

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.6



      Name: dfC67450 Date: 12/07/99



      If we call getContent() method of URL, read the byte from returned InputStream,
      close this stream and then call getContent() again we will get new InputStream
      but different with the first one.

      Note: To get the same stream after closing we can
      insert Thread.sleep(10000) before second invoÓation of getContent().


      Here is the test demonstrating the bug:

      ---------------------------------------------

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

      public class URLTest {
          public static void main (String args[]){

              try {
          
                  if (args.length == 0) {
                      System.out.println("url parameter required");
                      return;
                  }
          
                  URL url = new URL(args[0]);
                  System.out.println("url: " + url);
                  Object obj = url.getContent();
                  int c1 = ((InputStream) obj).read();
                  ((InputStream)obj).close();
                  // Thread.sleep(10000);
                  obj = url.getContent();
                  int c2 = ((InputStream) obj).read();
          
                  if ( c1 != c2) {
                      System.out.println(c1 + " != " + c2);
                      System.out.println("Test failed");
                      return;
                  }
          
              } catch (Exception e) {
                  System.out.println("Unexpected exception:" + e);
                  return;
              }
          
              System.out.println("Test passed");
              return;

          }
      }
      ------------- output for N, O, P builds of JDK 1.3.0 ---------
      #> java URLTest http://javaweb.eng/sqe/index.html
      url: http://javaweb.eng/sqe/index.html
      60 != 112
      Test failed
      ------------- output for JDK builds 1.3.0-L, 1.2.2-W -------------------
      #> java URLTest http://javaweb.eng/sqe/index.html
      url: http://javaweb.eng/sqe/index.html
      Test passed
      ----------------------------------------------------------

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

            shihliu Sharon Liu (Inactive)
            fdasunw Fda Fda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: