1.初步解决null param存入data slot的NPE问题

This commit is contained in:
LeoLee
2021-12-10 17:19:23 +08:00
parent 21458d6c47
commit a9e025ff9c
3 changed files with 48 additions and 1 deletions

View File

@@ -288,6 +288,10 @@ public class FlowExecutor {
public <T extends Slot> T execute(String chainId, Object param, Class<T> slotClazz, public <T extends Slot> T execute(String chainId, Object param, Class<T> slotClazz,
Integer slotIndex, boolean isInnerChain) throws Exception { 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); T slot = this.doExecute(chainId, param, slotClazz, slotIndex, isInnerChain);
if (ObjectUtil.isNotNull(slot.getException())) { if (ObjectUtil.isNotNull(slot.getException())) {
throw 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, public <T extends Slot> LiteflowResponse<T> execute2Resp(String chainId, Object param, Class<T> slotClazz, Integer slotIndex,
boolean isInnerChain) { boolean isInnerChain) {
LiteflowResponse<T> response = new LiteflowResponse<>(); 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); T slot = doExecute(chainId, param, slotClazz, slotIndex, isInnerChain);
if (ObjectUtil.isNotNull(slot.getException()) && !notFailExceptionList.contains(slot.getException().getClass())) { if (ObjectUtil.isNotNull(slot.getException()) && !notFailExceptionList.contains(slot.getException().getClass())) {

View File

@@ -7,6 +7,7 @@
*/ */
package com.yomahub.liteflow.entity.data; package com.yomahub.liteflow.entity.data;
import com.yomahub.liteflow.exception.NullParamException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Iterator; import java.util.Iterator;
@@ -56,10 +57,18 @@ public abstract class AbsSlot implements Slot {
} }
public <T> void setInput(String nodeId,T t){ 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); dataMap.put(NODE_INPUT_PREFIX + nodeId, t);
} }
public <T> void setOutput(String nodeId,T 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); dataMap.put(NODE_OUTPUT_PREFIX + nodeId, t);
} }

View File

@@ -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;
}
}