From ae3e96e33d18c82c1608a0a2e9424d888274b14e Mon Sep 17 00:00:00 2001 From: pansb Date: Fri, 31 Jul 2026 15:02:06 +0800 Subject: [PATCH] fix Calling getValue() directly will throw an NPE if the record of next.dbid does not exist in the database (property is null) --- .../flowable/engine/impl/cmd/GetNextIdBlockCmd.java | 11 ++++++++++- .../activiti/engine/impl/cmd/GetNextIdBlockCmd.java | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetNextIdBlockCmd.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetNextIdBlockCmd.java index e4d59826ab3..dd64935205d 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetNextIdBlockCmd.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetNextIdBlockCmd.java @@ -12,6 +12,7 @@ */ package org.flowable.engine.impl.cmd; +import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.impl.db.IdBlock; import org.flowable.common.engine.impl.interceptor.Command; import org.flowable.common.engine.impl.interceptor.CommandContext; @@ -33,7 +34,15 @@ public GetNextIdBlockCmd(int idBlockSize) { @Override public IdBlock execute(CommandContext commandContext) { PropertyEntity property = (PropertyEntity) CommandContextUtil.getPropertyEntityManager(commandContext).findById("next.dbid"); - long oldValue = Long.parseLong(property.getValue()); + if (property == null) { + throw new FlowableException("Property 'next.dbid' not found. Database may not have been properly initialized."); + } + long oldValue; + try { + oldValue = Long.parseLong(property.getValue()); + } catch (NumberFormatException e) { + throw new FlowableException("Invalid value for property 'next.dbid': " + property.getValue(), e); + } long newValue = oldValue + idBlockSize; property.setValue(Long.toString(newValue)); return new IdBlock(oldValue, newValue - 1); diff --git a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetNextIdBlockCmd.java b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetNextIdBlockCmd.java index 091e339ba60..2c6771b37e3 100644 --- a/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetNextIdBlockCmd.java +++ b/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/GetNextIdBlockCmd.java @@ -12,6 +12,7 @@ */ package org.activiti.engine.impl.cmd; +import org.activiti.engine.ActivitiException; import org.activiti.engine.impl.db.IdBlock; import org.activiti.engine.impl.interceptor.Command; import org.activiti.engine.impl.interceptor.CommandContext; @@ -34,7 +35,15 @@ public IdBlock execute(CommandContext commandContext) { PropertyEntity property = commandContext .getPropertyEntityManager() .findPropertyById("next.dbid"); - long oldValue = Long.parseLong(property.getValue()); + if (property == null) { + throw new ActivitiException("Property 'next.dbid' not found. Database may not have been properly initialized."); + } + long oldValue; + try { + oldValue = Long.parseLong(property.getValue()); + } catch (NumberFormatException e) { + throw new ActivitiException("Invalid value for property 'next.dbid': " + property.getValue(), e); + } long newValue = oldValue + idBlockSize; property.setValue(Long.toString(newValue)); return new IdBlock(oldValue, newValue - 1);