• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Null pointer Exception in in Spring.

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

It seems like NullPointerException is the most common Exception encountered while doing Spring.

I normally solve it by setting the if(x != null){ } condition

Can Any One please help me with an Expert Advice in dealing with Null Pointer Exceptions.

Thanks.


 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NPEs happening a lot happen in all applications. It isn't Spring specific. NPEs is my bane in Java development. I get it a lot, and that was even before I ever used Spring.

But I will say that you just can't get around a NPE happening if an object is set to null and you try to call a method etc.

Practices are

1) check for null before calling the object
2) never leave an object at null
3) Make sure it is set.
4) You can do exception handling with AOP, but that won't stop NPEs or other exceptions, just a nice centralized location for Exception Handling.

Mark
 
Shibani Joseph
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a Lot Mark.This will surely help.

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shibani Joseph wrote:Hi All,

It seems like NullPointerException is the most common Exception encountered while doing Spring.

I normally solve it by setting the if(x != null){ } condition

Can Any One please help me with an Expert Advice in dealing with Null Pointer Exceptions.

Thanks.




Check out this link: Exception Handling. It is nice one.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should take care of certain things like.

Calling the instance method of a null object.
Accessing or modifying the field of a null object.
Taking the length of null as if it were an array.
Accessing or modifying the slots of null as if it were an array.
Throwing null as if it were a Throwable value.
Applications should throw instances of this class to indicate other illegal uses of the null object.
 
reply
    Bookmark Topic Watch Topic
  • New Topic