[LANG-1681] - fix some javadoc on FieldUtils methods (#1047)

* [LANG-1681] - fix some javadoc on FieldUtils methods

* [LANG-1681] - fixing javadoc on FieldUtils methods and adding tests

[LANG-1681] - fixing javadoc on DiffBuilder

[LANG-1681] - fixing javadoc on HashCodeBuilder

[LANG-1681] - adding `@throws` javadoc on ClassPathUtils

[LANG-1681] - fixing javadoc on Fraction

[LANG-1681] - add missing javadoc and tests on RandomStringUtils

[LANG-1681] - one fix and add missing javadoc/tests on MethodUtils

[LANG-1681] - add missing javadoc/tests on TypeUtils

---------

Co-authored-by: Laurent SCHOELENS <laurent.schoelens@sfr.com>
Co-authored-by: Diego Marcilio <dvmarcilio@gmail.com>
This commit is contained in:
laurentschoelens 2023-04-17 14:58:49 +02:00 committed by GitHub
parent 860a343217
commit f19416ae37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 401 additions and 117 deletions

View File

@ -35,6 +35,7 @@ public class ClassPathUtils {
*
* @param path the source path.
* @return a package name.
* @throws NullPointerException if {@code path} is null.
* @since 3.13.0
*/
public static String packageToPath(final String path) {
@ -46,6 +47,7 @@ public class ClassPathUtils {
*
* @param path the source path.
* @return a package name.
* @throws NullPointerException if {@code path} is null.
* @since 3.13.0
*/
public static String pathToPackage(final String path) {

View File

@ -62,6 +62,7 @@ public class RandomStringUtils {
*
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
*/
public static String random(final int count) {
return random(count, false, false);
@ -80,6 +81,7 @@ public class RandomStringUtils {
* @param numbers if {@code true}, generated string may include
* numeric characters
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
*/
public static String random(final int count, final boolean letters, final boolean numbers) {
return random(count, 0, 0, letters, numbers);
@ -119,6 +121,7 @@ public class RandomStringUtils {
* @param numbers if {@code true}, generated string may include
* numeric characters
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
*/
public static String random(final int count, final int start, final int end, final boolean letters, final boolean numbers) {
return random(count, start, end, letters, numbers, null, random());
@ -145,6 +148,7 @@ public class RandomStringUtils {
* @return the random string
* @throws ArrayIndexOutOfBoundsException if there are not
* {@code (end - start) + 1} characters in the set array.
* @throws IllegalArgumentException if {@code count} &lt; 0.
*/
public static String random(final int count, final int start, final int end, final boolean letters, final boolean numbers, final char... chars) {
return random(count, start, end, letters, numbers, chars, random());
@ -291,6 +295,7 @@ public class RandomStringUtils {
*
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
*/
public static String randomAlphabetic(final int count) {
return random(count, true, false);
@ -320,6 +325,7 @@ public class RandomStringUtils {
*
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
*/
public static String randomAlphanumeric(final int count) {
return random(count, true, true);
@ -350,6 +356,7 @@ public class RandomStringUtils {
*
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
*/
public static String randomAscii(final int count) {
return random(count, 32, 127, false, false);
@ -380,6 +387,7 @@ public class RandomStringUtils {
*
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @since 3.5
*/
public static String randomGraph(final int count) {
@ -410,6 +418,7 @@ public class RandomStringUtils {
*
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
*/
public static String randomNumeric(final int count) {
return random(count, false, true);
@ -439,6 +448,7 @@ public class RandomStringUtils {
*
* @param count the length of random string to create
* @return the random string
* @throws IllegalArgumentException if {@code count} &lt; 0.
* @since 3.5
*/
public static String randomPrint(final int count) {

View File

@ -94,7 +94,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* without creating a field {@link Diff} if the trivially equal
* test is enabled and returns true. The result of this test
* is never changed throughout the life of this {@link DiffBuilder}.
* @throws IllegalArgumentException
* @throws NullPointerException
* if {@code lhs} or {@code rhs} is {@code null}
* @since 3.4
*/
@ -134,7 +134,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param style
* the style will use when outputting the objects, {@code null}
* uses the default
* @throws IllegalArgumentException
* @throws NullPointerException
* if {@code lhs} or {@code rhs} is {@code null}
*/
public DiffBuilder(final T lhs, final T rhs,
@ -153,7 +153,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code boolean}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final boolean lhs,
@ -191,7 +191,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code boolean[]}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final boolean[] lhs,
@ -228,7 +228,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code byte}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final byte lhs,
@ -265,7 +265,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code byte[]}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final byte[] lhs,
@ -303,7 +303,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code char}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final char lhs,
@ -341,7 +341,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code char[]}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final char[] lhs,
@ -379,7 +379,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code double}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final double lhs,
@ -417,7 +417,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code double[]}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final double[] lhs,
@ -455,7 +455,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code float}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final float lhs,
@ -493,7 +493,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code float[]}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final float[] lhs,
@ -531,7 +531,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code int}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final int lhs,
@ -569,7 +569,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code int[]}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final int[] lhs,
@ -607,7 +607,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code long}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final long lhs,
@ -645,7 +645,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code long[]}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final long[] lhs,
@ -683,7 +683,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code short}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final short lhs,
@ -721,7 +721,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code short[]}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final short[] lhs,
@ -759,7 +759,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@link Object}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final Object lhs,
@ -841,7 +841,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param rhs
* the right-hand {@code Object[]}
* @return this
* @throws IllegalArgumentException
* @throws NullPointerException
* if field name is {@code null}
*/
public DiffBuilder<T> append(final String fieldName, final Object[] lhs,
@ -900,7 +900,7 @@ public class DiffBuilder<T> implements Builder<DiffResult<T>> {
* @param diffResult
* the {@link DiffResult} to append
* @return this
* @throws NullPointerException if field name is {@code null}
* @throws NullPointerException if field name is {@code null} or diffResult is {@code null}
* @since 3.5
*/
public DiffBuilder<T> append(final String fieldName, final DiffResult<T> diffResult) {

View File

@ -237,7 +237,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* @param object
* the Object to create a {@code hashCode} for
* @return int hash code
* @throws IllegalArgumentException
* @throws NullPointerException
* if the Object is {@code null}
* @throws IllegalArgumentException
* if the number is zero or even
@ -281,7 +281,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* @param testTransients
* whether to include transient fields
* @return int hash code
* @throws IllegalArgumentException
* @throws NullPointerException
* if the Object is {@code null}
* @throws IllegalArgumentException
* if the number is zero or even
@ -333,7 +333,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* @param excludeFields
* array of field names to exclude from use in calculation of hash code
* @return int hash code
* @throws IllegalArgumentException
* @throws NullPointerException
* if the Object is {@code null}
* @throws IllegalArgumentException
* if the number is zero or even
@ -382,7 +382,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* @param testTransients
* whether to include transient fields
* @return int hash code
* @throws IllegalArgumentException
* @throws NullPointerException
* if the object is {@code null}
*
* @see HashCodeExclude
@ -420,7 +420,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* @param excludeFields
* Collection of String field names to exclude from use in calculation of hash code
* @return int hash code
* @throws IllegalArgumentException
* @throws NullPointerException
* if the object is {@code null}
*
* @see HashCodeExclude
@ -457,7 +457,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* @param excludeFields
* array of field names to exclude from use in calculation of hash code
* @return int hash code
* @throws IllegalArgumentException
* @throws NullPointerException
* if the object is {@code null}
*
* @see HashCodeExclude

View File

@ -129,7 +129,7 @@ public class ToStringBuilder implements Builder<String> {
* that the latest value set is the value returned from {@link #getDefaultStyle}.</p>
*
* @param style the default {@link ToStringStyle}
* @throws IllegalArgumentException if the style is {@code null}
* @throws NullPointerException if the style is {@code null}
*/
public static void setDefaultStyle(final ToStringStyle style) {
defaultStyle = Objects.requireNonNull(style, "style");

View File

@ -684,7 +684,7 @@ public final class Fraction extends Number implements Comparable<Fraction> {
*
* @param fraction the fraction to add, must not be {@code null}
* @return a {@link 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}
*/
@ -698,7 +698,7 @@ public final class Fraction extends Number implements Comparable<Fraction> {
*
* @param fraction the fraction to subtract, must not be {@code null}
* @return a {@link 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
* cannot be represented in an {@code int}.
*/

View File

@ -60,8 +60,10 @@ public class FieldUtils {
* @param fieldName
* the field name to obtain
* @return the Field object
* @throws NullPointerException
* if the class is {@code null}
* @throws IllegalArgumentException
* if the class is {@code null}, or the field name is blank or empty
* if the field name is {@code null}, blank, or empty
*/
public static Field getField(final Class<?> cls, final String fieldName) {
return MemberUtils.setAccessibleWorkaround(getField(cls, fieldName, false));
@ -143,8 +145,10 @@ public class FieldUtils {
* @param fieldName
* the field name to obtain
* @return the Field object
* @throws NullPointerException
* if the class is {@code null}
* @throws IllegalArgumentException
* if the class is {@code null}, or the field name is blank or empty
* if the field name is {@code null}, blank, or empty
*/
public static Field getDeclaredField(final Class<?> cls, final String fieldName) {
return getDeclaredField(cls, fieldName, false);
@ -163,8 +167,10 @@ public class FieldUtils {
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @return the Field object
* @throws NullPointerException
* if the class is {@code null}
* @throws IllegalArgumentException
* if the class is {@code null}, or the field name is blank or empty
* if the field name is {@code null}, blank, or empty
*/
public static Field getDeclaredField(final Class<?> cls, final String fieldName, final boolean forceAccess) {
Objects.requireNonNull(cls, "cls");
@ -191,7 +197,7 @@ public class FieldUtils {
* @param cls
* the {@link Class} to query
* @return an array of Fields (possibly empty).
* @throws IllegalArgumentException
* @throws NullPointerException
* if the class is {@code null}
* @since 3.2
*/
@ -205,7 +211,7 @@ public class FieldUtils {
* @param cls
* the {@link Class} to query
* @return a list of Fields (possibly empty).
* @throws IllegalArgumentException
* @throws NullPointerException
* if the class is {@code null}
* @since 3.2
*/
@ -228,7 +234,7 @@ public class FieldUtils {
* @param annotationCls
* the {@link Annotation} that must be present on a field to be matched
* @return an array of Fields (possibly empty).
* @throws IllegalArgumentException
* @throws NullPointerException
* if the class or annotation are {@code null}
* @since 3.4
*/
@ -243,7 +249,7 @@ public class FieldUtils {
* @param annotationCls
* the {@link Annotation} that must be present on a field to be matched
* @return a list of Fields (possibly empty).
* @throws IllegalArgumentException
* @throws NullPointerException
* if the class or annotation are {@code null}
* @since 3.4
*/
@ -258,8 +264,10 @@ public class FieldUtils {
* @param field
* to read
* @return the field value
* @throws NullPointerException
* if the field is {@code null}
* @throws IllegalArgumentException
* if the field is {@code null}, or not {@code static}
* if the field is not {@code static}
* @throws IllegalAccessException
* if the field is not accessible
*/
@ -276,8 +284,10 @@ public class FieldUtils {
* whether to break scope restrictions using the
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method.
* @return the field value
* @throws NullPointerException
* if the field is {@code null}
* @throws IllegalArgumentException
* if the field is {@code null} or not {@code static}
* if the field is not {@code static}
* @throws IllegalAccessException
* if the field is not made accessible
*/
@ -295,9 +305,10 @@ public class FieldUtils {
* @param fieldName
* the field name to obtain
* @return the value of the field
* @throws NullPointerException
* if the class is {@code null}, or the field could not be found
* @throws IllegalArgumentException
* if the class is {@code null}, or the field name is blank or empty, is not {@code static}, or could
* not be found
* if the field name is {@code null}, blank or empty, or is not {@code static}
* @throws IllegalAccessException
* if the field is not accessible
*/
@ -317,9 +328,10 @@ public class FieldUtils {
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @return the Field object
* @throws NullPointerException
* if the class is {@code null}, or the field could not be found
* @throws IllegalArgumentException
* if the class is {@code null}, or the field name is blank or empty, is not {@code static}, or could
* not be found
* if the field name is {@code null}, blank or empty, or is not {@code static}
* @throws IllegalAccessException
* if the field is not made accessible
*/
@ -339,9 +351,10 @@ public class FieldUtils {
* @param fieldName
* the field name to obtain
* @return the value of the field
* @throws NullPointerException
* if the class is {@code null}, or the field could not be found
* @throws IllegalArgumentException
* if the class is {@code null}, or the field name is blank or empty, is not {@code static}, or could
* not be found
* if the field name is {@code null}, blank, empty, or is not {@code static}
* @throws IllegalAccessException
* if the field is not accessible
*/
@ -361,9 +374,10 @@ public class FieldUtils {
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @return the Field object
* @throws NullPointerException
* if the class is {@code null}, or the field could not be found
* @throws IllegalArgumentException
* if the class is {@code null}, or the field name is blank or empty, is not {@code static}, or could
* not be found
* if the field name is blank or empty, is not {@code static}
* @throws IllegalAccessException
* if the field is not made accessible
*/
@ -382,7 +396,7 @@ public class FieldUtils {
* @param target
* the object to call on, may be {@code null} for {@code static} fields
* @return the field value
* @throws IllegalArgumentException
* @throws NullPointerException
* if the field is {@code null}
* @throws IllegalAccessException
* if the field is not accessible
@ -402,7 +416,7 @@ public class FieldUtils {
* whether to break scope restrictions using the
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method.
* @return the field value
* @throws IllegalArgumentException
* @throws NullPointerException
* if the field is {@code null}
* @throws IllegalAccessException
* if the field is not made accessible
@ -425,8 +439,10 @@ public class FieldUtils {
* @param fieldName
* the field name to obtain
* @return the value of the field
* @throws NullPointerException
* if the target is {@code null}
* @throws IllegalArgumentException
* if the class is {@code null}, or the field name is blank or empty or could not be found
* if the field name is {@code null}, blank, empty, or could not be found
* @throws IllegalAccessException
* if the named field is not {@code public}
*/
@ -446,8 +462,10 @@ public class FieldUtils {
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @return the field value
* @throws NullPointerException
* if {@code target} is {@code null}
* @throws IllegalArgumentException
* if {@code target} is {@code null}, or the field name is blank or empty or could not be found
* if the field name is {@code null}, blank, empty, or could not be found
* @throws IllegalAccessException
* if the named field is not made accessible
*/
@ -468,8 +486,10 @@ public class FieldUtils {
* @param fieldName
* the field name to obtain
* @return the value of the field
* @throws NullPointerException
* if {@code target} is @{code null}
* @throws IllegalArgumentException
* if {@code target} is {@code null}, or the field name is blank or empty or could not be found
* if {@code fieldName} is {@code null}, blank or empty, or could not be found
* @throws IllegalAccessException
* if the named field is not {@code public}
*/
@ -489,8 +509,10 @@ public class FieldUtils {
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match public fields.
* @return the Field object
* @throws NullPointerException
* if {@code target} is @{code null}
* @throws IllegalArgumentException
* if {@code target} is {@code null}, or the field name is blank or empty or could not be found
* if {@code fieldName} is {@code null}, blank or empty, or could not be found
* @throws IllegalAccessException
* if the field is not made accessible
*/
@ -510,8 +532,10 @@ public class FieldUtils {
* to write
* @param value
* to set
* @throws NullPointerException
* if the field is {@code null}
* @throws IllegalArgumentException
* if the field is {@code null} or not {@code static}, or {@code value} is not assignable
* if the field is not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not {@code public} or is {@code final}
*/
@ -530,8 +554,10 @@ public class FieldUtils {
* whether to break scope restrictions using the
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @throws NullPointerException
* if the field is {@code null}
* @throws IllegalArgumentException
* if the field is {@code null} or not {@code static}, or {@code value} is not assignable
* if the field is not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not made accessible or is {@code final}
*/
@ -551,8 +577,10 @@ public class FieldUtils {
* to write
* @param value
* to set
* @throws NullPointerException
* if {@code target} is @{code null}
* @throws IllegalArgumentException
* if {@code cls} is {@code null}, the field name is blank or empty, the field cannot be located or is
* if {@code fieldName} is {@code null}, blank or empty, the field cannot be located or is
* not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not {@code public} or is {@code final}
@ -574,9 +602,10 @@ public class FieldUtils {
* whether to break scope restrictions using the
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @throws NullPointerException
* if {@code cls} is {@code null} or the field cannot be located
* @throws IllegalArgumentException
* if {@code cls} is {@code null}, the field name is blank or empty, the field cannot be located or is
* not {@code static}, or {@code value} is not assignable
* if {@code fieldName} is {@code null}, blank or empty, the field not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not made accessible or is {@code final}
*/
@ -597,9 +626,10 @@ public class FieldUtils {
* to write
* @param value
* to set
* @throws NullPointerException
* if {@code cls} is {@code null} or the field cannot be located
* @throws IllegalArgumentException
* if {@code cls} is {@code null}, the field name is blank or empty, the field cannot be located or is
* not {@code static}, or {@code value} is not assignable
* if the field name is @{code null}, blank, empty, not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not {@code public} or is {@code final}
*/
@ -619,9 +649,10 @@ public class FieldUtils {
* @param forceAccess
* whether to break scope restrictions using the {@code AccessibleObject#setAccessible(boolean)} method.
* {@code false} will only match {@code public} fields.
* @throws NullPointerException
* if {@code cls} is {@code null} or the field cannot be located
* @throws IllegalArgumentException
* if {@code cls} is {@code null}, the field name is blank or empty, the field cannot be located or is
* not {@code static}, or {@code value} is not assignable
* if the field name is @{code null}, blank, empty, not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not made accessible or is {@code final}
*/
@ -642,9 +673,12 @@ public class FieldUtils {
* the object to call on, may be {@code null} for {@code static} fields
* @param value
* to set
* @throws NullPointerException
* if the field is {@code null}
* @throws IllegalArgumentException
* if {@code value} is not assignable
* @throws IllegalAccessException
* if the field or target is {@code null}, the field is not accessible or is {@code final}, or
* {@code value} is not assignable
* if the field is not accessible or is {@code final}
*/
public static void writeField(final Field field, final Object target, final Object value) throws IllegalAccessException {
writeField(field, target, value, false);
@ -663,8 +697,10 @@ public class FieldUtils {
* whether to break scope restrictions using the
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @throws NullPointerException
* if the field is {@code null}
* @throws IllegalArgumentException
* if the field is {@code null} or {@code value} is not assignable
* if {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not made accessible or is {@code final}
*/
@ -684,7 +720,7 @@ public class FieldUtils {
*
* @param field
* to remove the final modifier
* @throws IllegalArgumentException
* @throws NullPointerException
* if the field is {@code null}
* @since 3.2
*/
@ -701,7 +737,7 @@ public class FieldUtils {
* whether to break scope restrictions using the
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @throws IllegalArgumentException
* @throws NullPointerException
* if the field is {@code null}
* @deprecated As of Java 12, we can no longer drop the {@code final} modifier, thus
* rendering this method obsolete. The JDK discussion about this change can be found
@ -748,9 +784,11 @@ public class FieldUtils {
* the field name to obtain
* @param value
* to set
* @throws NullPointerException
* if {@code target} is @{code null}
* @throws IllegalArgumentException
* if {@code target} is {@code null}, {@code fieldName} is blank or empty or could not be found, or
* {@code value} is not assignable
* if {@code fieldName} is {@code null}, blank, empty, or could not be found,
* or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not accessible
*/
@ -771,9 +809,11 @@ public class FieldUtils {
* whether to break scope restrictions using the
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @throws NullPointerException
* if {@code target} is @{code null}
* @throws IllegalArgumentException
* if {@code target} is {@code null}, {@code fieldName} is blank or empty or could not be found, or
* {@code value} is not assignable
* if {@code fieldName} is {@code null}, blank, empty, or could not be found,
* or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not made accessible
*/
@ -796,9 +836,11 @@ public class FieldUtils {
* the field name to obtain
* @param value
* to set
* @throws NullPointerException
* if {@code target} is @{code null}
* @throws IllegalArgumentException
* if {@code target} is {@code null}, {@code fieldName} is blank or empty or could not be found, or
* {@code value} is not assignable
* if {@code fieldName} is {@code null}, blank or empty, or could not be found,
* or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not made accessible
*/
@ -820,8 +862,8 @@ public class FieldUtils {
* {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} method. {@code false} will only
* match {@code public} fields.
* @throws IllegalArgumentException
* if {@code target} is {@code null}, {@code fieldName} is blank or empty or could not be found, or
* {@code value} is not assignable
* if {@code fieldName} is {@code null}, blank or empty, or could not be found,
* or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not made accessible
*/

View File

@ -142,6 +142,7 @@ public class MethodUtils {
* @throws NoSuchMethodException if there is no such accessible method
* @throws InvocationTargetException wraps an exception thrown by the method invoked
* @throws IllegalAccessException if the requested method is not accessible via reflection
* @throws NullPointerException if the object or method name are {@code null}
*/
public static Object invokeMethod(final Object object, final String methodName,
Object... args) throws NoSuchMethodException,
@ -170,7 +171,7 @@ public class MethodUtils {
* @throws NoSuchMethodException if there is no such accessible method
* @throws InvocationTargetException wraps an exception thrown by the method invoked
* @throws IllegalAccessException if the requested method is not accessible via reflection
*
* @throws NullPointerException if the object or method name are {@code null}
* @since 3.5
*/
public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName,
@ -197,6 +198,7 @@ public class MethodUtils {
* @throws NoSuchMethodException if there is no such accessible method
* @throws InvocationTargetException wraps an exception thrown by the method invoked
* @throws IllegalAccessException if the requested method is not accessible via reflection
* @throws NullPointerException if the object or method name are {@code null}
* @since 3.5
*/
public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName, Object[] args, Class<?>[] parameterTypes)
@ -294,6 +296,7 @@ public class MethodUtils {
* method invoked
* @throws IllegalAccessException if the requested method is not accessible
* via reflection
* @throws NullPointerException if the object or method name are {@code null}
*/
public static Object invokeExactMethod(final Object object, final String methodName,
Object... args) throws NoSuchMethodException,
@ -320,6 +323,7 @@ public class MethodUtils {
* method invoked
* @throws IllegalAccessException if the requested method is not accessible
* via reflection
* @throws NullPointerException if the object or method name are {@code null}
*/
public static Object invokeExactMethod(final Object object, final String methodName, Object[] args, Class<?>[] parameterTypes)
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
@ -711,6 +715,7 @@ public class MethodUtils {
* @param methodName The method that we wish to call
* @param parameterTypes Argument class types
* @throws IllegalStateException if there is no unique result
* @throws NullPointerException if the class is {@code null}
* @return The method
*
* @since 3.5
@ -861,7 +866,7 @@ public class MethodUtils {
* @param annotationCls
* the {@link Annotation} that must be present on a method to be matched
* @return a list of Methods (possibly empty).
* @throws IllegalArgumentException
* @throws NullPointerException
* if the class or annotation are {@code null}
* @since 3.4
*/

View File

@ -415,6 +415,7 @@ public class TypeUtils {
* @return a {@link Map} of the type assignments that could be determined
* for the type variables in each type in the inheritance hierarchy from
* {@code type} to {@code toClass} inclusive.
* @throws NullPointerException if either {@code cls} or {@code superParameterizedType} is {@code null}
*/
public static Map<TypeVariable<?>, Type> determineTypeArguments(final Class<?> cls,
final ParameterizedType superParameterizedType) {
@ -670,6 +671,7 @@ public class TypeUtils {
*
* @param typeVariable the subject type variable, not {@code null}
* @return a non-empty array containing the bounds of the type variable.
* @throws NullPointerException if {@code typeVariable} is {@code null}
*/
public static Type[] getImplicitBounds(final TypeVariable<?> typeVariable) {
Objects.requireNonNull(typeVariable, "typeVariable");
@ -686,6 +688,7 @@ public class TypeUtils {
* @param wildcardType the subject wildcard type, not {@code null}
* @return a non-empty array containing the lower bounds of the wildcard
* type.
* @throws NullPointerException if {@code wildcardType} is {@code null}
*/
public static Type[] getImplicitLowerBounds(final WildcardType wildcardType) {
Objects.requireNonNull(wildcardType, "wildcardType");
@ -703,6 +706,7 @@ public class TypeUtils {
* @param wildcardType the subject wildcard type, not {@code null}
* @return a non-empty array containing the upper bounds of the wildcard
* type.
* @throws NullPointerException if {@code wildcardType} is {@code null}
*/
public static Type[] getImplicitUpperBounds(final WildcardType wildcardType) {
Objects.requireNonNull(wildcardType, "wildcardType");
@ -1509,6 +1513,7 @@ public class TypeUtils {
* {@link WildcardType} or {@link TypeVariable}, not {@code null}.
* @return an array containing the values from {@code bounds} minus the
* redundant types.
* @throws NullPointerException if {@code bounds} is {@code null}
*/
public static Type[] normalizeUpperBounds(final Type[] bounds) {
Objects.requireNonNull(bounds, "bounds");
@ -1680,6 +1685,7 @@ public class TypeUtils {
*
* @param typeVariable the type variable to create a String representation for, not {@code null}
* @return String
* @throws NullPointerException if {@code typeVariable} is {@code null}
* @since 3.2
*/
public static String toLongString(final TypeVariable<?> typeVariable) {
@ -1713,6 +1719,7 @@ public class TypeUtils {
*
* @param type the type to create a String representation for, not {@code null}
* @return String
* @throws NullPointerException if {@code type} is {@code null}
* @since 3.2
*/
public static String toString(final Type type) {
@ -1747,6 +1754,7 @@ public class TypeUtils {
* type variables, not {@code null}.
* @return whether or not the types can be assigned to their respective type
* variables.
* @throws NullPointerException if {@code typeVariableMap} is {@code null}
*/
public static boolean typesSatisfyVariables(final Map<TypeVariable<?>, Type> typeVariableMap) {
Objects.requireNonNull(typeVariableMap, "typeVariableMap");

View File

@ -180,6 +180,11 @@ public class RandomStringUtilsTest extends AbstractLangTest {
() -> RandomStringUtils.random(-1, 'a', 'z', false, false, DUMMY, new Random()));
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(8, 32, 48, false, true));
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.random(8, 32, 65, true, false));
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.randomAlphabetic(-1));
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.randomAscii(-1));
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.randomGraph(-1));
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.randomNumeric(-1));
assertThrows(IllegalArgumentException.class, () -> RandomStringUtils.randomPrint(-1));
}
/**

View File

@ -317,6 +317,16 @@ public class DiffBuilderTest extends AbstractLangTest {
assertThrows(NullPointerException.class, () -> new DiffBuilder<>(this, null, ToStringStyle.DEFAULT_STYLE));
}
@Test
public void testNullLhs_4args() {
assertThrows(NullPointerException.class, () -> new DiffBuilder<>(null, this, ToStringStyle.DEFAULT_STYLE, true));
}
@Test
public void testNullRhs_4args() {
assertThrows(NullPointerException.class, () -> new DiffBuilder<>(this, null, ToStringStyle.DEFAULT_STYLE, true));
}
@Test
public void testObject() {
final TypeTestClass class1 = new TypeTestClass();

View File

@ -107,22 +107,22 @@ public class FieldUtilsTest extends AbstractLangTest {
}
@Test
public void testGetFieldIllegalArgumentException1() {
public void testGetFieldNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.getField(null, "none"));
}
@Test
public void testGetFieldIllegalArgumentException2() {
public void testGetFieldIllegalArgumentException1() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getField(PublicChild.class, null));
}
@Test
public void testGetFieldIllegalArgumentException3() {
public void testGetFieldIllegalArgumentException2() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getField(PublicChild.class, ""));
}
@Test
public void testGetFieldIllegalArgumentException4() {
public void testGetFieldIllegalArgumentException3() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getField(PublicChild.class, " "));
}
@ -146,22 +146,22 @@ public class FieldUtilsTest extends AbstractLangTest {
}
@Test
public void testGetFieldForceAccessIllegalArgumentException1() {
public void testGetFieldForceAccessNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.getField(null, "none", true));
}
@Test
public void testGetFieldForceAccessIllegalArgumentException2() {
public void testGetFieldForceAccessIllegalArgumentException1() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getField(PublicChild.class, null, true));
}
@Test
public void testGetFieldForceAccessIllegalArgumentException3() {
public void testGetFieldForceAccessIllegalArgumentException2() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getField(PublicChild.class, "", true));
}
@Test
public void testGetFieldForceAccessIllegalArgumentException4() {
public void testGetFieldForceAccessIllegalArgumentException3() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getField(PublicChild.class, " ", true));
}
@ -183,6 +183,11 @@ public class FieldUtilsTest extends AbstractLangTest {
assertEquals(expected, allFields.length, Arrays.toString(allFields));
}
@Test
public void testGetAllFieldsNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.getAllFields(null));
}
private Field[] sort(final Field[] fields) {
// Field does not implement Comparable, so we use a KISS solution here.
return ArraySorter.sort(fields, ObjectToStringComparator.INSTANCE);
@ -209,6 +214,11 @@ public class FieldUtilsTest extends AbstractLangTest {
}
@Test
public void testGetAllFieldListsNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.getAllFieldsList(null));
}
@Test
public void testGetFieldsWithAnnotation() throws NoSuchFieldException {
assertArrayEquals(new Field[0], FieldUtils.getFieldsWithAnnotation(Object.class, Annotated.class));
@ -220,17 +230,17 @@ public class FieldUtilsTest extends AbstractLangTest {
}
@Test
public void testGetFieldsWithAnnotationIllegalArgumentException1() {
public void testGetFieldsWithAnnotationNullPointerException1() {
assertThrows(NullPointerException.class, () -> FieldUtils.getFieldsWithAnnotation(FieldUtilsTest.class, null));
}
@Test
public void testGetFieldsWithAnnotationIllegalArgumentException2() {
public void testGetFieldsWithAnnotationNullPointerException2() {
assertThrows(NullPointerException.class, () -> FieldUtils.getFieldsWithAnnotation(null, Annotated.class));
}
@Test
public void testGetFieldsWithAnnotationIllegalArgumentException3() {
public void testGetFieldsWithAnnotationNullPointerException3() {
assertThrows(NullPointerException.class, () -> FieldUtils.getFieldsWithAnnotation(null, null));
}
@ -248,17 +258,17 @@ public class FieldUtilsTest extends AbstractLangTest {
}
@Test
public void testGetFieldsListWithAnnotationIllegalArgumentException1() {
public void testGetFieldsListWithAnnotationNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.getFieldsListWithAnnotation(FieldUtilsTest.class, null));
}
@Test
public void testGetFieldsListWithAnnotationIllegalArgumentException2() {
public void testGetFieldsListWithAnnotationNullPointerException2() {
assertThrows(NullPointerException.class, () -> FieldUtils.getFieldsListWithAnnotation(null, Annotated.class));
}
@Test
public void testGetFieldsListWithAnnotationIllegalArgumentException3() {
public void testGetFieldsListWithAnnotationNullPointerException3() {
assertThrows(NullPointerException.class, () -> FieldUtils.getFieldsListWithAnnotation(null, null));
}
@ -282,22 +292,22 @@ public class FieldUtilsTest extends AbstractLangTest {
}
@Test
public void testGetDeclaredFieldAccessIllegalArgumentException1() {
public void testGetDeclaredFieldAccessNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.getDeclaredField(null, "none"));
}
@Test
public void testGetDeclaredFieldAccessIllegalArgumentException2() {
public void testGetDeclaredFieldAccessIllegalArgumentException1() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getDeclaredField(PublicChild.class, null));
}
@Test
public void testGetDeclaredFieldAccessIllegalArgumentException3() {
public void testGetDeclaredFieldAccessIllegalArgumentException2() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getDeclaredField(PublicChild.class, ""));
}
@Test
public void testGetDeclaredFieldAccessIllegalArgumentException4() {
public void testGetDeclaredFieldAccessIllegalArgumentException3() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getDeclaredField(PublicChild.class, " "));
}
@ -321,22 +331,22 @@ public class FieldUtilsTest extends AbstractLangTest {
}
@Test
public void testGetDeclaredFieldForceAccessIllegalArgumentException1() {
public void testGetDeclaredFieldForceAccessNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.getDeclaredField(null, "none", true));
}
@Test
public void testGetDeclaredFieldForceAccessIllegalArgumentException2() {
public void testGetDeclaredFieldForceAccessIllegalArgumentException1() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getDeclaredField(PublicChild.class, null, true));
}
@Test
public void testGetDeclaredFieldForceAccessIllegalArgumentException3() {
public void testGetDeclaredFieldForceAccessIllegalArgumentException2() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getDeclaredField(PublicChild.class, "", true));
}
@Test
public void testGetDeclaredFieldForceAccessIllegalArgumentException4() {
public void testGetDeclaredFieldForceAccessIllegalArgumentException3() {
assertThrows(IllegalArgumentException.class, () -> FieldUtils.getDeclaredField(PublicChild.class, " ", true));
}
@ -346,12 +356,12 @@ public class FieldUtilsTest extends AbstractLangTest {
}
@Test
public void testReadStaticFieldIllegalArgumentException1() {
public void testReadStaticFieldNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.readStaticField(null));
}
@Test
public void testReadStaticFieldIllegalArgumentException2() throws Exception {
public void testReadStaticFieldIllegalArgumentException() throws Exception {
assertEquals(Foo.VALUE, FieldUtils.readStaticField(FieldUtils.getField(Foo.class, "VALUE")));
final Field nonStaticField = FieldUtils.getField(PublicChild.class, "s");
assumeTrue(nonStaticField != null);
@ -365,15 +375,15 @@ public class FieldUtilsTest extends AbstractLangTest {
}
@Test
public void testReadStaticFieldForceAccessIllegalArgumentException1() {
public void testReadStaticFieldForceAccessNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.readStaticField(null, true));
}
@Test
public void testReadStaticFieldForceAccessIllegalArgumentException2() {
public void testReadStaticFieldForceAccessIllegalArgumentException() {
final Field nonStaticField = FieldUtils.getField(PublicChild.class, "s", true);
assumeTrue(nonStaticField != null);
assertThrows(IllegalArgumentException.class, () -> FieldUtils.readStaticField(nonStaticField));
assertThrows(IllegalArgumentException.class, () -> FieldUtils.readStaticField(nonStaticField, true));
}
@Test
@ -386,7 +396,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readStaticField(null, "none"),
"null class should cause an IllegalArgumentException");
"null class should cause an NullPointerException");
assertThrows(
IllegalArgumentException.class,
@ -406,7 +416,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readStaticField(Foo.class, "does_not_exist"),
"a field that doesn't exist should cause an IllegalArgumentException");
"a field that doesn't exist should cause an NullPointerException");
assertThrows(
IllegalArgumentException.class,
@ -424,7 +434,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readStaticField(null, "none", true),
"null class should cause an IllegalArgumentException");
"null class should cause an NullPointerException");
assertThrows(
IllegalArgumentException.class,
@ -444,7 +454,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readStaticField(Foo.class, "does_not_exist", true),
"a field that doesn't exist should cause an IllegalArgumentException");
"a field that doesn't exist should cause an NullPointerException");
assertThrows(
IllegalArgumentException.class,
@ -455,6 +465,9 @@ public class FieldUtilsTest extends AbstractLangTest {
@Test
public void testReadDeclaredNamedStaticField() throws Exception {
assertEquals(Foo.VALUE, FieldUtils.readDeclaredStaticField(Foo.class, "VALUE"));
assertThrows(
NullPointerException.class, () ->
FieldUtils.readDeclaredField(null, "VALUE"));
assertThrows(
NullPointerException.class, () -> FieldUtils.readDeclaredStaticField(PublicChild.class, "VALUE"));
assertThrows(
@ -463,6 +476,15 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readDeclaredStaticField(PrivatelyShadowedChild.class, "VALUE"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.readDeclaredStaticField(PublicChild.class, null));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.readDeclaredStaticField(PublicChild.class, ""));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.readDeclaredStaticField(PublicChild.class, " "));
}
@Test
@ -475,6 +497,15 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readDeclaredStaticField(PrivatelyShadowedChild.class, "VALUE", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.readDeclaredStaticField(PrivatelyShadowedChild.class, null, true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.readDeclaredStaticField(PrivatelyShadowedChild.class, "", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.readDeclaredStaticField(PrivatelyShadowedChild.class, " ", true));
}
@Test
@ -499,7 +530,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readField(null, publicChild),
"a null field should cause an IllegalArgumentException");
"a null field should cause an NullPointerException");
}
@Test
@ -528,7 +559,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readField(null, publicChild, true),
"a null field should cause an IllegalArgumentException");
"a null field should cause an NullPointerException");
}
@Test
@ -555,7 +586,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readField((Object) null, "none"),
"a null target should cause an IllegalArgumentException");
"a null target should cause an NullPointerException");
assertThrows(IllegalArgumentException.class, () -> FieldUtils.readField(publicChild, "b"));
@ -602,7 +633,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readField((Object) null, "none", true),
"a null target should cause an IllegalArgumentException");
"a null target should cause an NullPointerException");
}
@Test
@ -625,7 +656,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readDeclaredField(null, "none"),
"a null target should cause an IllegalArgumentException");
"a null target should cause an NullPointerException");
assertThrows(IllegalArgumentException.class, () -> FieldUtils.readDeclaredField(publicChild, "s"));
assertEquals("ss", FieldUtils.readDeclaredField(publiclyShadowedChild, "s"));
@ -661,7 +692,7 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.readDeclaredField(null, "none", true),
"a null target should cause an IllegalArgumentException");
"a null target should cause an NullPointerException");
assertThrows(IllegalArgumentException.class, () -> FieldUtils.readDeclaredField(publicChild, "s", true));
assertEquals("ss", FieldUtils.readDeclaredField(publiclyShadowedChild, "s", true));
@ -703,6 +734,10 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
IllegalAccessException.class,
() -> FieldUtils.writeStaticField(StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE"), "new"));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeStaticField(null, "new"));
}
@Test
@ -731,6 +766,10 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
IllegalAccessException.class,
() -> FieldUtils.writeStaticField(StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE"), "new", true));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeStaticField(null, "new", true));
}
@Test
@ -758,6 +797,19 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PRIVATE", "new"));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeStaticField(null, "IMMUTABLE_PRIVATE", "new"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeStaticField(StaticContainerChild.class, null, "new"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeStaticField(StaticContainerChild.class, "", "new"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeStaticField(StaticContainerChild.class, " ", "new"));
}
@Test
@ -782,6 +834,19 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
IllegalAccessException.class,
() -> FieldUtils.writeStaticField(StaticContainerChild.class, "IMMUTABLE_PRIVATE", "new", true));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeStaticField(null, "IMMUTABLE_PRIVATE", "new", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeStaticField(StaticContainerChild.class, null, "new", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeStaticField(StaticContainerChild.class, "", "new", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeStaticField(StaticContainerChild.class, " ", "new", true));
}
@Test
@ -809,6 +874,19 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PRIVATE", "new"));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeDeclaredStaticField(null, "mutablePublic", "new"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredStaticField(StaticContainer.class, null, "new"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredStaticField(StaticContainer.class, "", "new"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredStaticField(StaticContainer.class, " ", "new"));
}
@Test
@ -833,6 +911,19 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
IllegalAccessException.class,
() -> FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PRIVATE", "new", true));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeDeclaredStaticField(null, "mutablePublic", "new", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredStaticField(StaticContainer.class, null, "new", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredStaticField(StaticContainer.class, "", "new", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredStaticField(StaticContainer.class, " ", "new", true));
}
@Test
@ -849,6 +940,10 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
IllegalAccessException.class,
() -> FieldUtils.writeField(parentClass.getDeclaredField("d"), publicChild, Double.valueOf(Double.MAX_VALUE)));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeField(null, publicChild, "S"));
}
@Test
@ -865,6 +960,10 @@ public class FieldUtilsTest extends AbstractLangTest {
field = parentClass.getDeclaredField("d");
FieldUtils.writeField(field, publicChild, Double.valueOf(Double.MAX_VALUE), true);
assertEquals(Double.valueOf(Double.MAX_VALUE), field.get(publicChild));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeField(null, publicChild, "S", true));
}
@Test
@ -896,6 +995,19 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeField(privatelyShadowedChild, "d", Double.valueOf(1.0)));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeField((Object) null, "s", "s"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeField(publicChild, null, "s"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeField(publicChild, "", "s"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeField(publicChild, " ", "s"));
}
@Test
@ -926,6 +1038,19 @@ public class FieldUtilsTest extends AbstractLangTest {
assertEquals(Integer.valueOf(0), FieldUtils.readField(privatelyShadowedChild, "i", true));
FieldUtils.writeField(privatelyShadowedChild, "d", Double.valueOf(0.0), true);
assertEquals(Double.valueOf(0.0), FieldUtils.readField(privatelyShadowedChild, "d", true));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeField((Object) null, "s", "s", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeField(publicChild, null, "s", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeField(publicChild, "", "s", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeField(publicChild, " ", "s", true));
}
@Test
@ -960,6 +1085,19 @@ public class FieldUtilsTest extends AbstractLangTest {
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredField(privatelyShadowedChild, "d", Double.valueOf(1.0)));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeDeclaredField(null, "s", "S"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredField(publicChild, "null", "S"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredField(publicChild, "", "S"));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredField(publicChild, " ", "S"));
}
@Test
@ -992,6 +1130,19 @@ public class FieldUtilsTest extends AbstractLangTest {
assertEquals(Integer.valueOf(0), FieldUtils.readDeclaredField(privatelyShadowedChild, "i", true));
FieldUtils.writeDeclaredField(privatelyShadowedChild, "d", Double.valueOf(0.0), true);
assertEquals(Double.valueOf(0.0), FieldUtils.readDeclaredField(privatelyShadowedChild, "d", true));
assertThrows(
NullPointerException.class,
() -> FieldUtils.writeDeclaredField(null, "s", "S", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredField(publicChild, "null", "S", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredField(publicChild, "", "S", true));
assertThrows(
IllegalArgumentException.class,
() -> FieldUtils.writeDeclaredField(publicChild, " ", "S", true));
}
@Test
@ -1011,6 +1162,11 @@ public class FieldUtilsTest extends AbstractLangTest {
}
}
@Test
public void testRemoveFinalModifierNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.removeFinalModifier(null));
}
@Test
public void testRemoveFinalModifierWithAccess() throws Exception {
final Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2");
@ -1023,6 +1179,11 @@ public class FieldUtilsTest extends AbstractLangTest {
}
}
@Test
public void testRemoveFinalModifierWithAccessNullPointerException() {
assertThrows(NullPointerException.class, () -> FieldUtils.removeFinalModifier(null, true));
}
@Test
public void testRemoveFinalModifierWithoutAccess() throws Exception {
final Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2");

View File

@ -447,6 +447,9 @@ public class MethodUtilsTest extends AbstractLangTest {
MethodUtils.invokeMethod(testBean, "varOverloadEcho", "x", "y"));
TestBean.verify(new ImmutablePair<>("Number...", new Number[]{17, 23, 42}),
MethodUtils.invokeMethod(testBean, "varOverloadEcho", 17, 23, 42));
assertThrows(NullPointerException.class, () -> MethodUtils.invokeMethod(null, "foo", 1, 2));
assertThrows(NullPointerException.class, () -> MethodUtils.invokeMethod(testBean, null, 1, 2));
}
@Test
@ -492,6 +495,22 @@ public class MethodUtilsTest extends AbstractLangTest {
NoSuchMethodException.class,
() -> MethodUtils.invokeExactMethod(testBean, "foo", NumberUtils.LONG_ONE));
assertThrows(NoSuchMethodException.class, () -> MethodUtils.invokeExactMethod(testBean, "foo", Boolean.TRUE));
assertThrows(
NullPointerException.class,
() -> MethodUtils.invokeExactMethod(null, "foo", NumberUtils.BYTE_ONE));
assertThrows(
NullPointerException.class,
() -> MethodUtils.invokeExactMethod(testBean, null, NumberUtils.BYTE_ONE));
assertThrows(
NullPointerException.class,
() -> MethodUtils.invokeExactMethod(null, "foo", new Object[]{NumberUtils.DOUBLE_ONE},
new Class[]{Double.TYPE}));
assertThrows(
NullPointerException.class,
() -> MethodUtils.invokeExactMethod(testBean, null, new Object[]{NumberUtils.DOUBLE_ONE},
new Class[]{Double.TYPE}));
}
@Test
@ -893,17 +912,17 @@ public class MethodUtilsTest extends AbstractLangTest {
}
@Test
public void testGetMethodsListWithAnnotationIllegalArgumentException1() {
public void testGetMethodsListWithAnnotationNullPointerException1() {
assertThrows(NullPointerException.class, () -> MethodUtils.getMethodsListWithAnnotation(FieldUtilsTest.class, null));
}
@Test
public void testGetMethodsListWithAnnotationIllegalArgumentException2() {
public void testGetMethodsListWithAnnotationNullPointerException2() {
assertThrows(NullPointerException.class, () -> MethodUtils.getMethodsListWithAnnotation(null, Annotated.class));
}
@Test
public void testGetMethodsListWithAnnotationIllegalArgumentException3() {
public void testGetMethodsListWithAnnotationNullPointerException3() {
assertThrows(NullPointerException.class, () -> MethodUtils.getMethodsListWithAnnotation(null, null));
}
@ -1007,6 +1026,11 @@ public class MethodUtilsTest extends AbstractLangTest {
assertEquals("privateStringStuff(double)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", 5.0d));
assertEquals("privateStringStuff(String)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", "Hi There"));
assertEquals("privateStringStuff(Object)", MethodUtils.invokeMethod(testBean, true, "privateStringStuff", new Date()));
assertThrows(NullPointerException.class,
() -> MethodUtils.invokeMethod(null, true, "privateStringStuff", "Hi There"));
assertThrows(NullPointerException.class,
() -> MethodUtils.invokeMethod(testBean, true, null, "Hi There"));
}
@Test
@ -1056,6 +1080,9 @@ public class MethodUtilsTest extends AbstractLangTest {
assertEquals(MethodUtils.getMatchingMethod(GetMatchingMethodImpl.class, "testMethod5", RuntimeException.class),
GetMatchingMethodImpl.class.getMethod("testMethod5", Exception.class));
assertThrows(NullPointerException.class,
() -> MethodUtils.getMatchingMethod(null, "testMethod5", RuntimeException.class));
}
private static final class GetMatchingMethodClass {

View File

@ -282,6 +282,11 @@ public class TypeUtilsTest<B> extends AbstractLangTest {
assertTrue(typeVarAssigns.containsKey(treeSetTypeVar));
assertEquals(iterableType.getActualTypeArguments()[0], typeVarAssigns
.get(treeSetTypeVar));
assertThrows(NullPointerException.class,
() -> TypeUtils.determineTypeArguments(TreeSet.class, null));
assertThrows(NullPointerException.class,
() -> TypeUtils.determineTypeArguments(null, iterableType));
}
@Test
@ -984,6 +989,8 @@ public class TypeUtilsTest<B> extends AbstractLangTest {
@Test
public void testToLongString() {
assertEquals(getClass().getName() + ":B", TypeUtils.toLongString(getClass().getTypeParameters()[0]));
assertThrows(NullPointerException.class, () -> TypeUtils.toLongString(null));
}
@Test
@ -1007,6 +1014,8 @@ public class TypeUtilsTest<B> extends AbstractLangTest {
typeVarAssigns.clear();
typeVarAssigns.put(getClass().getMethod("stub3").getTypeParameters()[0], Integer.class);
assertTrue(TypeUtils.typesSatisfyVariables(typeVarAssigns));
assertThrows(NullPointerException.class, () -> TypeUtils.typesSatisfyVariables(null));
}
@Test
@ -1017,6 +1026,11 @@ public class TypeUtilsTest<B> extends AbstractLangTest {
assertArrayEquals(new Type[] { null }, TypeUtils.getImplicitLowerBounds(unbounded));
assertEquals("?", TypeUtils.toString(unbounded));
assertEquals("?", unbounded.toString());
assertThrows(NullPointerException.class,
() -> TypeUtils.getImplicitLowerBounds(null));
assertThrows(NullPointerException.class,
() -> TypeUtils.getImplicitUpperBounds(null));
}
@Test