[jboss-jira] [JBoss JIRA] Assigned: (JBRULES-1452) Improved NullPointerException messages

Michael Neale (JIRA) jira-events at lists.jboss.org
Tue Mar 11 23:50:58 EDT 2008


     [ http://jira.jboss.com/jira/browse/JBRULES-1452?page=all ]

Michael Neale reassigned JBRULES-1452:
--------------------------------------

    Assignee: Michael Neale

> Improved NullPointerException messages
> --------------------------------------
>
>                 Key: JBRULES-1452
>                 URL: http://jira.jboss.com/jira/browse/JBRULES-1452
>             Project: JBoss Drools
>          Issue Type: Patch
>      Security Level: Public(Everyone can see) 
>    Affects Versions: 4.0.4, 4.0.3, 4.0.2, 4.0.1,  4.0.0.GA,  4.0.0.MR3, 4.0.0.MR2
>            Reporter: mike mcmahon
>         Assigned To: Michael Neale
>             Fix For: 4.0.5
>
>
> Currently, there are many places in drools-core which can (potentially) throw NullPointerException. The error message contains no information about which Rule or which item/property in working memory caused the NPE, and this makes it very difficult to fix the Rule or working memory data.
> The patch below (relative to 4.0.4) adds some valuable information to aid in fixing Rules.
> Index: org/drools/base/evaluators/DateFactory.java
> ===================================================================
> --- org/drools/base/evaluators/DateFactory.java	(revision 18270)
> +++ org/drools/base/evaluators/DateFactory.java	(working copy)
> @@ -282,6 +282,8 @@
>              }
>              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;
>          }
>  
> @@ -342,6 +344,8 @@
>              }
>              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;
>          }
>  
> @@ -402,6 +406,8 @@
>              }
>              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;
>          }
>  
> @@ -462,6 +468,8 @@
>              }
>              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;
>          }
>  
> Index: org/drools/rule/EvalCondition.java
> ===================================================================
> --- org/drools/rule/EvalCondition.java	(revision 18270)
> +++ org/drools/rule/EvalCondition.java	(working copy)
> @@ -73,7 +73,7 @@
>                                               this.requiredDeclarations,
>                                               workingMemory );
>          } catch ( final Exception e ) {
> -            throw new RuntimeDroolsException( e );
> +            throw new RuntimeDroolsException( this.getEvalExpression() + " : " + e );
>          }
>      }
>  

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list