This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 3744263 Use Objects.requireNonNull() instead of custom check. Minor
formatting.
3744263 is described below
commit 37442639705892348d2cd6d7717fff4d9841ca09
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Dec 25 23:00:43 2019 -0500
Use Objects.requireNonNull() instead of custom check. Minor formatting.
---
.../java/org/apache/commons/lang3/Functions.java | 12 +++++-----
.../java/org/apache/commons/lang3/Validate.java | 26 ++++++----------------
.../commons/lang3/builder/CompareToBuilder.java | 7 +++---
3 files changed, 16 insertions(+), 29 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/Functions.java
b/src/main/java/org/apache/commons/lang3/Functions.java
index db422ad..2d0ca06 100644
--- a/src/main/java/org/apache/commons/lang3/Functions.java
+++ b/src/main/java/org/apache/commons/lang3/Functions.java
@@ -19,6 +19,7 @@ package org.apache.commons.lang3;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
@@ -433,10 +434,8 @@ public class Functions {
errorHandler = pErrorHandler;
}
if (pResources != null) {
- for (FailableRunnable<? extends Throwable> runnable : pResources) {
- if (runnable == null) {
- throw new NullPointerException("A resource action must not
be null.");
- }
+ for (FailableRunnable<? extends Throwable> failableRunnable :
pResources) {
+ Objects.requireNonNull(failableRunnable, "runnable");
}
}
Throwable th = null;
@@ -514,9 +513,8 @@ public class Functions {
* @return Never returns anything, this method never terminates normally.
*/
public static RuntimeException rethrow(Throwable pThrowable) {
- if (pThrowable == null) {
- throw new NullPointerException("The Throwable must not be null.");
- } else if (pThrowable instanceof RuntimeException) {
+ Objects.requireNonNull(pThrowable, "pThrowable");
+ if (pThrowable instanceof RuntimeException) {
throw (RuntimeException) pThrowable;
} else if (pThrowable instanceof Error) {
throw (Error) pThrowable;
diff --git a/src/main/java/org/apache/commons/lang3/Validate.java
b/src/main/java/org/apache/commons/lang3/Validate.java
index 9808990..bfd6719 100644
--- a/src/main/java/org/apache/commons/lang3/Validate.java
+++ b/src/main/java/org/apache/commons/lang3/Validate.java
@@ -19,6 +19,7 @@ package org.apache.commons.lang3;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
+import java.util.Objects;
import java.util.regex.Pattern;
/**
@@ -221,10 +222,7 @@ public class Validate {
* @see #notNull(Object)
*/
public static <T> T notNull(final T object, final String message, final
Object... values) {
- if (object == null) {
- throw new NullPointerException(String.format(message, values));
- }
- return object;
+ return Objects.requireNonNull(object, () -> String.format(message,
values));
}
// notEmpty array
@@ -247,9 +245,7 @@ public class Validate {
* @see #notEmpty(Object[])
*/
public static <T> T[] notEmpty(final T[] array, final String message,
final Object... values) {
- if (array == null) {
- throw new NullPointerException(String.format(message, values));
- }
+ Objects.requireNonNull(array, () -> String.format(message, values));
if (array.length == 0) {
throw new IllegalArgumentException(String.format(message, values));
}
@@ -296,9 +292,7 @@ public class Validate {
* @see #notEmpty(Object[])
*/
public static <T extends Collection<?>> T notEmpty(final T collection,
final String message, final Object... values) {
- if (collection == null) {
- throw new NullPointerException(String.format(message, values));
- }
+ Objects.requireNonNull(collection, () -> String.format(message,
values));
if (collection.isEmpty()) {
throw new IllegalArgumentException(String.format(message, values));
}
@@ -345,9 +339,7 @@ public class Validate {
* @see #notEmpty(Object[])
*/
public static <T extends Map<?, ?>> T notEmpty(final T map, final String
message, final Object... values) {
- if (map == null) {
- throw new NullPointerException(String.format(message, values));
- }
+ Objects.requireNonNull(map, () -> String.format(message, values));
if (map.isEmpty()) {
throw new IllegalArgumentException(String.format(message, values));
}
@@ -394,9 +386,7 @@ public class Validate {
* @see #notEmpty(CharSequence)
*/
public static <T extends CharSequence> T notEmpty(final T chars, final
String message, final Object... values) {
- if (chars == null) {
- throw new NullPointerException(String.format(message, values));
- }
+ Objects.requireNonNull(chars, () -> String.format(message, values));
if (chars.length() == 0) {
throw new IllegalArgumentException(String.format(message, values));
}
@@ -447,9 +437,7 @@ public class Validate {
* @since 3.0
*/
public static <T extends CharSequence> T notBlank(final T chars, final
String message, final Object... values) {
- if (chars == null) {
- throw new NullPointerException(String.format(message, values));
- }
+ Objects.requireNonNull(chars, () -> String.format(message, values));
if (StringUtils.isBlank(chars)) {
throw new IllegalArgumentException(String.format(message, values));
}
diff --git
a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
index 553b291..03ca984 100644
--- a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
@@ -21,6 +21,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Comparator;
+import java.util.Objects;
import org.apache.commons.lang3.ArrayUtils;
@@ -282,9 +283,9 @@ public class CompareToBuilder implements Builder<Integer> {
if (lhs == rhs) {
return 0;
}
- if (lhs == null || rhs == null) {
- throw new NullPointerException();
- }
+ Objects.requireNonNull(lhs, "lhs");
+ Objects.requireNonNull(rhs, "rhs");
+
Class<?> lhsClazz = lhs.getClass();
if (!lhsClazz.isInstance(rhs)) {
throw new ClassCastException();