From 8186ec2416f3a41cd0d4dc91e357539522d2dd9b Mon Sep 17 00:00:00 2001 From: Oleksandr Moliavko Date: Thu, 1 Aug 2019 14:02:18 +0300 Subject: Fixed potential crashes due to null object dereference attempts in exception handlers Issue-ID: SO-1841 Signed-off-by: Oleksandr Moliavko Change-Id: I9882171b47b6442fa8ca12110d8ef23fc975347b --- .../main/java/org/onap/so/bpmn/core/BaseTask.java | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/BaseTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/BaseTask.java index 2e66493a25..1442099286 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/BaseTask.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/BaseTask.java @@ -86,8 +86,13 @@ public class BaseTask implements JavaDelegate { } return variable; } else { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "expected a variable name string" + ", got object of type " + o.getClass().getName()); + if (o != null) { + throw new BadInjectedFieldException(fieldName, getTaskName(), + "expected a variable name string, got object of type " + o.getClass().getName()); + } else { + throw new BadInjectedFieldException(fieldName, getTaskName(), + "expected a variable name string, got null object"); + } } } @@ -114,7 +119,7 @@ public class BaseTask implements JavaDelegate { return null; } else { throw new BadInjectedFieldException(fieldName, getTaskName(), - "expected a variable name string" + ", got object of type " + o.getClass().getName()); + "expected a variable name string, got object of type " + o.getClass().getName()); } } @@ -133,9 +138,11 @@ public class BaseTask implements JavaDelegate { Object o = getFieldImpl(expression, execution, fieldName, false); if (o instanceof String) { return (String) o; - } else { + } else if (o != null) { throw new BadInjectedFieldException(fieldName, getTaskName(), "cannot convert '" + o.toString() + "' to Integer"); + } else { + throw new MissingInjectedFieldException(fieldName, getTaskName()); } } @@ -189,8 +196,12 @@ public class BaseTask implements JavaDelegate { try { return Integer.parseInt(o.toString()); } catch (NumberFormatException e) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "cannot convert '" + o.toString() + "' to Integer"); + if (o != null) { + throw new BadInjectedFieldException(fieldName, getTaskName(), + "cannot convert '" + o.toString() + "' to Integer"); + } else { + throw new MissingInjectedFieldException(fieldName, getTaskName()); + } } } } @@ -289,8 +300,12 @@ public class BaseTask implements JavaDelegate { try { return Long.parseLong(o.toString()); } catch (NumberFormatException e) { - throw new BadInjectedFieldException(fieldName, getTaskName(), - "cannot convert '" + o.toString() + "' to Long"); + if (o != null) { + throw new BadInjectedFieldException(fieldName, getTaskName(), + "cannot convert '" + o.toString() + "' to Long"); + } else { + throw new MissingInjectedFieldException(fieldName, getTaskName()); + } } } } -- cgit 1.2.3-korg