Java Bugs - URLConnection bug

This code:

URLConnection conn = url.openConnection();
String contentType = conn.getContentType();
works properly for files that exist, but gives a NullPointerException on non-existent files.

Inserting this:

InputStream f = conn.getInputStream();
before the getContentType() gives the proper FileNotFoundException.

Looks like either there are some missing checks, or you need to document that getInputStream() has to be called first.

Back to bugs.
Back to ACME Java.
Back to ACME Labs.