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

URLConnection.getContent() throws NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.2, 1.3.0
    • core-libs
    • beta
    • generic, x86
    • generic, windows_nt



      Name: skT88420 Date: 10/06/99


      URLConnection.getContent() throws a NullPointerException when URLConnection.getContentType() returns a null value. I am using jdk 1.2.2 on Windows NT sp5, and performing a standard http download operation. This bug appears similar to 4229488, which was fixed in 1.2.2. This bug is still a problem with jdk 1.2.2.

      Here is the error message:
      java.lang.NullPointerException
         at java.net.URLConnection.stripOffParameters(URLConnection.java:961)
         at java.net.URLConnection.getContentHandler(URLConnection.java:929)
         at java.net.URLConnection.getContent(URLConnection.java:560)

      I looked at the source code for the java.net.URLConnection class and think I have found the problem.

      URLConnection.getContentHandler calls stripOffParameters like this (URLConnection.java line 929):

      String contentType = stripOffParameters(getContentType());

      stripOffParameters in turn calls indexOf on the String object passed to it without checking to make sure the String is non-null, as seen here (URLConnection.java line 959):

          private String stripOffParameters(String contentType)
          {
      int index = contentType.indexOf(';');

      if (index > 0)
      return contentType.substring(0, index);
      else
      return contentType;
          }

      When the String contentType is null, a NullPointerException is thrown.
      (Review ID: 96104)
      ======================================================================

            michaelm Michael McMahon
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: