diff options
author | Diego Marcilio <dvmarcilio@gmail.com> | 2023-02-11 16:38:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-11 10:38:50 -0500 |
commit | 680f9d5492e2c9c27e5c1178744a9edf36a0272b (patch) | |
tree | 2a8871b62cccde0656723efbb128ba36d04a114f | |
parent | 3da149382fcc8c8880cc96aba2c93cc575cc4970 (diff) | |
download | apache-commons-lang-680f9d5492e2c9c27e5c1178744a9edf36a0272b.tar.gz |
Add missing javadoc/tests for some null arguments (#869)
7 files changed, 48 insertions, 0 deletions
diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 25d576546..95bf83964 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -3772,6 +3772,7 @@ public class ArrayUtils { * @param comparator the {@link Comparator} to compare over * @param <T> the datatype of the array * @return whether the array is sorted + * @throws NullPointerException if {@code comparator} is {@code null} * @since 3.4 */ public static <T> boolean isSorted(final T[] array, final Comparator<T> comparator) { diff --git a/src/main/java/org/apache/commons/lang3/Range.java b/src/main/java/org/apache/commons/lang3/Range.java index b93a557d3..66cb5ddf4 100644 --- a/src/main/java/org/apache/commons/lang3/Range.java +++ b/src/main/java/org/apache/commons/lang3/Range.java @@ -274,6 +274,7 @@ public class Range<T> implements Serializable { * * @param element the element to check for, not null * @return -1, 0 or +1 depending on the element's location relative to the range + * @throws NullPointerException if {@code element} is {@code null} */ public int elementCompareTo(final T element) { // Comparable API says throw NPE on null @@ -329,6 +330,7 @@ public class Range<T> implements Serializable { * </pre> * @param element the element to check for, not null * @return the minimum, the element, or the maximum depending on the element's location relative to the range + * @throws NullPointerException if {@code element} is {@code null} * @since 3.10 */ public T fit(final T element) { diff --git a/src/main/java/org/apache/commons/lang3/builder/ToStringBuilder.java b/src/main/java/org/apache/commons/lang3/builder/ToStringBuilder.java index 020ca4475..231d3fc7a 100644 --- a/src/main/java/org/apache/commons/lang3/builder/ToStringBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/ToStringBuilder.java @@ -907,6 +907,7 @@ public class ToStringBuilder implements Builder<String> { * * @param srcObject the {@link Object} whose class name and id to output * @return this + * @throws NullPointerException if {@code srcObject} is {@code null} * @since 2.0 */ public ToStringBuilder appendAsObjectToString(final Object srcObject) { diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java index c985643c2..83beab013 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java @@ -1543,6 +1543,7 @@ public class TypeUtils { * @param rawClass the raw class to create a parameterized type instance for * @param typeVariableMap the map used for parameterization * @return {@link ParameterizedType} + * @throws NullPointerException if either {@code rawClass} or {@code typeVariableMap} is {@code null} * @since 3.2 */ public static final ParameterizedType parameterize(final Class<?> rawClass, @@ -1559,6 +1560,7 @@ public class TypeUtils { * @param rawClass the raw class to create a parameterized type instance for * @param typeArguments the types used for parameterization * @return {@link ParameterizedType} + * @throws NullPointerException if {@code rawClass} is {@code null} * @since 3.2 */ public static final ParameterizedType parameterize(final Class<?> rawClass, final Type... typeArguments) { @@ -1607,6 +1609,8 @@ public class TypeUtils { * @param rawClass the raw class to create a parameterized type instance for * @param typeVariableMap the map used for parameterization * @return {@link ParameterizedType} + * @throws NullPointerException if either {@code rawClass} or {@code typeVariableMap} + * is {@code null} * @since 3.2 */ public static final ParameterizedType parameterizeWithOwner(final Type owner, final Class<?> rawClass, @@ -1625,6 +1629,7 @@ public class TypeUtils { * @param typeArguments the types used for parameterization * * @return {@link ParameterizedType} + * @throws NullPointerException if {@code rawClass} is {@code null} * @since 3.2 */ public static final ParameterizedType parameterizeWithOwner(final Type owner, final Class<?> rawClass, diff --git a/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java index 46a2a3d70..64a244764 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java @@ -610,6 +610,13 @@ public class ToStringBuilderTest extends AbstractLangTest { } @Test + public void testAppendAsObjectToStringNullPointerException() { + ToStringBuilder builder = new ToStringBuilder(1); + assertThrows(NullPointerException.class, () -> builder.appendAsObjectToString(null)); + builder.toString(); + } + + @Test public void testAppendBooleanArrayWithFieldName() { final boolean[] array = { true, false, false }; assertEquals(baseStr + "[flags={true,false,false}]", diff --git a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java index 7dd4affed..49f2c0d7d 100644 --- a/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/reflect/TypeUtilsTest.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.awt.Insets; @@ -948,6 +949,18 @@ public class TypeUtilsTest<B> extends AbstractLangTest { } @Test + public void testParameterizeNullPointerException() { + assertThrows(NullPointerException.class, () -> TypeUtils.parameterize(null, Collections.emptyMap())); + final Map<TypeVariable<?>, Type> nullTypeVariableMap = null; + assertThrows(NullPointerException.class, () -> TypeUtils.parameterize(String.class, nullTypeVariableMap)); + } + + @Test + public void testParameterizeVarArgsNullPointerException() { + assertThrows(NullPointerException.class, () -> TypeUtils.parameterize(null)); + } + + @Test public void testParameterizeWithOwner() throws Exception { final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class); final ParameterizedType dat2Type = TypeUtils.parameterizeWithOwner(owner, That.class, String.class, String.class); @@ -955,6 +968,20 @@ public class TypeUtilsTest<B> extends AbstractLangTest { } @Test + public void testParameterizeWithOwner3ArgsNullPointerException() { + final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class); + assertThrows(NullPointerException.class, () -> TypeUtils.parameterizeWithOwner(owner, null, String.class)); + final Map<TypeVariable<?>, Type> nullTypeVariableMap = null; + assertThrows(NullPointerException.class, () -> TypeUtils.parameterizeWithOwner(owner, That.class, nullTypeVariableMap)); + } + + @Test + public void testParameterizeWithOwnerVarArgsNullPointerException() { + final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class); + assertThrows(NullPointerException.class, () -> TypeUtils.parameterizeWithOwner(owner, null)); + } + + @Test public void testToLongString() { assertEquals(getClass().getName() + ":B", TypeUtils.toLongString(getClass().getTypeParameters()[0])); } diff --git a/src/test/java/org/apache/commons/lang3/time/DurationUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DurationUtilsTest.java index d3d8f3126..af258c79a 100644 --- a/src/test/java/org/apache/commons/lang3/time/DurationUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/time/DurationUtilsTest.java @@ -144,6 +144,11 @@ public class DurationUtilsTest extends AbstractLangTest { } @Test + public void testToMillisIntNullDuration() { + assertThrows(NullPointerException.class, () -> DurationUtils.toMillisInt(null)); + } + + @Test public void testZeroIfNull() { assertEquals(Duration.ZERO, DurationUtils.zeroIfNull(null)); assertEquals(Duration.ofDays(1), DurationUtils.zeroIfNull(Duration.ofDays(1))); |