Java 在DRools规则中遍历空数组时出错
我正在.drl规则文件中使用arrayList。 在一条规则中,我检查列表是否为空,并设置setFocus(第二条规则)。 在第二个规则中,我从列表中获取元素,在这个规则中,我获取的列表为空错误 我希望检查列表是否为空,并在一个规则中从该arraylist获取特定元素Java 在DRools规则中遍历空数组时出错,java,drools,Java,Drools,我正在.drl规则文件中使用arrayList。 在一条规则中,我检查列表是否为空,并设置setFocus(第二条规则)。 在第二个规则中,我从列表中获取元素,在这个规则中,我获取的列表为空错误 我希望检查列表是否为空,并在一个规则中从该arraylist获取特定元素 rule "Rule chesks client had already received Notifications or Not" salience 10 no-loop true when event :
rule "Rule chesks client had already received Notifications or Not"
salience 10
no-loop true
when
event : Event($listOfClientNotifications : clientNotifications)
eval($listOfClientNotifications < 1)
then
event.setMessage("list is null");
end
rule“rule chesks客户端是否已收到通知”
显著性10
无循环为真
什么时候
事件:事件($listOfClientNotifications:clientNotifications)
eval($ListofClient通知<1)
然后
setMessage(“列表为空”);
结束
第二条规则:
rule "Rule chesks "
salience 05
no-loop true
when
event : Event($listOfClientNotifications : clientNotifications)
value : ClientNotifications() from $listOfClientNotifications; // <<< !!!
then
event.setMessage("Value "+**value.getMessage()**);
end
规则“规则检查”
显著性05
无循环为真
什么时候
事件:事件($listOfClientNotifications:clientNotifications)
值:$ListofClient Notifications中的ClientNotifications()// 在一个规则中针对null测试列表(正确!)并不能避免在另一个规则中遇到NPE。规则评估与规则执行、显著性和激活组不同步,也不重复
这是一个正确的检查:
rule "check list is null"
when
event : Event(clientNotifications == null)
then
event.setMessage("list is null");
end
防止撞到NPE
rule "use notifications from list"
when
event : Event($listOfClientNotifications : clientNotifications != null)
value : ClientNotifications() from $listOfClientNotifications;
then
event.setMessage("Value "+ value.getMessage()); // strange, but maybe?
end