Fix null message handling in AllowedRegexErrorResponseTransformStrategy. (#13177)

Error messages can be null. If the incoming error message is null, then
return null.
This commit is contained in:
Gian Merlino 2022-10-09 07:42:41 -07:00 committed by GitHub
parent 573e12c75f
commit 5b519f3689
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -51,7 +51,8 @@ public class AllowedRegexErrorResponseTransformStrategy implements ErrorResponse
public Function<String, String> 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;

View File

@ -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()
{