如何在流口水中进行空值或空值检查-Mvel方言?

时间:2018-07-16 11:10:42

标签: drools rules business-rules mvel

当configList为null时,AND逻辑不应继续进行,但是我收到此错误-“数组索引超出范围”

以下是规则:

rule "testRule"
   when
       config : Config( configList != null && !configList.empty && configList[0].attribute != null )
   then
       // logic
end

1 个答案:

答案 0 :(得分:0)

由于Drools执行规则条件的方式,因此不能保证短路逻辑运算符。在某些情况下,它们可以工作,但在其他情况下,则不能。

作为一种解决方法,您可以将单个模式分成两个:

rule "testRule"
when
  config : Config( $configList: configList != null, configList.empty == false)
  Attribute() from $configList.get(0)
then
  // logic
end

我假设$configListAttribute对象的列表。

希望有帮助,