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)
======================================================================
- duplicates
-
JDK-4361068 Uncatched null pointer in URLConnection.getContent()
-
- Closed
-