0

I'm working with Drools 5.4, and have been experiencin an NPE in a block of code similar to this:

rule "NPE sometimes"
   when
      $person : Person((name == null || name.last == null || name.last.empty),
         person.uniqueId != null)
   then
      log.error("Person has unique ID, but no last name");
end

The error occurs when it appears that the middle expression is attempted to be evaluated out of order:

Exception in thread "Thread-18" [Error: null pointer or function not found: last]
[Near : {... name == null || name.last == null || name....}]
                             ^

I know that the rules engine attempts to optimize where possible. Is this kind of expression not allowed, or subject to optimization?

josh-cain
  • 4,997
  • 7
  • 35
  • 55
  • I doubt very much that this code is "similar" enough to what you really have there. Kindly post a complete set of Java + DRL, reproducing the problem you are experiencing. And the error isn't happening during "evaluation" - it has all the hallmarks of a DRL compiler error message, (What about the stack dump?) – laune Dec 09 '14 at 06:20
  • Unfortunately I can't post the entirety (or even the real rule), I'll work to re-create the issue in a post I can share. – josh-cain Dec 09 '14 at 13:03

1 Answers1

0

Drools 5.4 is an older version and the support for free-form constraints may not have been perfect. Given the compilation error, could you try name.getLast() in place of name.last ? Same for name.last.empty later.

Davide Sottara
  • 221
  • 1
  • 3