geirm       01/04/02 22:05:31

  Modified:    src/java/org/apache/velocity/runtime/parser/node
                        ASTAndNode.java
  Log:
  Added log error message if LHS or RHS is null, and further short
  circuit the && - the LHS is false, dont evaluate the RHS.
  
  Revision  Changes    Path
  1.5       +26 -6     
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java
  
  Index: ASTAndNode.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ASTAndNode.java   2001/03/19 17:17:44     1.4
  +++ ASTAndNode.java   2001/04/03 05:05:31     1.5
  @@ -58,14 +58,14 @@
   import org.apache.velocity.context.InternalContextAdapter;
   import org.apache.velocity.runtime.parser.Parser;
   import org.apache.velocity.exception.MethodInvocationException;
  -
  +import org.apache.velocity.runtime.Runtime;
   /**
    * Please look at the Parser.jjt file which is
    * what controls the generation of this class.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: ASTAndNode.java,v 1.4 2001/03/19 17:17:44 geirm Exp $ 
  + * @version $Id: ASTAndNode.java,v 1.5 2001/04/03 05:05:31 geirm Exp $ 
    */
   public class ASTAndNode extends SimpleNode
   {
  @@ -96,13 +96,33 @@
       {       
           Node left = jjtGetChild(0);
           Node right = jjtGetChild(1);
  +
  +        /*
  +         *  if either is null, lets log and bail
  +         */
   
  -        if (left != null &&  right != null)
  +        if (left == null || right == null)
           {
  -            return ( left.evaluate( context) && right.evaluate( context ) );
  -        }
  -        else
  +            Runtime.error( ( left == null ? "Left" : "Right" ) + " side of '&&' 
operation is null."
  +                           + " Operation not possible. "
  +                           + context.getCurrentTemplateName() + " [line " + 
getLine() 
  +                           + ", column " + getColumn() + "]");
               return false;
  +        }
  +        
  +        /*
  +         *  short circuit the test.  Don't eval the RHS if the LHS is false
  +         */
  +
  +        if( left.evaluate( context ) )
  +        {
  +            if ( right.evaluate( context ) )
  +            {
  +                return true;
  +            }
  +        }        
  +           
  +        return false;
       }
   }
   
  
  
  

Reply via email to