[jboss-svn-commits] JBL Code SVN: r18873 - in labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools: rule and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Mar 12 00:43:36 EDT 2008
Author: michael.neale at jboss.com
Date: 2008-03-12 00:43:36 -0400 (Wed, 12 Mar 2008)
New Revision: 18873
Modified:
labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java
labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/rule/EvalCondition.java
Log:
JBRULES-1452 Improved NPE error handling (thanks to Mike McMahon)
Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java 2008-03-12 04:38:28 UTC (rev 18872)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/base/evaluators/DateFactory.java 2008-03-12 04:43:36 UTC (rev 18873)
@@ -2,13 +2,13 @@
/*
* Copyright 2005 JBoss Inc
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,14 +31,14 @@
/**
* This will generate evaluators that handle dates.
- * This will also parse strings into dates, according to
+ * This will also parse strings into dates, according to
* DEFAULT_FORMAT_MASK, unless it is overridden by the drools.dateformat system property.
- *
+ *
* When parsing dates from a string, no time is included.
- *
- * So you can do expressions like
+ *
+ * So you can do expressions like
* <code>Person(birthday <= "10-Jul-1974")</code> etc.
- *
+ *
* @author Michael Neale
*/
public class DateFactory
@@ -52,10 +52,10 @@
private static EvaluatorFactory INSTANCE = new DateFactory();
private static ThreadLocal df = new ThreadLocal() {
protected Object initialValue() {
- return new SimpleDateFormat( DateFactory.DATE_FORMAT_MASK );
+ return new SimpleDateFormat( DateFactory.DATE_FORMAT_MASK );
};
};
-
+
private DateFactory() {
}
@@ -90,7 +90,7 @@
static class DateEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new DateEqualEvaluator();
@@ -163,7 +163,7 @@
static class DateNotEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new DateNotEqualEvaluator();
@@ -235,7 +235,7 @@
static class DateLessEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new DateLessEvaluator();
@@ -285,6 +285,7 @@
}
final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ if (null == value2) throw new NullPointerException(extractor2.toString());
return value1.compareTo( value2 ) < 0;
}
@@ -295,7 +296,7 @@
static class DateLessOrEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new DateLessOrEqualEvaluator();
@@ -345,6 +346,7 @@
}
final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ if (null == value2) throw new NullPointerException(extractor2.toString());
return value1.compareTo( value2 ) <= 0;
}
@@ -355,7 +357,7 @@
static class DateGreaterEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
public final static Evaluator INSTANCE = new DateGreaterEvaluator();
@@ -405,6 +407,7 @@
}
final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ if (null == value2) throw new NullPointerException(extractor2.toString());
return value1.compareTo( value2 ) > 0;
}
@@ -415,7 +418,7 @@
static class DateGreaterOrEqualEvaluator extends BaseEvaluator {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
private final static Evaluator INSTANCE = new DateGreaterOrEqualEvaluator();
@@ -465,6 +468,7 @@
}
final Date value1 = (Date) extractor1.getValue( workingMemory, object1 );
final Date value2 = (Date) extractor2.getValue( workingMemory, object2 );
+ if (null == value2) throw new NullPointerException(extractor2.toString());
return value1.compareTo( value2 ) >= 0;
}
@@ -502,7 +506,7 @@
return "Date not memberOf";
}
}
-
+
/** Use the simple date formatter to read the date from a string */
public static Date parseDate(final String input) {
try {
Modified: labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/rule/EvalCondition.java
===================================================================
--- labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/rule/EvalCondition.java 2008-03-12 04:38:28 UTC (rev 18872)
+++ labs/jbossrules/branches/4.0.x/drools-core/src/main/java/org/drools/rule/EvalCondition.java 2008-03-12 04:43:36 UTC (rev 18873)
@@ -2,13 +2,13 @@
/*
* Copyright 2005 JBoss Inc
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,7 +27,7 @@
public class EvalCondition extends ConditionalElement {
/**
- *
+ *
*/
private static final long serialVersionUID = 400L;
@@ -65,7 +65,7 @@
public Declaration[] getRequiredDeclarations() {
return this.requiredDeclarations;
}
-
+
public Object createContext() {
return this.expression.createContext();
}
@@ -79,7 +79,7 @@
workingMemory,
context );
} catch ( final Exception e ) {
- throw new RuntimeDroolsException( e );
+ throw new RuntimeDroolsException( this.getEvalExpression() + " : " + e );
}
}
More information about the jboss-svn-commits
mailing list