mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
1.初步解决null param存入data slot的NPE问题
This commit is contained in:
@@ -288,6 +288,10 @@ public class FlowExecutor {
|
||||
|
||||
public <T extends Slot> T execute(String chainId, Object param, Class<T> slotClazz,
|
||||
Integer slotIndex, boolean isInnerChain) throws Exception {
|
||||
if (null == param) {
|
||||
//data slot is a ConcurrentHashMap, so null value will trigger NullPointerException
|
||||
throw new NullParamException("data slot cann't accept null param");
|
||||
}
|
||||
T slot = this.doExecute(chainId, param, slotClazz, slotIndex, isInnerChain);
|
||||
if (ObjectUtil.isNotNull(slot.getException())) {
|
||||
throw slot.getException();
|
||||
@@ -309,7 +313,10 @@ public class FlowExecutor {
|
||||
public <T extends Slot> LiteflowResponse<T> execute2Resp(String chainId, Object param, Class<T> slotClazz, Integer slotIndex,
|
||||
boolean isInnerChain) {
|
||||
LiteflowResponse<T> response = new LiteflowResponse<>();
|
||||
|
||||
if (null == param) {
|
||||
//data slot is a ConcurrentHashMap, so null value will trigger NullPointerException
|
||||
throw new NullParamException("data slot cann't accept null param");
|
||||
}
|
||||
T slot = doExecute(chainId, param, slotClazz, slotIndex, isInnerChain);
|
||||
|
||||
if (ObjectUtil.isNotNull(slot.getException()) && !notFailExceptionList.contains(slot.getException().getClass())) {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package com.yomahub.liteflow.entity.data;
|
||||
|
||||
import com.yomahub.liteflow.exception.NullParamException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.util.Iterator;
|
||||
@@ -56,10 +57,18 @@ public abstract class AbsSlot implements Slot {
|
||||
}
|
||||
|
||||
public <T> void setInput(String nodeId,T t){
|
||||
if (null == t) {
|
||||
//data slot is a ConcurrentHashMap, so null value will trigger NullPointerException
|
||||
throw new NullParamException("data slot cann't accept null param");
|
||||
}
|
||||
dataMap.put(NODE_INPUT_PREFIX + nodeId, t);
|
||||
}
|
||||
|
||||
public <T> void setOutput(String nodeId,T t){
|
||||
if (null == t) {
|
||||
//data slot is a ConcurrentHashMap, so null value will trigger NullPointerException
|
||||
throw new NullParamException("data slot cann't accept null param");
|
||||
}
|
||||
dataMap.put(NODE_OUTPUT_PREFIX + nodeId, t);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.yomahub.liteflow.exception;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* null param exception
|
||||
* when param is null, dataMap (ConcurrentHashMap) cann't accept a null value
|
||||
*
|
||||
* @Author LeoLee
|
||||
* @Date 2021/12/10 16:47
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class NullParamException extends RuntimeException implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -864259139568071245L;
|
||||
|
||||
private String message;
|
||||
|
||||
public NullParamException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user