We have a method that is used to read a BLOB out of an Oracle database, and often a NullPointerException is caught even when everything seems to work right. It's almost like a false alarm error message when we see another "Error retrieving image" show up in Tomcat's catalina.out log. Here's the complete method in question:
public java.io.InputStream getDefaultLabel(String orderNbr) {
String result = null;
DBPoolAccess oDB = new DBPoolAccess();
ResultSet oRS;
java.io.BufferedInputStream in = null;
oRS = oDB.loadPreparedStatement("SELECT MAINIMAGE FROM IMAGES WHERE ORDERNBR = ?", orderNbr);
if (oRS != null) {
try {
if (oRS.next()) {
Blob blob = oRS.getBlob(1);
in = new java.io.BufferedInputStream(blob.getBinaryStream());
}
}
catch (Exception e) {
System.out.println("Error retrieving image #" + orderNbr +
": " + e);
}
}
oDB.closeCon(); // whether ResultSet was null or not, close this
return in;
}
Typically, the image is built with Java code and then written to the database and then immediately the user is directed to a webpage whose HTML is streamed out by one servlet, and the <img> tag on the page references another servlet that calls the above method to stream the image down to the user.
We are seeing this error message pop up even though the image is showing up properly in the browser, and the exception reported is always a NullPointerException. Any idea as to why we're seeing a NullPointerException even though everything seems to be working as expected?