geirm 01/04/08 19:24:04
Modified: src/java/org/apache/velocity/runtime/parser/node
ASTEQNode.java ASTGENode.java ASTGTNode.java
ASTLENode.java ASTLTNode.java ASTNENode.java
Log:
Fixed to ensure no NPEs and good logging.
Revision Changes Path
1.6 +2 -3
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTEQNode.java
Index: ASTEQNode.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTEQNode.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ASTEQNode.java 2001/03/19 17:17:45 1.5
+++ ASTEQNode.java 2001/04/09 02:24:03 1.6
@@ -1,6 +1,5 @@
package org.apache.velocity.runtime.parser.node;
-/* Generated By:JJTree: Do not edit this line. ASTEQNode.java */
/*
* The Apache Software License, Version 1.1
*
@@ -56,7 +55,7 @@
*/
import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.parser.*;
+import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.exception.MethodInvocationException;
@@ -69,7 +68,7 @@
* This operator requires that the LHS and RHS are both of the
* same Class.
*
- * @version $Id: ASTEQNode.java,v 1.5 2001/03/19 17:17:45 geirm Exp $
+ * @version $Id: ASTEQNode.java,v 1.6 2001/04/09 02:24:03 geirm Exp $
*/
public class ASTEQNode extends SimpleNode
{
1.5 +8 -13
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java
Index: ASTGENode.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ASTGENode.java 2001/04/03 03:33:09 1.4
+++ ASTGENode.java 2001/04/09 02:24:03 1.5
@@ -1,6 +1,5 @@
package org.apache.velocity.runtime.parser.node;
-/* Generated By:JJTree: Do not edit this line. ASTGENode.java */
/*
* The Apache Software License, Version 1.1
*
@@ -94,9 +93,11 @@
if (left == null || right == null)
{
- Runtime.error( ( left == null ? "Left" : "Right" ) + " side of '>='
operation has null value."
+ Runtime.error( ( left == null ? "Left" : "Right" )
+ + " side of '>=' operation has null value."
+ " Operation not possible. "
- + context.getCurrentTemplateName() + " [line " +
getLine()
+ + context.getCurrentTemplateName() + " [line "
+ + getLine()
+ ", column " + getColumn() + "]");
return false;
}
@@ -109,21 +110,15 @@
{
Runtime.error( ( !( left instanceof Integer ) ? "Left" : "Right" )
+ " side of '>=' operation is not a valid type. "
- + "Currently only integers (1,2,3...) and Integer type
is supported. "
+ + " It is a " + ( !( left instanceof Integer ) ?
left.getClass() : right.getClass() )
+ + ". Currently only integers (1,2,3...) and Integer type
is supported. "
+ context.getCurrentTemplateName() + " [line " +
getLine()
+ ", column " + getColumn() + "]");
return false;
}
- if ( ((Integer) left).intValue() >=
- ((Integer) right).intValue() )
- {
- return true;
- }
- else
- {
- return false;
- }
+ return ( (Integer) left).intValue() >= ((Integer) right).intValue() ;
+
}
}
1.5 +9 -17
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java
Index: ASTGTNode.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ASTGTNode.java 2001/04/03 06:01:10 1.4
+++ ASTGTNode.java 2001/04/09 02:24:03 1.5
@@ -1,6 +1,5 @@
package org.apache.velocity.runtime.parser.node;
-/* Generated By:JJTree: Do not edit this line. ASTGTNode.java */
/*
* The Apache Software License, Version 1.1
*
@@ -56,7 +55,7 @@
*/
import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.parser.*;
+import org.apache.velocity.runtime.parser.Parser;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.runtime.Runtime;
@@ -81,9 +80,7 @@
public boolean evaluate(InternalContextAdapter context)
throws MethodInvocationException
{
-
-
- /*
+ /*
* get the two args
*/
@@ -96,9 +93,11 @@
if (left == null || right == null)
{
- Runtime.error( ( left == null ? "Left" : "Right" ) + " side of '>'
operation has null value."
+ Runtime.error( ( left == null ? "Left" : "Right" )
+ + " side of '>' operation has null value."
+ " Operation not possible. "
- + context.getCurrentTemplateName() + " [line " +
getLine()
+ + context.getCurrentTemplateName() + " [line "
+ + getLine()
+ ", column " + getColumn() + "]");
return false;
}
@@ -111,21 +110,14 @@
{
Runtime.error( ( !( left instanceof Integer ) ? "Left" : "Right" )
+ " side of '>' operation is not a valid type. "
- + "Currently only integers (1,2,3...) and Integer type
is supported. "
+ + " It is a " + ( !( left instanceof Integer ) ?
left.getClass() : right.getClass() )
+ + ". Currently only integers (1,2,3...) and Integer type
is supported. "
+ context.getCurrentTemplateName() + " [line " +
getLine()
+ ", column " + getColumn() + "]");
return false;
}
- if ( ((Integer) left).intValue() >
- ((Integer) right).intValue() )
- {
- return true;
- }
- else
- {
- return false;
- }
+ return ((Integer) left).intValue() > ((Integer) right).intValue();
}
}
1.4 +40 -6
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTLENode.java
Index: ASTLENode.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTLENode.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ASTLENode.java 2001/03/19 17:17:49 1.3
+++ ASTLENode.java 2001/04/09 02:24:03 1.4
@@ -1,6 +1,5 @@
package org.apache.velocity.runtime.parser.node;
-/* Generated By:JJTree: Do not edit this line. ASTLENode.java */
/*
* The Apache Software License, Version 1.1
*
@@ -56,7 +55,8 @@
*/
import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.parser.*;
+import org.apache.velocity.runtime.parser.Parser;
+import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.exception.MethodInvocationException;
@@ -81,10 +81,44 @@
public boolean evaluate( InternalContextAdapter context)
throws MethodInvocationException
{
- if (((Integer)jjtGetChild(0).value(context)).intValue() <=
- ((Integer)jjtGetChild(1).value(context)).intValue())
- return true;
- else
+ /*
+ * get the two args
+ */
+
+ Object left = jjtGetChild(0).value( context );
+ Object right = jjtGetChild(1).value( context );
+
+ /*
+ * if either is null, lets log and bail
+ */
+
+ if (left == null || right == null)
+ {
+ Runtime.error( ( left == null ? "Left" : "Right" )
+ + " side of '<=' operation has null value."
+ + " Operation not possible. "
+ + context.getCurrentTemplateName() + " [line "
+ + getLine()
+ + ", column " + getColumn() + "]");
return false;
+ }
+
+ /*
+ * if not an Integer, not much we can do either
+ */
+
+ if ( !( left instanceof Integer ) || !( right instanceof Integer ))
+ {
+ Runtime.error( ( !( left instanceof Integer ) ? "Left" : "Right" )
+ + " side of '<=' operation is not a valid type. "
+ + " It is a " + ( !( left instanceof Integer ) ?
left.getClass() : right.getClass() )
+ + ". Currently only integers (1,2,3...) and Integer type
is supported. "
+ + context.getCurrentTemplateName() + " [line " +
getLine()
+ + ", column " + getColumn() + "]");
+
+ return false;
+ }
+
+ return ((Integer) left).intValue() <= ((Integer) right).intValue() ;
}
}
1.4 +40 -6
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTLTNode.java
Index: ASTLTNode.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTLTNode.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ASTLTNode.java 2001/03/19 17:17:50 1.3
+++ ASTLTNode.java 2001/04/09 02:24:03 1.4
@@ -1,6 +1,5 @@
package org.apache.velocity.runtime.parser.node;
-/* Generated By:JJTree: Do not edit this line. ASTLTNode.java */
/*
* The Apache Software License, Version 1.1
*
@@ -56,7 +55,8 @@
*/
import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.parser.*;
+import org.apache.velocity.runtime.parser.Parser;
+import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.exception.MethodInvocationException;
@@ -81,10 +81,44 @@
public boolean evaluate(InternalContextAdapter context)
throws MethodInvocationException
{
- if (((Integer)jjtGetChild(0).value(context)).intValue() <
- ((Integer)jjtGetChild(1).value(context)).intValue())
- return true;
- else
+ /*
+ * get the two args
+ */
+
+ Object left = jjtGetChild(0).value( context );
+ Object right = jjtGetChild(1).value( context );
+
+ /*
+ * if either is null, lets log and bail
+ */
+
+ if (left == null || right == null)
+ {
+ Runtime.error( ( left == null ? "Left" : "Right" )
+ + " side of '<' operation has null value."
+ + " Operation not possible. "
+ + context.getCurrentTemplateName() + " [line "
+ + getLine()
+ + ", column " + getColumn() + "]");
return false;
+ }
+
+ /*
+ * if not an Integer, not much we can do either
+ */
+
+ if ( !( left instanceof Integer ) || !( right instanceof Integer ))
+ {
+ Runtime.error( ( !( left instanceof Integer ) ? "Left" : "Right" )
+ + " side of '<' operation is not a valid type. "
+ + " It is a " + ( !( left instanceof Integer ) ?
left.getClass() : right.getClass() )
+ + ". Currently only integers (1,2,3...) and Integer type
is supported. "
+ + context.getCurrentTemplateName() + " [line " +
getLine()
+ + ", column " + getColumn() + "]");
+
+ return false;
+ }
+
+ return ((Integer) left).intValue() < ((Integer) right).intValue() ;
}
}
1.4 +39 -15
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTNENode.java
Index: ASTNENode.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTNENode.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ASTNENode.java 2001/03/19 17:17:51 1.3
+++ ASTNENode.java 2001/04/09 02:24:03 1.4
@@ -1,7 +1,5 @@
package org.apache.velocity.runtime.parser.node;
-/* Generated By:JJTree: Do not edit this line. ASTNENode.java */
-
/*
* The Apache Software License, Version 1.1
*
@@ -57,7 +55,8 @@
*/
import org.apache.velocity.context.InternalContextAdapter;
-import org.apache.velocity.runtime.parser.*;
+import org.apache.velocity.runtime.parser.Parser;
+import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.exception.MethodInvocationException;
@@ -82,19 +81,44 @@
public boolean evaluate( InternalContextAdapter context)
throws MethodInvocationException
{
- if (jjtGetChild(0).value(context) instanceof Boolean &&
- ((Boolean)jjtGetChild(0).value(context)).booleanValue() !=
- ((Boolean)jjtGetChild(1).value(context)).booleanValue())
- return true;
- else if (jjtGetChild(0).value(context) instanceof Integer &&
- ((Integer)jjtGetChild(0).value(context)).intValue() !=
- ((Integer)jjtGetChild(1).value(context)).intValue())
- return true;
- else if (jjtGetChild(0).value(context) instanceof String &&
- ! jjtGetChild(0).value(context).toString()
- .equals(jjtGetChild(1).value(context).toString()))
- return true;
+ Object left = jjtGetChild(0).value( context );
+ Object right = jjtGetChild(1).value( context );
+
+ /*
+ * null check
+ */
+
+ if ( left == null || right == null)
+ {
+ Runtime.error( ( left == null ? "Left" : "Right" ) + " side of '!='
operation has null value."
+ + " Operation not possible. "
+ + context.getCurrentTemplateName() + " [line " +
getLine()
+ + ", column " + getColumn() + "]");
+ return false;
+
+ }
+
+
+ /*
+ * check to see if they are the same class. I don't think this is slower
+ * as I don't think that getClass() results in object creation, and we can
+ * extend == to handle all classes
+ */
+
+ if (left.getClass().equals( right.getClass() ) )
+ {
+ return !(left.equals( right ));
+ }
else
+ {
+ Runtime.error("Error in evaluation of != expression."
+ + " Both arguments must be of the same Class."
+ + " Currently left = " + left.getClass() + ", right = "
+ + right.getClass() + ". "
+ + context.getCurrentTemplateName() + " [line " +
getLine()
+ + ", column " + getColumn() + "] (ASTEQNode)");
+
return false;
+ }
}
}