bug #I6G0D5 NodeIfComponent 重写 isAccess 导致空指针报错

This commit is contained in:
everywhere.z
2023-03-02 11:05:26 +08:00
parent 8034120dd6
commit 4a2d6a12c1
8 changed files with 61 additions and 0 deletions

View File

@@ -28,6 +28,11 @@ public class ForCondition extends LoopCondition{
throw new NoForNodeException(errorInfo);
}
//先去判断isAccess方法如果isAccess方法都返回false整个FOR表达式不执行
if (!this.getForNode().isAccess(slotIndex)){
return;
}
//执行forCount组件
forNode.setCurrChainId(this.getCurrChainId());
forNode.execute(slotIndex);

View File

@@ -27,6 +27,11 @@ public class IfCondition extends Condition {
@Override
public void execute(Integer slotIndex) throws Exception {
if (ListUtil.toList(NodeTypeEnum.IF, NodeTypeEnum.IF_SCRIPT).contains(getIfNode().getType())){
//先去判断isAccess方法如果isAccess方法都返回false整个IF表达式不执行
if (!this.getIfNode().isAccess(slotIndex)){
return;
}
//先执行IF节点
this.getIfNode().setCurrChainId(this.getCurrChainId());
this.getIfNode().execute(slotIndex);

View File

@@ -24,6 +24,11 @@ public class IteratorCondition extends LoopCondition{
throw new NoIteratorNodeException(errorInfo);
}
//先去判断isAccess方法如果isAccess方法都返回false整个ITERATOR表达式不执行
if (!this.getIteratorNode().isAccess(slotIndex)){
return;
}
//执行Iterator组件
iteratorNode.setCurrChainId(this.getCurrChainId());
iteratorNode.execute(slotIndex);

View File

@@ -36,6 +36,11 @@ public class SwitchCondition extends Condition{
@Override
public void execute(Integer slotIndex) throws Exception {
if (ListUtil.toList(NodeTypeEnum.SWITCH, NodeTypeEnum.SWITCH_SCRIPT).contains(this.getSwitchNode().getType())){
//先去判断isAccess方法如果isAccess方法都返回false整个SWITCH表达式不执行
if (!this.getSwitchNode().isAccess(slotIndex)){
return;
}
//先执行switch节点
this.getSwitchNode().setCurrChainId(this.getCurrChainId());
this.getSwitchNode().execute(slotIndex);

View File

@@ -28,6 +28,11 @@ public class WhileCondition extends LoopCondition{
throw new NoWhileNodeException(errorInfo);
}
//先去判断isAccess方法如果isAccess方法都返回false整个WHILE表达式不执行
if (!this.getWhileNode().isAccess(slotIndex)){
return;
}
//获得要循环的可执行对象
Executable executableItem = this.getDoExecutor();

View File

@@ -84,4 +84,12 @@ public class IfELSpringbootTest extends BaseTest {
Assert.assertEquals("x1==>x1==>x1==>x1==>d==>b==>a", response.getExecuteStepStrWithoutTime());
}
//IF节点中isAccess返回false这个情况相当于IF整个表达式串没执行
@Test
public void testIf8() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain8", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("c", response.getExecuteStepStrWithoutTime());
}
}

View File

@@ -0,0 +1,24 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.ifelse.cmp;
import com.yomahub.liteflow.core.NodeIfComponent;
import org.springframework.stereotype.Component;
@Component("x2")
public class X2Cmp extends NodeIfComponent {
@Override
public boolean processIf() throws Exception {
return true;
}
@Override
public boolean isAccess() {
return false;
}
}

View File

@@ -38,4 +38,8 @@
.ELIF(x1.tag("false"), d)
.ELSE(THEN(d, b, a));
</chain>
<chain name="chain8">
THEN(IF(x2, a, b), c);
</chain>
</flow>