flowable / flowable/flowable-engine
Possible NPE in TaskEndedHistoryJsonTransformer.java in CMMN engine
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 7h 8m
- Merged PRs (30d)
- 2
Description
**Describe the bug**
NPE possible given static code analysis.
**Expected behavior**
Don't generate NPE's :)
**Code**
This code [(see here)](https://github.com/flowable/flowable-engine/blob/9926fb6f2ca64e657f6b6c9b40cfa4789f0820de/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/async/json/transformer/TaskEndedHistoryJsonTransformer.java#L43):
@Override
public void transformJson(HistoryJobEntity job, ObjectNode historicalData, CommandContext commandContext) {
HistoricTaskInstanceEntity historicTaskInstance = getHistoricTaskEntity(historicalData, commandContext);
if (historicTaskInstance != null) { [** 1 **]
// The end time is the last update time
Date lastUpdateTime = getDateFromJson(historicalData, CmmnAsyncHistoryConstants.FIELD_END_TIME);
if (historicTaskInstance.getLastUpdateTime() == null || !historicTaskInstance.getLastUpdateTime().after(lastUpdateTime)) {
historicTaskInstance.setLastUpdateTime(lastUpdateTime);
copyCommonHistoricTaskInstanceFields(historicalData, historicTaskInstance);
}
setEndProperties(historicalData, historicTaskInstance);
} else {
HistoricTaskService historicTaskService = CommandContextUtil.getHistoricTaskService(commandContext);
HistoricTaskInstanceEntity historicTaskInstanceEntity = historicTaskService.createHistoricTask();
copyCommonHistoricTaskInstanceFields(historicalData, historicTaskInstanceEntity);
setEndProperties(historicalData, historicTaskInstance); [** 2 **]
historicTaskService.insertHistoricTask(historicTaskInstanceEntity, false);
}
}protected void setEndProperties(ObjectNode historicalData, HistoricTaskInstanceEntity historicTaskInstance) {
Date endTime = getDateFromJson(historicalData, CmmnAsyncHistoryConstants.FIELD_END_TIME);
historicTaskInstance.setEndTime(endTime); [** 3 **]
historicTaskInstance.setDeleteReason(getStringFromJson(historicalData, CmmnAsyncHistoryConstants.FIELD_DELETE_REASON));
Date startTime = historicTaskInstance.getStartTime();
if (startTime != null && endTime != null) {
historicTaskInstance.setDurationInMillis(endTime.getTime() - startTime.getTime());
}
}
If `historicTaskInstance` is null (see ** 1 **), then the code falls into the `else` block and at ** 2 ** a call is made to `setEndProperties()`. This will cause a NPE when `setEndTime()` is called; see ** 3 **.
Sorry but I am not exactly sure of the fix.
If it is any consolation the code has been like this since it was originally written in May, 2018.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.