bug #I6Y300 修复可能IdGeneratorHolder 存在的NPE异常

This commit is contained in:
everywhere.z
2023-05-03 21:36:32 +08:00
parent ba07efecc8
commit 07e3fd703e
2 changed files with 11 additions and 4 deletions

View File

@@ -71,8 +71,9 @@ public class FlowExecutor {
/**
* FlowExecutor的初始化化方式主要用于parse规则文件
* isStart表示是否是系统启动阶段启动阶段要做额外的事情而因为reload所调用的init就不用做
*/
public void init(boolean hook) {
public void init(boolean isStart) {
if (ObjectUtil.isNull(liteflowConfig)) {
throw new ConfigErrorException("config error, please check liteflow config property");
}
@@ -82,8 +83,10 @@ public class FlowExecutor {
// 在非spring体系下是一个空实现等于不做此步骤
ContextCmpInitHolder.loadContextCmpInit().initCmp();
// 进行id生成器的初始化
IdGeneratorHolder.init();
if (isStart){
// 进行id生成器的初始化
IdGeneratorHolder.init();
}
String ruleSource = liteflowConfig.getRuleSource();
if (StrUtil.isBlank(ruleSource)) {
@@ -191,7 +194,7 @@ public class FlowExecutor {
}
// 执行钩子
if (hook) {
if (isStart) {
FlowInitHook.executeHook();
}

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.flow.id;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.yomahub.liteflow.exception.RequestIdGeneratorException;
import com.yomahub.liteflow.property.LiteflowConfig;
@@ -44,6 +45,9 @@ public class IdGeneratorHolder {
}
public String generate() {
if (ObjectUtil.isNull(requestIdGenerator)){
init();
}
return requestIdGenerator.generate();
}