6

Short version: How can I disable the MVEL strict mode using the new KIE API?

I know that there is a configuration property "drools.dialect.mvel.strict" that can be set using the old KnowledgeBuilder API. However I can not find a way to accomplish the same with the new API.

Long version: I have an object method, called Object attribute(String name), and the result can be many different types. Sometimes could be a List, others String or whatever. Now in order to use that method I have to use a lot of casting or drools throws exceptions. For the following example:

$entity : RootEntity( attribute('authors') != null && 
                      attribute('authors').size() >= 3 && 
                      attribute('authors')[2] == 'whatever' ) 

I get errors like this:

Unable to Analyse Expression attribute("authors").size() >= 3:
[Error: unable to resolve method using strict-mode: java.lang.Object.size()]

Unable to Analyse Expression attribute("authors")[2] == "whatever":
[Error: unknown collection type: class java.lang.Object; property=]

In order to make this work with the strict typing enabled I have to type the same expression as such:

$entity : RootEntity( attribute('authors') != null && 
                      ((java.util.List) attribute('authors')).size() >= 3 && 
                      ((java.util.List) attribute('authors'))[2] == 'whatever' ) 

Which can be disabled with the strict typing option.

Community
  • 1
  • 1
Dimitrios Menounos
  • 456
  • 1
  • 6
  • 16
  • This pattern works, exaclty as shown, with some 5.x version? How is `attribute` defined? – laune Oct 07 '14 at 16:20
  • public Object attribute(String attribute) { /* resolve the actual value */ } – Dimitrios Menounos Oct 08 '14 at 14:58
  • Yes, casting works but is not ideal. Drools/MVEL can also process dynamic expressions without the need to cast. For that to work I need to find the way to set the "drools.dialect.mvel.strict" to false (using the new KIE API instead of the old KnowledgeBuilder API). That is the question. – Dimitrios Menounos Oct 08 '14 at 15:03
  • I meant the *first* pattern, the one without the casts. Did this work, exactly as shown, with `attribute()` returning an Object? Which Drools version can handle that? – laune Oct 08 '14 at 17:01
  • Any luck/updates with this question? Facing the same problem myself. Can't seem to find any solid support in the docs. – GroomedGorilla Feb 11 '15 at 11:46

0 Answers0