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 3700641 Correct Javadocs of methods that use Validate.notNull() and
replace some uses of Validate.isTrue() with Validate.notNull(). (#525)
3700641 is described below
commit 3700641b4e745a1804b4409c58dee15b459dad16
Author: Isira Seneviratne <[email protected]>
AuthorDate: Fri Jul 10 01:26:19 2020 +0000
Correct Javadocs of methods that use Validate.notNull() and replace some
uses of Validate.isTrue() with Validate.notNull(). (#525)
* Update Javadocs of methods that call Validate.notNull() to refer to
NullPointerException instead of IllegalArgumentException for null values.
* Use Validate.notNull() instead of Validate.isTrue() to check for null
values, and update the associated tests to check for NullPointerException
instead of IllegalArgumentException.
---
.../java/org/apache/commons/lang3/CharUtils.java | 6 ++++--
.../apache/commons/lang3/SerializationUtils.java | 14 +++++--------
.../apache/commons/lang3/builder/DiffBuilder.java | 3 +--
.../apache/commons/lang3/builder/DiffResult.java | 3 +--
.../org/apache/commons/lang3/math/Fraction.java | 6 +++---
.../apache/commons/lang3/math/IEEE754rUtils.java | 8 ++++----
.../apache/commons/lang3/reflect/FieldUtils.java | 6 +++---
.../apache/commons/lang3/reflect/MethodUtils.java | 16 ++++++---------
.../org/apache/commons/lang3/time/DateUtils.java | 24 +++++++++++-----------
.../org/apache/commons/lang3/time/FormatCache.java | 2 +-
.../commons/lang3/reflect/MethodUtilsTest.java | 6 +++---
11 files changed, 43 insertions(+), 51 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/CharUtils.java
b/src/main/java/org/apache/commons/lang3/CharUtils.java
index b4e8ccf..4e07693 100644
--- a/src/main/java/org/apache/commons/lang3/CharUtils.java
+++ b/src/main/java/org/apache/commons/lang3/CharUtils.java
@@ -131,7 +131,7 @@ public class CharUtils {
*
* @param ch the character to convert
* @return the char value of the Character
- * @throws IllegalArgumentException if the Character is null
+ * @throws NullPointerException if the Character is null
*/
public static char toChar(final Character ch) {
Validate.notNull(ch, "The Character must not be null");
@@ -172,6 +172,7 @@ public class CharUtils {
*
* @param str the character to convert
* @return the char value of the first letter of the String
+ * @throws NullPointerException if the string is null
* @throws IllegalArgumentException if the String is empty
*/
public static char toChar(final String str) {
@@ -260,7 +261,8 @@ public class CharUtils {
*
* @param ch the character to convert, not null
* @return the int value of the character
- * @throws IllegalArgumentException if the Character is not ASCII numeric
or is null
+ * @throws NullPointerException if the Character is null
+ * @throws IllegalArgumentException if the Character is not ASCII numeric
*/
public static int toIntValue(final Character ch) {
Validate.notNull(ch, "The character must not be null");
diff --git a/src/main/java/org/apache/commons/lang3/SerializationUtils.java
b/src/main/java/org/apache/commons/lang3/SerializationUtils.java
index 5f7ed8c..ed46f2a 100644
--- a/src/main/java/org/apache/commons/lang3/SerializationUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SerializationUtils.java
@@ -129,7 +129,7 @@ public class SerializationUtils {
*
* @param obj the object to serialize to bytes, may be null
* @param outputStream the stream to write to, must not be null
- * @throws IllegalArgumentException if {@code outputStream} is {@code null}
+ * @throws NullPointerException if {@code outputStream} is {@code null}
* @throws SerializationException (runtime) if the serialization fails
*/
public static void serialize(final Serializable obj, final OutputStream
outputStream) {
@@ -182,10 +182,8 @@ public class SerializationUtils {
* @param inputStream
* the serialized object input stream, must not be null
* @return the deserialized object
- * @throws IllegalArgumentException
- * if {@code inputStream} is {@code null}
- * @throws SerializationException
- * (runtime) if the serialization fails
+ * @throws NullPointerException if {@code inputStream} is {@code null}
+ * @throws SerializationException (runtime) if the serialization fails
*/
public static <T> T deserialize(final InputStream inputStream) {
Validate.notNull(inputStream, "The InputStream must not be null");
@@ -213,10 +211,8 @@ public class SerializationUtils {
* @param objectData
* the serialized object, must not be null
* @return the deserialized object
- * @throws IllegalArgumentException
- * if {@code objectData} is {@code null}
- * @throws SerializationException
- * (runtime) if the serialization fails
+ * @throws NullPointerException if {@code objectData} is {@code null}
+ * @throws SerializationException (runtime) if the serialization fails
*/
public static <T> T deserialize(final byte[] objectData) {
Validate.notNull(objectData, "The byte[] must not be null");
diff --git a/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
b/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
index 2ea1f69..fed655d 100644
--- a/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
@@ -943,8 +943,7 @@ public class DiffBuilder<T> implements
Builder<DiffResult<T>> {
* @param diffResult
* the {@code DiffResult} to append
* @return this
- * @throws IllegalArgumentException
- * if field name is {@code null}
+ * @throws NullPointerException if field name is {@code null}
* @since 3.5
*/
public DiffBuilder<T> append(final String fieldName,
diff --git a/src/main/java/org/apache/commons/lang3/builder/DiffResult.java
b/src/main/java/org/apache/commons/lang3/builder/DiffResult.java
index b8594ad..c55aafc 100644
--- a/src/main/java/org/apache/commons/lang3/builder/DiffResult.java
+++ b/src/main/java/org/apache/commons/lang3/builder/DiffResult.java
@@ -69,8 +69,7 @@ public class DiffResult<T> implements Iterable<Diff<?>> {
* the style to use for the {@link #toString()} method. May be
* {@code null}, in which case
* {@link ToStringStyle#DEFAULT_STYLE} is used
- * @throws IllegalArgumentException
- * if {@code lhs}, {@code rhs} or {@code diffs} is {@code null}
+ * @throws NullPointerException if {@code lhs}, {@code rhs} or {@code
diffs} is {@code null}
*/
DiffResult(final T lhs, final T rhs, final List<Diff<?>> diffs,
final ToStringStyle style) {
diff --git a/src/main/java/org/apache/commons/lang3/math/Fraction.java
b/src/main/java/org/apache/commons/lang3/math/Fraction.java
index 7c11f2a..e90e340 100644
--- a/src/main/java/org/apache/commons/lang3/math/Fraction.java
+++ b/src/main/java/org/apache/commons/lang3/math/Fraction.java
@@ -308,7 +308,7 @@ public final class Fraction extends Number implements
Comparable<Fraction> {
*
* @param str the string to parse, must not be {@code null}
* @return the new {@code Fraction} instance
- * @throws IllegalArgumentException if the string is {@code null}
+ * @throws NullPointerException if the string is {@code null}
* @throws NumberFormatException if the number format is invalid
*/
public static Fraction getFraction(String str) {
@@ -773,7 +773,7 @@ public final class Fraction extends Number implements
Comparable<Fraction> {
*
* @param fraction the fraction to multiply by, must not be {@code null}
* @return a {@code Fraction} instance with the resulting values
- * @throws IllegalArgumentException if the fraction is {@code null}
+ * @throws NullPointerException if the fraction is {@code null}
* @throws ArithmeticException if the resulting numerator or denominator
exceeds
* {@code Integer.MAX_VALUE}
*/
@@ -795,7 +795,7 @@ public final class Fraction extends Number implements
Comparable<Fraction> {
*
* @param fraction the fraction to divide by, must not be {@code null}
* @return a {@code Fraction} instance with the resulting values
- * @throws IllegalArgumentException if the fraction is {@code null}
+ * @throws NullPointerException if the fraction is {@code null}
* @throws ArithmeticException if the fraction to divide by is zero
* @throws ArithmeticException if the resulting numerator or denominator
exceeds
* {@code Integer.MAX_VALUE}
diff --git a/src/main/java/org/apache/commons/lang3/math/IEEE754rUtils.java
b/src/main/java/org/apache/commons/lang3/math/IEEE754rUtils.java
index ae737cf..1af353d 100644
--- a/src/main/java/org/apache/commons/lang3/math/IEEE754rUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/IEEE754rUtils.java
@@ -32,7 +32,7 @@ public class IEEE754rUtils {
*
* @param array an array, must not be null or empty
* @return the minimum value in the array
- * @throws IllegalArgumentException if {@code array} is {@code null}
+ * @throws NullPointerException if {@code array} is {@code null}
* @throws IllegalArgumentException if {@code array} is empty
* @since 3.4 Changed signature from min(double[]) to min(double...)
*/
@@ -54,7 +54,7 @@ public class IEEE754rUtils {
*
* @param array an array, must not be null or empty
* @return the minimum value in the array
- * @throws IllegalArgumentException if {@code array} is {@code null}
+ * @throws NullPointerException if {@code array} is {@code null}
* @throws IllegalArgumentException if {@code array} is empty
* @since 3.4 Changed signature from min(float[]) to min(float...)
*/
@@ -144,7 +144,7 @@ public class IEEE754rUtils {
*
* @param array an array, must not be null or empty
* @return the minimum value in the array
- * @throws IllegalArgumentException if {@code array} is {@code null}
+ * @throws NullPointerException if {@code array} is {@code null}
* @throws IllegalArgumentException if {@code array} is empty
* @since 3.4 Changed signature from max(double[]) to max(double...)
*/
@@ -166,7 +166,7 @@ public class IEEE754rUtils {
*
* @param array an array, must not be null or empty
* @return the minimum value in the array
- * @throws IllegalArgumentException if {@code array} is {@code null}
+ * @throws NullPointerException if {@code array} is {@code null}
* @throws IllegalArgumentException if {@code array} is empty
* @since 3.4 Changed signature from max(float[]) to max(float...)
*/
diff --git a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
index 2a78f58..0e1ed7a 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java
@@ -81,9 +81,9 @@ public class FieldUtils {
* {@link
java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code
false} will only
* match {@code public} fields.
* @return the Field object
- * @throws IllegalArgumentException
- * if the class is {@code null}, or the field name is blank or
empty or is matched at multiple places
- * in the inheritance hierarchy
+ * @throws NullPointerException if the class is {@code null}
+ * @throws IllegalArgumentException if the field name is blank or empty or
is matched at multiple places
+ * in the inheritance hierarchy
*/
public static Field getField(final Class<?> cls, final String fieldName,
final boolean forceAccess) {
Validate.notNull(cls, "The class must not be null");
diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
index 125bba3..3ddeac5 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
@@ -847,8 +847,7 @@ public class MethodUtils {
* @param annotationCls
* the {@link java.lang.annotation.Annotation} that must be
present on a method to be matched
* @return an array of Methods (possibly empty).
- * @throws IllegalArgumentException
- * if the class or annotation are {@code null}
+ * @throws NullPointerException if the class or annotation are {@code null}
* @since 3.4
*/
public static Method[] getMethodsWithAnnotation(final Class<?> cls, final
Class<? extends Annotation> annotationCls) {
@@ -881,8 +880,7 @@ public class MethodUtils {
* @param ignoreAccess
* determines if non public methods should be considered
* @return an array of Methods (possibly empty).
- * @throws IllegalArgumentException
- * if the class or annotation are {@code null}
+ * @throws NullPointerException if the class or annotation are {@code null}
* @since 3.6
*/
public static Method[] getMethodsWithAnnotation(final Class<?> cls, final
Class<? extends Annotation> annotationCls,
@@ -903,8 +901,7 @@ public class MethodUtils {
* @param ignoreAccess
* determines if non public methods should be considered
* @return a list of Methods (possibly empty).
- * @throws IllegalArgumentException
- * if the class or annotation are {@code null}
+ * @throws NullPointerException if either the class or annotation class is
{@code null}
* @since 3.6
*/
public static List<Method> getMethodsListWithAnnotation(final Class<?> cls,
@@ -912,7 +909,7 @@ public class MethodUtils {
final boolean
searchSupers, final boolean ignoreAccess) {
Validate.notNull(cls, "The class must not be null");
- Validate.isTrue(annotationCls != null, "The annotation class must not
be null");
+ Validate.notNull(annotationCls, "The annotation class must not be
null");
final List<Class<?>> classes = (searchSupers ?
getAllSuperclassesAndInterfaces(cls)
: new ArrayList<>());
classes.add(0, cls);
@@ -947,15 +944,14 @@ public class MethodUtils {
* @param ignoreAccess
* determines if underlying method has to be accessible
* @return the first matching annotation, or {@code null} if not found
- * @throws IllegalArgumentException
- * if the method or annotation are {@code null}
+ * @throws NullPointerException if either the method or annotation class
is {@code null}
* @since 3.6
*/
public static <A extends Annotation> A getAnnotation(final Method method,
final Class<A> annotationCls,
final boolean
searchSupers, final boolean ignoreAccess) {
Validate.notNull(method, "The method must not be null");
- Validate.isTrue(annotationCls != null, "The annotation class must not
be null");
+ Validate.notNull(annotationCls, "The annotation class must not be
null");
if (!ignoreAccess && !MemberUtils.isAccessible(method)) {
return null;
}
diff --git a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
index fd34049..917515d 100644
--- a/src/main/java/org/apache/commons/lang3/time/DateUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DateUtils.java
@@ -509,7 +509,7 @@ public class DateUtils {
* @param calendarField the calendar field to add to
* @param amount the amount to add, may be negative
* @return the new {@code Date} with the amount added
- * @throws IllegalArgumentException if the date is null
+ * @throws NullPointerException if the date is null
*/
private static Date add(final Date date, final int calendarField, final
int amount) {
validateDateNotNull(date);
@@ -736,7 +736,7 @@ public class DateUtils {
* @param date the date to work with, not null
* @param field the field from {@code Calendar} or {@code SEMI_MONTH}
* @return the different rounded date, not null
- * @throws IllegalArgumentException if the date is {@code null}
+ * @throws NullPointerException if the date is {@code null}
* @throws ArithmeticException if the year is over 280 million
*/
public static Calendar round(final Calendar date, final int field) {
@@ -776,7 +776,7 @@ public class DateUtils {
* @param date the date to work with, either {@code Date} or {@code
Calendar}, not null
* @param field the field from {@code Calendar} or {@code SEMI_MONTH}
* @return the different rounded date, not null
- * @throws IllegalArgumentException if the date is {@code null}
+ * @throws NullPointerException if the date is {@code null}
* @throws ClassCastException if the object type is not a {@code Date} or
{@code Calendar}
* @throws ArithmeticException if the year is over 280 million
*/
@@ -806,7 +806,7 @@ public class DateUtils {
* @param date the date to work with, not null
* @param field the field from {@code Calendar} or {@code SEMI_MONTH}
* @return the different truncated date, not null
- * @throws IllegalArgumentException if the date is {@code null}
+ * @throws NullPointerException if the date is {@code null}
* @throws ArithmeticException if the year is over 280 million
*/
public static Date truncate(final Date date, final int field) {
@@ -829,7 +829,7 @@ public class DateUtils {
* @param date the date to work with, not null
* @param field the field from {@code Calendar} or {@code SEMI_MONTH}
* @return the different truncated date, not null
- * @throws IllegalArgumentException if the date is {@code null}
+ * @throws NullPointerException if the date is {@code null}
* @throws ArithmeticException if the year is over 280 million
*/
public static Calendar truncate(final Calendar date, final int field) {
@@ -853,7 +853,7 @@ public class DateUtils {
* @param date the date to work with, either {@code Date} or {@code
Calendar}, not null
* @param field the field from {@code Calendar} or {@code SEMI_MONTH}
* @return the different truncated date, not null
- * @throws IllegalArgumentException if the date is {@code null}
+ * @throws NullPointerException if the date is {@code null}
* @throws ClassCastException if the object type is not a {@code Date} or
{@code Calendar}
* @throws ArithmeticException if the year is over 280 million
*/
@@ -883,7 +883,7 @@ public class DateUtils {
* @param date the date to work with, not null
* @param field the field from {@code Calendar} or {@code SEMI_MONTH}
* @return the different ceil date, not null
- * @throws IllegalArgumentException if the date is {@code null}
+ * @throws NullPointerException if the date is {@code null}
* @throws ArithmeticException if the year is over 280 million
* @since 2.5
*/
@@ -907,7 +907,7 @@ public class DateUtils {
* @param date the date to work with, not null
* @param field the field from {@code Calendar} or {@code SEMI_MONTH}
* @return the different ceil date, not null
- * @throws IllegalArgumentException if the date is {@code null}
+ * @throws NullPointerException if the date is {@code null}
* @throws ArithmeticException if the year is over 280 million
* @since 2.5
*/
@@ -932,7 +932,7 @@ public class DateUtils {
* @param date the date to work with, either {@code Date} or {@code
Calendar}, not null
* @param field the field from {@code Calendar} or {@code SEMI_MONTH}
* @return the different ceil date, not null
- * @throws IllegalArgumentException if the date is {@code null}
+ * @throws NullPointerException if the date is {@code null}
* @throws ClassCastException if the object type is not a {@code Date} or
{@code Calendar}
* @throws ArithmeticException if the year is over 280 million
* @since 2.5
@@ -1121,7 +1121,7 @@ public class DateUtils {
* {@link DateUtils#RANGE_WEEK_RELATIVE},
* {@link DateUtils#RANGE_WEEK_CENTER}
* @return the date iterator, not null, not null
- * @throws IllegalArgumentException if the date is {@code null}
+ * @throws NullPointerException if the date is {@code null}
* @throws IllegalArgumentException if the rangeStyle is invalid
*/
public static Iterator<Calendar> iterator(final Date focus, final int
rangeStyle) {
@@ -1643,8 +1643,8 @@ public class DateUtils {
* @param fragment the Calendar field part of date to calculate
* @param unit the time unit
* @return number of units within the fragment of the date
- * @throws IllegalArgumentException if the date is {@code null} or
- * fragment is not supported
+ * @throws NullPointerException if the date is {@code null}
+ * @throws IllegalArgumentException if fragment is not supported
* @since 2.4
*/
private static long getFragment(final Date date, final int fragment, final
TimeUnit unit) {
diff --git a/src/main/java/org/apache/commons/lang3/time/FormatCache.java
b/src/main/java/org/apache/commons/lang3/time/FormatCache.java
index 08e78ae..a268203 100644
--- a/src/main/java/org/apache/commons/lang3/time/FormatCache.java
+++ b/src/main/java/org/apache/commons/lang3/time/FormatCache.java
@@ -65,8 +65,8 @@ abstract class FormatCache<F extends Format> {
* @param timeZone the time zone, null means use the default TimeZone
* @param locale the locale, null means use the default Locale
* @return a pattern based date/time formatter
+ * @throws NullPointerException if pattern is {@code null}
* @throws IllegalArgumentException if pattern is invalid
- * or {@code null}
*/
public F getInstance(final String pattern, TimeZone timeZone, Locale
locale) {
Validate.notNull(pattern, "pattern must not be null");
diff --git
a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
index ceafcac..5a6820d 100644
--- a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
@@ -863,7 +863,7 @@ public class MethodUtilsTest {
@Test
public void testGetMethodsWithAnnotationIllegalArgumentException1() {
- assertThrows(IllegalArgumentException.class, () ->
MethodUtils.getMethodsWithAnnotation(FieldUtilsTest.class, null));
+ assertThrows(NullPointerException.class, () ->
MethodUtils.getMethodsWithAnnotation(FieldUtilsTest.class, null));
}
@Test
@@ -891,7 +891,7 @@ public class MethodUtilsTest {
@Test
public void testGetMethodsListWithAnnotationIllegalArgumentException1() {
- assertThrows(IllegalArgumentException.class, () ->
MethodUtils.getMethodsListWithAnnotation(FieldUtilsTest.class, null));
+ assertThrows(NullPointerException.class, () ->
MethodUtils.getMethodsListWithAnnotation(FieldUtilsTest.class, null));
}
@Test
@@ -906,7 +906,7 @@ public class MethodUtilsTest {
@Test
public void testGetAnnotationIllegalArgumentException1() {
- assertThrows(IllegalArgumentException.class,
+ assertThrows(NullPointerException.class,
() ->
MethodUtils.getAnnotation(FieldUtilsTest.class.getDeclaredMethods()[0], null,
true, true));
}