From 32cec8b9c15363edac68405821d2625ff04585f5 Mon Sep 17 00:00:00 2001 From: andsel Date: Tue, 23 Jul 2024 18:01:33 +0200 Subject: [PATCH] Better error catching for non comparables in event condition and added NPE protection when left or right side of evend conditions are null --- .../org/logstash/config/ir/compiler/EventCondition.java | 8 ++++++-- .../main/java/org/logstash/config/ir/compiler/Utils.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/logstash-core/src/main/java/org/logstash/config/ir/compiler/EventCondition.java b/logstash-core/src/main/java/org/logstash/config/ir/compiler/EventCondition.java index a68ec8a9888..ab3c867f4f2 100644 --- a/logstash-core/src/main/java/org/logstash/config/ir/compiler/EventCondition.java +++ b/logstash-core/src/main/java/org/logstash/config/ir/compiler/EventCondition.java @@ -709,9 +709,13 @@ private static String getUnexpectedTypeDetails(Object unexpected) { details = (expression.getSourceWithMetadata() != null) ? expression.getSourceWithMetadata().toString() : expression.toString(); } else { - details = unexpected.toString(); + if (unexpected == null) { + details = ""; + } else { + details = unexpected.toString(); + } } - return String.format("%s:%s", unexpected.getClass(), details); + return String.format("%s:%s", unexpected == null ? "" : unexpected.getClass(), details); } } } diff --git a/logstash-core/src/main/java/org/logstash/config/ir/compiler/Utils.java b/logstash-core/src/main/java/org/logstash/config/ir/compiler/Utils.java index bbaaa7689e8..9ed5f8e6237 100644 --- a/logstash-core/src/main/java/org/logstash/config/ir/compiler/Utils.java +++ b/logstash-core/src/main/java/org/logstash/config/ir/compiler/Utils.java @@ -50,7 +50,7 @@ public static void filterEvents(Collection input boolean isFulfilled; try { isFulfilled = filter.fulfilled(e); - } catch (org.jruby.exceptions.TypeError ex) { + } catch (org.jruby.exceptions.TypeError | IllegalArgumentException ex) { // in case of error evaluation of an if condition, cancel the event e.getEvent().cancel(); throw new ConditionalEvaluationError(ex, e.getEvent());