Skip to content

Commit

Permalink
Use final
Browse files Browse the repository at this point in the history
- Use direct references
- Add missing @deprecated
- Merge test expressions with the same outcome
  • Loading branch information
garydgregory committed Dec 25, 2024
1 parent 00e08c9 commit e4894f8
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,8 @@ public static <T> Constructor<T> getAccessibleConstructor(
public static <T> Constructor<T> getAccessibleConstructor(final Constructor<T> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ConversionException extends RuntimeException {
*
* @deprecated Use {@link Throwable#getCause()}}.
*/
@Deprecated
protected Throwable cause;

/**
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/apache/commons/beanutils/MethodUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ private static Map<String, Object> 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<Class<?>, BeanIntrospectionData> descriptorsCache;
private final WeakFastHashMap<Class<?>, BeanIntrospectionData> descriptorsCache;

private WeakFastHashMap<Class<?>, FastHashMap> mappedDescriptorsCache;
private final WeakFastHashMap<Class<?>, FastHashMap> mappedDescriptorsCache;


/** Log instance */
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/beanutils/WrapDynaClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ private static Map<Object, Object> 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<Class<?>> beanClassRef;
private final Reference<Class<?>> beanClassRef;

/** Stores the associated {@code PropertyUtilsBean} instance. */
private final PropertyUtilsBean propertyUtilsBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit e4894f8

Please sign in to comment.