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

URLConnection.getInputStream() throwing spurious NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.1.7
    • core-libs
    • merlin
    • x86
    • windows_nt



      Name: dbT83986 Date: 03/09/99


      According to the JDK API doc, the getInputStream() method does not
      throw a NullPointerException. However, in actual use, it throws
      this exception about 35% of the time. The code below _should_
      work, but does not work reliably due to NullPointerExceptions:

         URLConnection serverConnection = targetURL.openConnection();
         serverConnection.connect();
         InputStream inStream = serverConnection.getInputStream();



      The code below is a workaround for the problem, retrying getting
      the input stream until it actually succeeds:

         URLConnection serverConnection = targetURL.openConnection();
         serverConnection.connect();
         InputStream inStream = null;
         while (inStream == null)
         {
      try
      {
      inStream = serverConnection.getInputStream();
      }
      catch(NullPointerException ex)
      {
      try
      { Thread.currentThread().sleep(15); }
      catch (Exception e)
      {}
      }
         }
      (Review ID: 55154)
      ======================================================================

            ywangsunw Yingxian Wang (Inactive)
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: