Drools error of Unexpected Global

I recently got the runtime exception from Drools stating "Unexpected global." I immediately checked my global declaration in my DRL file, but all looked good. Even my code looked good. The common solutions were of no help, either. I finally found the problem , and it wasn't related to my global variable at all.

Through my searching for the solution, I came across several things to check when you get this error message (including one that solved my problem). I though I'd compile them here:

1. Is the knowledgebase loading the correct resource file (ie, is the path correct for the DRL file or other resource?)
2. Is the type you are passing the same qualified type the global is expecting (HashMap<string, string> vs. HashMap<string, integer>)
3. Are all the needed classes for the DRL in your classpath and loaded?
4. Is the Java runtime the same version as needed for your classes/facts?
5. Are there any other errors in you rules file? This was my problem. In a rule, one fact referenced a field that it did not have. Not sure why it manifested as a global error. Combing through the rules for bad logic may be your answer.

Hope this helps someone.

Comments

  1. Similar to your item 5. I had problem in my rule file, I used wrong dialect. I was calling java function on global object, but I was relying on default dialect which is 'mvel'. As soon I changed my dialect to 'java' and put ';' at the end of each line. My problem got resolved.

    Would you like to add it to your list so that others might get reference as well.

    Thanks for compiling this list.

    ReplyDelete
  2. I am getting the same error. But it appears sometimes.When I restart the server, it works fine for few random days and problem reappears.

    What could be the possible issue?

    ReplyDelete
  3. Exactly. I had the same issue. I was accessing a member of an object in the rule file which does not exist. Don't know why Drools through such error, but combing through the whole rule file will solve such issues..

    ReplyDelete

Post a Comment

Popular Posts