diff --git a/src/main/java/org/apache/commons/beanutils/ConstructorUtils.java b/src/main/java/org/apache/commons/beanutils/ConstructorUtils.java index 04849911f..663fdf571 100644 --- a/src/main/java/org/apache/commons/beanutils/ConstructorUtils.java +++ b/src/main/java/org/apache/commons/beanutils/ConstructorUtils.java @@ -90,12 +90,8 @@ public static Constructor getAccessibleConstructor( public static Constructor getAccessibleConstructor(final Constructor ctor) { // Make sure we have a method to check - if (ctor == null) { - return null; - } - // If the requested method is not public we cannot call it - if (!Modifier.isPublic(ctor.getModifiers())) { + if (ctor == null || !Modifier.isPublic(ctor.getModifiers())) { return null; } diff --git a/src/main/java/org/apache/commons/beanutils/ConversionException.java b/src/main/java/org/apache/commons/beanutils/ConversionException.java index 5cc33969f..a24717041 100644 --- a/src/main/java/org/apache/commons/beanutils/ConversionException.java +++ b/src/main/java/org/apache/commons/beanutils/ConversionException.java @@ -32,6 +32,7 @@ public class ConversionException extends RuntimeException { * * @deprecated Use {@link Throwable#getCause()}}. */ + @Deprecated protected Throwable cause; /** diff --git a/src/main/java/org/apache/commons/beanutils/MethodUtils.java b/src/main/java/org/apache/commons/beanutils/MethodUtils.java index fa9ff556c..d0fc5b8c1 100644 --- a/src/main/java/org/apache/commons/beanutils/MethodUtils.java +++ b/src/main/java/org/apache/commons/beanutils/MethodUtils.java @@ -206,12 +206,8 @@ public static synchronized int clearCache() { public static Method getAccessibleMethod(Class clazz, Method method) { // Make sure we have a method to check - if (method == null) { - return null; - } - // If the requested method is not public we cannot call it - if (!Modifier.isPublic(method.getModifiers())) { + if (method == null || !Modifier.isPublic(method.getModifiers())) { return null; } diff --git a/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java b/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java index 4b398eb38..434230d1f 100644 --- a/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java @@ -136,9 +136,9 @@ private static Map toPropertyMap(final Object obj) { * The cache of PropertyDescriptor arrays for beans we have already * introspected, keyed by the java.lang.Class of this object. */ - private WeakFastHashMap, BeanIntrospectionData> descriptorsCache; + private final WeakFastHashMap, BeanIntrospectionData> descriptorsCache; - private WeakFastHashMap, FastHashMap> mappedDescriptorsCache; + private final WeakFastHashMap, FastHashMap> mappedDescriptorsCache; /** Log instance */ diff --git a/src/main/java/org/apache/commons/beanutils/WrapDynaClass.java b/src/main/java/org/apache/commons/beanutils/WrapDynaClass.java index dec0a632f..8a01acf55 100644 --- a/src/main/java/org/apache/commons/beanutils/WrapDynaClass.java +++ b/src/main/java/org/apache/commons/beanutils/WrapDynaClass.java @@ -269,12 +269,12 @@ private static Map getDynaClassesMap() { /** * Name of the JavaBean class represented by this WrapDynaClass. */ - private String beanClassName; + private final String beanClassName; /** * Reference to the JavaBean class represented by this WrapDynaClass. */ - private Reference> beanClassRef; + private final Reference> beanClassRef; /** Stores the associated {@code PropertyUtilsBean} instance. */ private final PropertyUtilsBean propertyUtilsBean; diff --git a/src/test/java/org/apache/commons/beanutils/converters/BooleanArrayConverterTestCase.java b/src/test/java/org/apache/commons/beanutils/converters/BooleanArrayConverterTestCase.java index 2af8999d5..a9b45f1e8 100644 --- a/src/test/java/org/apache/commons/beanutils/converters/BooleanArrayConverterTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/converters/BooleanArrayConverterTestCase.java @@ -57,7 +57,7 @@ public void testAdditionalStrings() { final BooleanConverter bc = new BooleanConverter( trueStrings, falseStrings, BooleanConverter.NO_DEFAULT); final BooleanArrayConverter converter = new BooleanArrayConverter( - bc, BooleanArrayConverter.NO_DEFAULT); + bc, AbstractArrayConverter.NO_DEFAULT); final boolean[] results = (boolean[]) converter.convert(null, "NOPE, sure, sure"); assertNotNull(results); @@ -162,7 +162,7 @@ public void testRegistration() { trueStrings, falseStrings, BooleanConverter.NO_DEFAULT); final BooleanArrayConverter converter = new BooleanArrayConverter( - bc, BooleanArrayConverter.NO_DEFAULT); + bc, AbstractArrayConverter.NO_DEFAULT); ConvertUtils.register(converter, BooleanArrayConverter.MODEL); final boolean[] sample = {}; diff --git a/src/test/java/org/apache/commons/beanutils/converters/SqlTimeConverterTestCase.java b/src/test/java/org/apache/commons/beanutils/converters/SqlTimeConverterTestCase.java index d5200f43f..d9c1e74e3 100644 --- a/src/test/java/org/apache/commons/beanutils/converters/SqlTimeConverterTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/converters/SqlTimeConverterTestCase.java @@ -63,7 +63,7 @@ protected Class getExpectedType() { private boolean isUSTimeFormatWithNarrowNoBreakSpace() { // Fix tests on Java 20 onwards. See https://bugs.openjdk.org/browse/JDK-8324308 for background. - DateFormat usDateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US); + final DateFormat usDateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US); return ((SimpleDateFormat) usDateFormat).toPattern().contains("\u202F"); } diff --git a/src/test/java/org/apache/commons/beanutils/converters/SqlTimestampConverterTestCase.java b/src/test/java/org/apache/commons/beanutils/converters/SqlTimestampConverterTestCase.java index b84e2237a..b03ed75b6 100644 --- a/src/test/java/org/apache/commons/beanutils/converters/SqlTimestampConverterTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/converters/SqlTimestampConverterTestCase.java @@ -69,7 +69,7 @@ private boolean isUSFormatWithComma() { private boolean isUSTimeFormatWithNarrowNoBreakSpace() { // Fix tests on Java 20 onwards. See https://bugs.openjdk.org/browse/JDK-8324308 for background. - DateFormat usDateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US); + final DateFormat usDateFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US); return ((SimpleDateFormat) usDateFormat).toPattern().contains("\u202F"); } diff --git a/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTestCase.java b/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTestCase.java index da547afab..064085f3c 100644 --- a/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTestCase.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.WeakHashMap; +import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.ContextClassLoaderLocal; import org.apache.commons.beanutils.ConversionException; import org.apache.commons.beanutils.ConvertUtils; @@ -361,7 +362,7 @@ public String toString() { assertEquals("Signal not set by test thread", 2, signal.getSignal()); assertTrue( "Different LocaleBeanUtilsBean instances per context classloader", - LocaleBeanUtilsBean.getInstance() != signal.getBean()); + BeanUtilsBean.getInstance() != signal.getBean()); assertTrue( "Different LocaleConvertUtilsBean instances per context classloader", LocaleConvertUtilsBean.getInstance() != signal.getConvertUtils());