• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getSingleResult returns NPE

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a query and it can return nulls for each row:



Unfortunately, the program interrupts the methods and returns a NullPointerException, when myQuery returns null. How can I handle that? You can see, I have a NoResultException which also returns null, when no results are found. But it does not prevent from causing a NPE.

I know, I can catch it with catch (NullPointerException ex), but what is the sense of NoResultException, when it cannot catch the NullPointerException implicitly??

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just don't chain your method calls. e.g:



 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic