Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated IllegalArgumentException to NullPointerException for Null Values in Require Class #11162

Merged
merged 6 commits into from
Oct 26, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions java/src/org/openqa/selenium/internal/Require.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public static void precondition(boolean condition, String message, Object... arg

public static <T> T nonNull(String argName, T arg) {
if (arg == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
return arg;
}

public static <T> T nonNull(String argName, T arg, String message, Object... args) {
if (arg == null) {
throw new IllegalArgumentException(
throw new NullPointerException(
String.join(" ", argName, String.format(message, args)));
}
return arg;
Expand All @@ -75,7 +75,8 @@ public static <T> ArgumentChecker<T> argument(String argName, T arg) {

public static Duration nonNegative(String argName, Duration arg) {
if (arg == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new IllegalArgumentException(String.format(
, argName));
}
if (arg.isNegative()) {
throw new IllegalArgumentException(String.format(MUST_BE_NON_NEGATIVE, argName));
Expand All @@ -85,7 +86,7 @@ public static Duration nonNegative(String argName, Duration arg) {

public static Duration nonNegative(Duration arg) {
if (arg == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, "Duration"));
throw new NullPointerException(String.format(MUST_BE_SET, "Duration"));
}
if (arg.isNegative()) {
throw new IllegalArgumentException(String.format(MUST_BE_NON_NEGATIVE, "Duration"));
Expand All @@ -95,7 +96,7 @@ public static Duration nonNegative(Duration arg) {

public static Duration positive(String argName, Duration arg) {
if (arg == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
if (arg.isNegative() || arg.isZero()) {
throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, argName));
Expand All @@ -105,7 +106,7 @@ public static Duration positive(String argName, Duration arg) {

public static Duration positive(Duration arg) {
if (arg == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, "Duration"));
throw new NullPointerException(String.format(MUST_BE_SET, "Duration"));
}
if (arg.isNegative() || arg.isZero()) {
throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, "Duration"));
Expand All @@ -115,7 +116,7 @@ public static Duration positive(Duration arg) {

public static int nonNegative(String argName, Integer number) {
if (number == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
if (number < 0) {
throw new IllegalArgumentException(String.format(MUST_BE_NON_NEGATIVE, argName));
Expand All @@ -125,13 +126,13 @@ public static int nonNegative(String argName, Integer number) {

public static int positive(String argName, Integer number, String message) {
if (number == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
if (number <= 0) {
if (message == null) {
throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
} else {
throw new IllegalArgumentException(message);
throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, message));
}
}
return number;
Expand All @@ -140,7 +141,7 @@ public static int positive(String argName, Integer number, String message) {
public static double positive(String argName, Double number, String message) {
if (number <= 0) {
if (message == null) {
throw new IllegalArgumentException(String.format(MUST_BE_POSITIVE, argName));
throw new NullPointerException(String.format(MUST_BE_POSITIVE, argName));
} else {
throw new IllegalArgumentException(message);
}
Expand Down Expand Up @@ -194,7 +195,7 @@ public static class ArgumentChecker<T> {

public T nonNull() {
if (arg == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
return arg;
}
Expand All @@ -208,7 +209,7 @@ public T nonNull(String message, Object... args) {

public T equalTo(Object other) {
if (arg == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
if (!Objects.equals(arg, other)) {
throw new IllegalArgumentException(String.format(MUST_BE_EQUAL, argName, other));
Expand All @@ -218,7 +219,7 @@ public T equalTo(Object other) {

public T instanceOf(Class<?> cls) {
if (arg == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
if (!cls.isInstance(arg)) {
throw new IllegalArgumentException(argName + " must be an instance of " + cls);
Expand All @@ -239,7 +240,7 @@ public static class IntChecker {

public int greaterThan(int max, String message) {
if (number == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
if (number <= max) {
throw new IllegalArgumentException(message);
Expand All @@ -260,7 +261,7 @@ public static class FileChecker {

public File isFile() {
if (file == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
if (!file.exists()) {
throw new IllegalArgumentException(
Expand All @@ -275,7 +276,7 @@ public File isFile() {

public File isDirectory() {
if (file == null) {
throw new IllegalArgumentException(String.format(MUST_BE_SET, argName));
throw new NullPointerException(String.format(MUST_BE_SET, argName));
}
if (!file.exists()) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -315,7 +316,7 @@ public T nonNull(String message, Object... args) {

public T instanceOf(Class<?> cls) {
if (state == null) {
throw new IllegalStateException(String.format(MUST_BE_SET, name));
throw new NullPointerException(String.format(MUST_BE_SET, name));
}
if (!cls.isInstance(state)) {
throw new IllegalStateException(name + " must be an instance of " + cls);
Expand All @@ -336,7 +337,7 @@ public static class FileStateChecker {

public File isFile() {
if (file == null) {
throw new IllegalStateException(String.format(MUST_BE_SET, name));
throw new NullPointerException(String.format(MUST_BE_SET, name));
}
if (!file.exists()) {
throw new IllegalStateException(String.format(MUST_EXIST, name, file.getAbsolutePath()));
Expand All @@ -349,7 +350,7 @@ public File isFile() {

public File isDirectory() {
if (file == null) {
throw new IllegalStateException(String.format(MUST_BE_SET, name));
throw new NullPointerException(String.format(MUST_BE_SET, name));
}
if (!file.exists()) {
throw new IllegalStateException(String.format(MUST_EXIST, name, file.getAbsolutePath()));
Expand All @@ -373,7 +374,7 @@ public static class PathStateChecker {

public Path isFile() {
if (path == null) {
throw new IllegalStateException(String.format(MUST_BE_SET, name));
throw new NullPointerException(String.format(MUST_BE_SET, name));
}
if (!Files.exists(path)) {
throw new IllegalStateException(String.format(MUST_EXIST, name, path));
Expand All @@ -386,7 +387,7 @@ public Path isFile() {

public Path isDirectory() {
if (path == null) {
throw new IllegalStateException(String.format(MUST_BE_SET, name));
throw new NullPointerException(String.format(MUST_BE_SET, name));
}
if (!Files.exists(path)) {
throw new IllegalStateException(String.format(MUST_EXIST, name, path));
Expand Down