From 454ae258efbea7cd60646999f236c01c92626e32 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 4 Dec 2024 12:48:41 +0700 Subject: [PATCH] [java] Enhance Null Check in Exception Handling (#14810) --- java/src/org/openqa/selenium/internal/Require.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/java/src/org/openqa/selenium/internal/Require.java b/java/src/org/openqa/selenium/internal/Require.java index 476966a597bb4..4ec171e5a305e 100644 --- a/java/src/org/openqa/selenium/internal/Require.java +++ b/java/src/org/openqa/selenium/internal/Require.java @@ -129,11 +129,8 @@ public static int positive(String argName, Integer number, String message) { throw new IllegalArgumentException(String.format(MUST_BE_SET, argName)); } if (number <= 0) { - if (message == null) { - throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, argName)); - } else { - throw new IllegalArgumentException(message); - } + throw new IllegalArgumentException( + Objects.requireNonNullElseGet(message, () -> String.format(MUST_BE_POSITIVE, argName))); } return number; } @@ -143,11 +140,8 @@ public static double positive(String argName, Double number, String message) { throw new IllegalArgumentException(String.format(MUST_BE_SET, argName)); } if (number <= 0) { - if (message == null) { - throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, argName)); - } else { - throw new IllegalArgumentException(message); - } + throw new IllegalArgumentException( + Objects.requireNonNullElseGet(message, () -> String.format(MUST_BE_POSITIVE, argName))); } return number; }