From 8508aafb6f4b70455407b9e5216dd257297bbccc Mon Sep 17 00:00:00 2001 From: Ruud Senden <8635138+rsenden@users.noreply.github.com> Date: Fri, 14 Jul 2023 18:11:20 +0200 Subject: [PATCH] fix: Potential NullPointerException if expression passed to '-o expr=...' returns null --- .../cli/common/output/writer/record/expr/ExprRecordWriter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/output/writer/record/expr/ExprRecordWriter.java b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/output/writer/record/expr/ExprRecordWriter.java index 7078017886..142e885d8c 100644 --- a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/output/writer/record/expr/ExprRecordWriter.java +++ b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/output/writer/record/expr/ExprRecordWriter.java @@ -55,7 +55,8 @@ public void writeRecord(ObjectNode record) { private String getFormattedRecord(ObjectNode record) { try { - return JsonHelper.evaluateSpelExpression(record, expression, String.class); + var result = JsonHelper.evaluateSpelExpression(record, expression, String.class); + return result==null ? "" : result; } catch ( Exception e ) { throw new IllegalStateException(String.format("Error evaluating output expression:\n\tMessage: %s\n\tExpression: %s\n\tRecord: %s", e.getMessage(), getConfig().getOptions(), record.toPrettyString().replace("\n", "\n\t\t"))); }