• Post Reply Bookmark Topic Watch Topic
  • New Topic

false NullPointerException when reading Blob from database?

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:




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?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what does the stack trace look like? One of the lines in the trace should refer to the getDefaultLabel() method above - look at the line number. Which line in the above code is throwing the exception?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, I see you're not actually printing the stack trace when you catch the exception. Which makes it hard to get more information about it. Add a line in the catch block:

If you were using a logging system like java.util.logging or log4j, that would be an even better way to report the stack trace. But printStackTrace() is certainly better than nothing...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!