[Best Practice] Test existence of properties to avoid Velocity errors in log

Vincent Massol vincent at massol.net
Tue Apr 17 11:55:42 CEST 2007


Hi,

Here's another one best practice I'd like to propose:

Instead of writing:

#set($obj = ...)
#if ($obj.getSomething() == "...")

Write:

#if($obj && $obj.getSomething() == "...")

This prevents the following error in logs:

11:54:04,777 ERROR P1-19 ... SimpleLog4JLogSystem:logVelocityMessage: 
154 - Left side ($obj.getSomething()) of '==' operation has null  
value. If a reference, it may not be in the context. Operation not  
possible.  [line 1, column 21]

WDYT?

Thanks
-Vincent





More information about the devs mailing list