diff --git a/core/src/main/java/org/apache/druid/common/exception/AllowedRegexErrorResponseTransformStrategy.java b/core/src/main/java/org/apache/druid/common/exception/AllowedRegexErrorResponseTransformStrategy.java index dde76bddf7c..43b7b14325c 100644 --- a/core/src/main/java/org/apache/druid/common/exception/AllowedRegexErrorResponseTransformStrategy.java +++ b/core/src/main/java/org/apache/druid/common/exception/AllowedRegexErrorResponseTransformStrategy.java @@ -51,7 +51,8 @@ public class AllowedRegexErrorResponseTransformStrategy implements ErrorResponse public Function getErrorMessageTransformFunction() { return (String errorMessage) -> { - if (allowedRegexPattern.stream().anyMatch(pattern -> pattern.matcher(errorMessage).matches())) { + if (errorMessage == null || allowedRegexPattern.stream() + .anyMatch(pattern -> pattern.matcher(errorMessage).matches())) { return errorMessage; } else { return null; diff --git a/core/src/test/java/org/apache/druid/common/exception/AllowedRegexErrorResponseTransformStrategyTest.java b/core/src/test/java/org/apache/druid/common/exception/AllowedRegexErrorResponseTransformStrategyTest.java index 9ababc860b2..3f3fbeca1ce 100644 --- a/core/src/test/java/org/apache/druid/common/exception/AllowedRegexErrorResponseTransformStrategyTest.java +++ b/core/src/test/java/org/apache/druid/common/exception/AllowedRegexErrorResponseTransformStrategyTest.java @@ -59,6 +59,16 @@ public class AllowedRegexErrorResponseTransformStrategyTest Assert.assertNull(result); } + @Test + public void testGetErrorMessageTransformFunctionWithNullMessage() + { + AllowedRegexErrorResponseTransformStrategy allowedRegex = new AllowedRegexErrorResponseTransformStrategy( + ImmutableList.of("acbd", "qwer") + ); + String result = allowedRegex.getErrorMessageTransformFunction().apply(null); + Assert.assertNull(result); + } + @Test public void testEqualsAndHashCode() {