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

bugs in HttpUrlConnection with KeepAlive

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.0
    • 1.1.6
    • core-libs
    • kestrel
    • sparc
    • solaris_2.6
    • Verified



      Name: diC59631 Date: 06/10/98


      After closing a http connection to a URL that has KeepAlive set, any attempt to try to connect the same URL or URLs in the same domain results in a NullPointer exception thrown at HttpURLConnection.getHeaderField. I even tried to stop the KeepAlive timer thread before reopen the connection.



      ---------stack dump------------------------------
      java.lang.NullPointerException
              at sun.net.ProgressData.unregister(ProgressData.java:99)
              at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:495)
              at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:416)
              at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:696)
              at UrlBug.main(UrlBug.java:52)

      ---------source code-----------------------------

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

      class UrlBug {

        public static void main(String argv[]) {
          try {
            // get page where server sets Connection: keep-alive
            URL url = new URL("http://www.levi.com/us/");
            HttpURLConnection http = (HttpURLConnection) url.openConnection();
            http.connect();
            System.err.println("If you see keep-alive here: " +
      http.getHeaderField("Connection"));

            BufferedReader r =
      new BufferedReader(new InputStreamReader(http.getInputStream()));
            String line;
            
            while ((line = r.readLine()) != null) {
      System.out.println(line);
            }
            r.close();
            http.disconnect();
            
            // tried to kill the KeepAlive timer thread
            ThreadGroup top_group = Thread.currentThread().getThreadGroup();

            Thread[] threads=new Thread[top_group.activeCount()];
            int num_threads = top_group.enumerate(threads);
            
            for(int j=0;j<num_threads;j++) {
      System.err.println(" The "+j+"th thread is "+threads[j].toString());
      if(threads[j] != Thread.currentThread()) {
      threads[j].stop();
      }
            }
           

            // now get page from same server
            url = new URL("http://www.levi.com/us/top.aspff");
            http = (HttpURLConnection) url.openConnection();
            http.connect();
            System.err.println("And you don't see it here: " +
      http.getHeaderField("Connection")); // this is where the null pointer exception thrown
            // r = new BufferedReader(new InputStreamReader(http.getInputStream()));
            //while ((line = r.readLine()) != null) {
      //System.out.println(line);
            // }
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
      (Review ID: 32633)
      ======================================================================

            jdn Jeffrey Nisewanger (Inactive)
            dindrigo Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: