0

One day we faced an incident that application started crashing because of the NPE. I found the place where it was crashing, but I cannot be sure why does it happen.

Roughly speaking lets assume that I have a class A which appears a spring bean at the same time. This class has a field property which is instantiated explicitly (yes, I know how it sounds like) and a method propertyUser which uses this field:

class A {
   private ObjectClass property = new ObjectClass();
   public void propertyUser() {
      property.action();
   }   
   ....
   getter\setter for property
}

And after some time of usual work, property field has become null which has resulted in NPE from propertyUser method. I changed this legacy code and now this property is assigned via spring container either, however I do need to be sure that this was the reason of this error appearance.

So I would be very pleased if somebody could give me a hint.

Andrei
  • 303
  • 3
  • 7
  • Check all usages of corresponding setter. Maybe somewhere you have `a.setproperty(reference)` where the reference was null? – Maksym Demidas Aug 28 '13 at 11:30
  • Double checked - no, setter is not used anywhere. – Andrei Aug 28 '13 at 11:48
  • Reflection? Some serialization process in place? it is stored in server side session? – Maksym Demidas Aug 28 '13 at 11:50
  • No, nothing from your list take place. This bean (I mean class A) is used like injected bean in one of mvc controllers. It doesn't store anything, neither it is stored anywhere. And that property is accessed only via that bean (several methods are delegated). Getter is not even used anywhere. – Andrei Aug 28 '13 at 12:19
  • Are you sure that you examine exactly the same version of the code (that was deployed that time)? – Maksym Demidas Aug 28 '13 at 12:28
  • Yes it is the same - just checked. I'm thinking: is it possible that spring container reload its bean after sometime and then calls each setter implicitly with null value? In that case this reference could be assigned and then removed... – Andrei Aug 28 '13 at 12:46
  • Do not know any situation where it is possible... – Maksym Demidas Aug 28 '13 at 13:07

0 Answers0