Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-1452

Improved NullPointerException messages

    XMLWordPrintable

    Details

    • Type: Patch
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 4.0.0.MR2, 4.0.0.MR3, 4.0.0.GA, 4.0.1, 4.0.2, 4.0.3, 4.0.4
    • Fix Version/s: 4.0.5
    • Component/s: None
    • Labels:
      None
    • Estimated Difficulty:
      Low

      Description

      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 ); }

      }

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                michaelneale Michael Neale
                Reporter:
                msquared Mike McMahon
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: