This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch 1.X in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
commit 74227b5c1ee8c711ca87257923a66a15ded8c0f2 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Jan 21 14:10:20 2025 -0500 Fix ParenPad --- .../apache/commons/beanutils/BeanComparator.java | 4 +- .../java/org/apache/commons/beanutils/BeanMap.java | 451 +++++++++------------ .../apache/commons/beanutils/BeanPredicate.java | 2 +- .../org/apache/commons/beanutils/LazyDynaList.java | 8 +- .../org/apache/commons/beanutils/MethodUtils.java | 14 +- .../commons/beanutils/PropertyUtilsBean.java | 35 +- .../apache/commons/beanutils/RowSetDynaClass.java | 2 +- .../beanutils/locale/LocaleConvertUtilsBean.java | 4 +- .../locale/converters/DateLocaleConverter.java | 2 +- .../commons/beanutils/BeanPredicateTestCase.java | 12 +- .../commons/beanutils/BeanificationTestCase.java | 14 +- .../beanutils/DynaPropertyUtilsTestCase.java | 18 +- .../commons/beanutils/MethodUtilsTestCase.java | 5 +- .../commons/beanutils/PropertyUtilsTestCase.java | 66 +-- .../org/apache/commons/beanutils/TestBean.java | 6 +- .../locale/LocaleBeanificationTestCase.java | 13 +- 16 files changed, 262 insertions(+), 394 deletions(-) diff --git a/src/main/java/org/apache/commons/beanutils/BeanComparator.java b/src/main/java/org/apache/commons/beanutils/BeanComparator.java index ed14fbee..e45aa145 100644 --- a/src/main/java/org/apache/commons/beanutils/BeanComparator.java +++ b/src/main/java/org/apache/commons/beanutils/BeanComparator.java @@ -71,7 +71,7 @@ public class BeanComparator<T> implements Comparator<T>, Serializable { * </p> */ public BeanComparator() { - this( null ); + this(null); } /** @@ -232,7 +232,7 @@ public class BeanComparator<T> implements Comparator<T>, Serializable { * @param property String method name to call to compare * If the property passed in is null then the actual objects will be compared */ - public void setProperty( final String property ) { + public void setProperty(final String property) { this.property = property; } } diff --git a/src/main/java/org/apache/commons/beanutils/BeanMap.java b/src/main/java/org/apache/commons/beanutils/BeanMap.java index 182da078..1b83787c 100644 --- a/src/main/java/org/apache/commons/beanutils/BeanMap.java +++ b/src/main/java/org/apache/commons/beanutils/BeanMap.java @@ -37,11 +37,9 @@ import org.apache.commons.collections.Transformer; import org.apache.commons.collections.keyvalue.AbstractMapEntry; /** - * An implementation of Map for JavaBeans which uses introspection to - * get and put properties in the bean. + * An implementation of Map for JavaBeans which uses introspection to get and put properties in the bean. * <p> - * If an exception occurs during attempts to get or set a property then the - * property is considered non existent in the Map + * If an exception occurs during attempts to get or set a property then the property is considered non existent in the Map * */ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { @@ -55,48 +53,45 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { /** * Constructs a new <code>Entry</code>. * - * @param owner the BeanMap this entry belongs to - * @param key the key for this entry - * @param value the value for this entry + * @param owner the BeanMap this entry belongs to + * @param key the key for this entry + * @param value the value for this entry */ - protected Entry( final BeanMap owner, final Object key, final Object value ) { - super( key, value ); + protected Entry(final BeanMap owner, final Object key, final Object value) { + super(key, value); this.owner = owner; } /** * Sets the value. * - * @param value the new value for the entry + * @param value the new value for the entry * @return the old value for the entry */ @Override public Object setValue(final Object value) { final Object key = getKey(); - final Object oldValue = owner.get( key ); + final Object oldValue = owner.get(key); - owner.put( key, value ); - final Object newValue = owner.get( key ); - super.setValue( newValue ); + owner.put(key, value); + final Object newValue = owner.get(key); + super.setValue(newValue); return oldValue; } } /** - * An empty array. Used to invoke accessors via reflection. + * An empty array. Used to invoke accessors via reflection. */ public static final Object[] NULL_ARGUMENTS = {}; /** - * Maps primitive Class types to transformers. The transformer - * transform strings into the appropriate primitive wrapper. + * Maps primitive Class types to transformers. The transformer transform strings into the appropriate primitive wrapper. * * N.B. private & unmodifiable replacement for the (public & static) defaultTransformers instance. */ - private static final Map<Class<? extends Object>, Transformer> typeTransformers = - Collections.unmodifiableMap(createTypeTransformers()); + private static final Map<Class<? extends Object>, Transformer> typeTransformers = Collections.unmodifiableMap(createTypeTransformers()); /** - * This HashMap has been made unmodifiable to prevent issues when - * loaded in a shared ClassLoader enviroment. + * This HashMap has been made unmodifiable to prevent issues when loaded in a shared ClassLoader enviroment. * * @see "http://issues.apache.org/jira/browse/BEANUTILS-112" * @deprecated Use {@link BeanMap#getTypeTransformer(Class)} method @@ -104,50 +99,62 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { @Deprecated public static HashMap defaultTransformers = new HashMap() { private static final long serialVersionUID = 1L; + @Override public void clear() { throw new UnsupportedOperationException(); } + @Override public boolean containsKey(final Object key) { return typeTransformers.containsKey(key); } + @Override public boolean containsValue(final Object value) { return typeTransformers.containsValue(value); } + @Override public Set entrySet() { return typeTransformers.entrySet(); } + @Override public Object get(final Object key) { return typeTransformers.get(key); } + @Override public boolean isEmpty() { return false; } + @Override public Set keySet() { return typeTransformers.keySet(); } + @Override public Object put(final Object key, final Object value) { throw new UnsupportedOperationException(); } + @Override public void putAll(final Map m) { throw new UnsupportedOperationException(); } + @Override public Object remove(final Object key) { throw new UnsupportedOperationException(); } + @Override public int size() { return typeTransformers.size(); } + @Override public Collection values() { return typeTransformers.values(); @@ -155,40 +162,15 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { }; private static Map<Class<? extends Object>, Transformer> createTypeTransformers() { - final Map<Class<? extends Object>, Transformer> defaultTransformers = - new HashMap<>(); - defaultTransformers.put( - Boolean.TYPE, - input -> Boolean.valueOf( input.toString() ) - ); - defaultTransformers.put( - Character.TYPE, - input -> Character.valueOf(input.toString().charAt( 0 )) - ); - defaultTransformers.put( - Byte.TYPE, - input -> Byte.valueOf( input.toString() ) - ); - defaultTransformers.put( - Short.TYPE, - input -> Short.valueOf( input.toString() ) - ); - defaultTransformers.put( - Integer.TYPE, - input -> Integer.valueOf( input.toString() ) - ); - defaultTransformers.put( - Long.TYPE, - input -> Long.valueOf( input.toString() ) - ); - defaultTransformers.put( - Float.TYPE, - input -> Float.valueOf( input.toString() ) - ); - defaultTransformers.put( - Double.TYPE, - input -> Double.valueOf( input.toString() ) - ); + final Map<Class<? extends Object>, Transformer> defaultTransformers = new HashMap<>(); + defaultTransformers.put(Boolean.TYPE, input -> Boolean.valueOf(input.toString())); + defaultTransformers.put(Character.TYPE, input -> Character.valueOf(input.toString().charAt(0))); + defaultTransformers.put(Byte.TYPE, input -> Byte.valueOf(input.toString())); + defaultTransformers.put(Short.TYPE, input -> Short.valueOf(input.toString())); + defaultTransformers.put(Integer.TYPE, input -> Integer.valueOf(input.toString())); + defaultTransformers.put(Long.TYPE, input -> Long.valueOf(input.toString())); + defaultTransformers.put(Float.TYPE, input -> Float.valueOf(input.toString())); + defaultTransformers.put(Double.TYPE, input -> Double.valueOf(input.toString())); return defaultTransformers; } @@ -211,11 +193,9 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { // Map interface /** - * Constructs a new <code>BeanMap</code> that operates on the - * specified bean. If the given bean is <code>null</code>, then - * this map will be empty. + * Constructs a new <code>BeanMap</code> that operates on the specified bean. If the given bean is <code>null</code>, then this map will be empty. * - * @param bean the bean for this map to operate on + * @param bean the bean for this map to operate on */ public BeanMap(final Object bean) { this.bean = bean; @@ -223,12 +203,9 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { } /** - * This method reinitializes the bean map to have default values for the - * bean's properties. This is accomplished by constructing a new instance - * of the bean which the map uses as its underlying data source. This - * behavior for <code>clear()</code> differs from the Map contract in that - * the mappings are not actually removed from the map (the mappings for a - * BeanMap are fixed). + * This method reinitializes the bean map to have default values for the bean's properties. This is accomplished by constructing a new instance of the bean + * which the map uses as its underlying data source. This behavior for <code>clear()</code> differs from the Map contract in that the mappings are not + * actually removed from the map (the mappings for a BeanMap are fixed). */ @Override public void clear() { @@ -248,28 +225,16 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { * Clone this bean map using the following process: * * <ul> - * <li>If there is no underlying bean, return a cloned BeanMap without a - * bean. - * </li> - * <li>Since there is an underlying bean, try to instantiate a new bean of - * the same type using Class.newInstance(). - * </li> - * <li>If the instantiation fails, throw a CloneNotSupportedException - * </li> - * <li>Clone the bean map and set the newly instantiated bean as the - * underlying bean for the bean map. - * </li> - * <li>Copy each property that is both readable and writable from the - * existing object to a cloned bean map. - * </li> - * <li>If anything fails along the way, throw a - * CloneNotSupportedException. - * </li> + * <li>If there is no underlying bean, return a cloned BeanMap without a bean.</li> + * <li>Since there is an underlying bean, try to instantiate a new bean of the same type using Class.newInstance().</li> + * <li>If the instantiation fails, throw a CloneNotSupportedException</li> + * <li>Clone the bean map and set the newly instantiated bean as the underlying bean for the bean map.</li> + * <li>Copy each property that is both readable and writable from the existing object to a cloned bean map.</li> + * <li>If anything fails along the way, throw a CloneNotSupportedException.</li> * </ul> * * @return a cloned instance of this bean map - * @throws CloneNotSupportedException if the underlying bean - * cannot be cloned + * @throws CloneNotSupportedException if the underlying bean cannot be cloned */ @Override public Object clone() throws CloneNotSupportedException { @@ -315,17 +280,14 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { /** * Returns true if the bean defines a property with the given name. * <p> - * The given name must be a <code>String</code>; if not, this method - * returns false. This method will also return false if the bean - * does not define a property with that name. + * The given name must be a <code>String</code>; if not, this method returns false. This method will also return false if the bean does not define a + * property with that name. * <p> - * Write-only properties will not be matched as the test operates against - * property read methods. + * Write-only properties will not be matched as the test operates against property read methods. * - * @param name the name of the property to check - * @return false if the given name is null or is not a <code>String</code>; - * false if the bean does not define a property with that name; or - * true if the bean does define a property with that name + * @param name the name of the property to check + * @return false if the given name is null or is not a <code>String</code>; false if the bean does not define a property with that name; or true if the bean + * does define a property with that name */ @Override public boolean containsKey(final Object name) { @@ -334,12 +296,10 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { } /** - * Returns true if the bean defines a property whose current value is - * the given object. + * Returns true if the bean defines a property whose current value is the given object. * - * @param value the value to check - * @return false true if the bean has at least one property whose - * current value is that object, false otherwise + * @param value the value to check + * @return false true if the bean has at least one property whose current value is that object, false otherwise */ @Override public boolean containsValue(final Object value) { @@ -348,86 +308,70 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { } /** - * Converts the given value to the given type. First, reflection is - * is used to find a public constructor declared by the given class - * that takes one argument, which must be the precise type of the - * given value. If such a constructor is found, a new object is - * created by passing the given value to that constructor, and the - * newly constructed object is returned.<P> + * Converts the given value to the given type. First, reflection is is used to find a public constructor declared by the given class that takes one + * argument, which must be the precise type of the given value. If such a constructor is found, a new object is created by passing the given value to that + * constructor, and the newly constructed object is returned. + * <P> * - * If no such constructor exists, and the given type is a primitive - * type, then the given value is converted to a string using its - * {@link Object#toString() toString()} method, and that string is - * parsed into the correct primitive type using, for instance, - * {@link Integer#valueOf(String)} to convert the string into an - * <code>int</code>.<P> + * If no such constructor exists, and the given type is a primitive type, then the given value is converted to a string using its {@link Object#toString() + * toString()} method, and that string is parsed into the correct primitive type using, for instance, {@link Integer#valueOf(String)} to convert the string + * into an <code>int</code>. + * <P> * - * If no special constructor exists and the given type is not a - * primitive type, this method returns the original value. + * If no special constructor exists and the given type is not a primitive type, this method returns the original value. * - * @param newType the type to convert the value to - * @param value the value to convert + * @param newType the type to convert the value to + * @param value the value to convert * @return the converted value - * @throws NumberFormatException if newType is a primitive type, and - * the string representation of the given value cannot be converted - * to that type - * @throws InstantiationException if the constructor found with - * reflection raises it - * @throws InvocationTargetException if the constructor found with - * reflection raises it - * @throws IllegalAccessException never + * @throws NumberFormatException if newType is a primitive type, and the string representation of the given value cannot be converted to that type + * @throws InstantiationException if the constructor found with reflection raises it + * @throws InvocationTargetException if the constructor found with reflection raises it + * @throws IllegalAccessException never * @throws IllegalArgumentException never */ - protected Object convertType( final Class<?> newType, final Object value ) - throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + protected Object convertType(final Class<?> newType, final Object value) + throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // try call constructor final Class<?>[] types = { value.getClass() }; try { - final Constructor<?> constructor = newType.getConstructor( types ); + final Constructor<?> constructor = newType.getConstructor(types); final Object[] arguments = { value }; - return constructor.newInstance( arguments ); - } - catch ( final NoSuchMethodException e ) { + return constructor.newInstance(arguments); + } catch (final NoSuchMethodException e) { // try using the transformers - final Transformer transformer = getTypeTransformer( newType ); - if ( transformer != null ) { - return transformer.transform( value ); + final Transformer transformer = getTypeTransformer(newType); + if (transformer != null) { + return transformer.transform(value); } return value; } } /** - * Creates an array of parameters to pass to the given mutator method. - * If the given object is not the right type to pass to the method - * directly, it will be converted using {@link #convertType(Class,Object)}. + * Creates an array of parameters to pass to the given mutator method. If the given object is not the right type to pass to the method directly, it will be + * converted using {@link #convertType(Class,Object)}. * - * @param method the mutator method + * @param method the mutator method * @param value the value to pass to the mutator method - * @return an array containing one object that is either the given value - * or a transformed value - * @throws IllegalAccessException if {@link #convertType(Class,Object)} - * raises it - * @throws IllegalArgumentException if any other exception is raised - * by {@link #convertType(Class,Object)} - * @throws ClassCastException if an error occurs creating the method args - */ - protected Object[] createWriteMethodArguments( final Method method, Object value ) - throws IllegalAccessException, ClassCastException { + * @return an array containing one object that is either the given value or a transformed value + * @throws IllegalAccessException if {@link #convertType(Class,Object)} raises it + * @throws IllegalArgumentException if any other exception is raised by {@link #convertType(Class,Object)} + * @throws ClassCastException if an error occurs creating the method args + */ + protected Object[] createWriteMethodArguments(final Method method, Object value) throws IllegalAccessException, ClassCastException { try { - if ( value != null ) { + if (value != null) { final Class<? extends Object>[] types = method.getParameterTypes(); - if ( types != null && types.length > 0 ) { + if (types != null && types.length > 0) { final Class<? extends Object> paramType = types[0]; - if ( ! paramType.isAssignableFrom( value.getClass() ) ) { - value = convertType( paramType, value ); + if (!paramType.isAssignableFrom(value.getClass())) { + value = convertType(paramType, value); } } } return new Object[] { value }; - } - catch ( final InvocationTargetException | InstantiationException e ) { + } catch (final InvocationTargetException | InstantiationException e) { throw new IllegalArgumentException(e.getMessage(), e); } } @@ -444,6 +388,7 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { public boolean hasNext() { return iter.hasNext(); } + @Override public Map.Entry<Object, Object> next() { final Object key = iter.next(); @@ -452,12 +397,13 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { final // This should not cause any problems; the key is actually a // string, but it does no harm to expose it as Object - Map.Entry<Object, Object> tmpEntry = new Entry( BeanMap.this, key, value ); + Map.Entry<Object, Object> tmpEntry = new Entry(BeanMap.this, key, value); return tmpEntry; } + @Override public void remove() { - throw new UnsupportedOperationException( "remove() not supported for BeanMap" ); + throw new UnsupportedOperationException("remove() not supported for BeanMap"); } }; } @@ -476,50 +422,45 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { public Iterator<Map.Entry<Object, Object>> iterator() { return entryIterator(); } + @Override public int size() { - return BeanMap.this.readMethods.size(); + return BeanMap.this.readMethods.size(); } }); } /** - * Called during a successful {@link #put(Object,Object)} operation. - * Default implementation does nothing. Override to be notified of - * property changes in the bean caused by this map. + * Called during a successful {@link #put(Object,Object)} operation. Default implementation does nothing. Override to be notified of property changes in the + * bean caused by this map. * - * @param key the name of the property that changed - * @param oldValue the old value for that property - * @param newValue the new value for that property + * @param key the name of the property that changed + * @param oldValue the old value for that property + * @param newValue the new value for that property */ - protected void firePropertyChange( final Object key, final Object oldValue, final Object newValue ) { + protected void firePropertyChange(final Object key, final Object oldValue, final Object newValue) { } /** * Returns the value of the bean's property with the given name. * <p> - * The given name must be a {@link String} and must not be - * null; otherwise, this method returns <code>null</code>. - * If the bean defines a property with the given name, the value of - * that property is returned. Otherwise, <code>null</code> is - * returned. + * The given name must be a {@link String} and must not be null; otherwise, this method returns <code>null</code>. If the bean defines a property with the + * given name, the value of that property is returned. Otherwise, <code>null</code> is returned. * <p> - * Write-only properties will not be matched as the test operates against - * property read methods. + * Write-only properties will not be matched as the test operates against property read methods. * - * @param name the name of the property whose value to return - * @return the value of the property with that name + * @param name the name of the property whose value to return + * @return the value of the property with that name */ @Override public Object get(final Object name) { - if ( bean != null ) { - final Method method = getReadMethod( name ); - if ( method != null ) { + if (bean != null) { + final Method method = getReadMethod(name); + if (method != null) { try { - return method.invoke( bean, NULL_ARGUMENTS ); - } - catch ( final IllegalAccessException | IllegalArgumentException | InvocationTargetException | NullPointerException e ) { - logWarn( e ); + return method.invoke(bean, NULL_ARGUMENTS); + } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException | NullPointerException e) { + logWarn(e); } } } @@ -527,8 +468,7 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { } /** - * Returns the bean currently being operated on. The return value may - * be null if this map is empty. + * Returns the bean currently being operated on. The return value may be null if this map is empty. * * @return the bean being operated on by this map */ @@ -541,19 +481,17 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { /** * Returns the accessor for the property with the given name. * - * @param name the name of the property - * @return null if the name is null; null if the name is not a - * {@link String}; null if no such property exists; or the accessor - * method for that property + * @param name the name of the property + * @return null if the name is null; null if the name is not a {@link String}; null if no such property exists; or the accessor method for that property */ - protected Method getReadMethod( final Object name ) { - return readMethods.get( name ); + protected Method getReadMethod(final Object name) { + return readMethods.get(name); } /** * Returns the accessor for the property with the given name. * - * @param name the name of the property + * @param name the name of the property * @return the accessor method for the property, or null */ public Method getReadMethod(final String name) { @@ -563,23 +501,21 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { /** * Returns the type of the property with the given name. * - * @param name the name of the property - * @return the type of the property, or <code>null</code> if no such - * property exists + * @param name the name of the property + * @return the type of the property, or <code>null</code> if no such property exists */ public Class<?> getType(final String name) { - return types.get( name ); + return types.get(name); } /** * Returns a transformer for the given primitive type. * - * @param aType the primitive type whose transformer to return - * @return a transformer that will convert strings into that type, - * or null if the given type is not a primitive type + * @param aType the primitive type whose transformer to return + * @return a transformer that will convert strings into that type, or null if the given type is not a primitive type */ - protected Transformer getTypeTransformer( final Class<?> aType ) { - return typeTransformers.get( aType ); + protected Transformer getTypeTransformer(final Class<?> aType) { + return typeTransformers.get(aType); } // Properties @@ -587,19 +523,18 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { /** * Returns the mutator for the property with the given name. * - * @param name the name of the - * @return null if the name is null; null if the name is not a - * {@link String}; null if no such property exists; null if the - * property is read-only; or the mutator method for that property + * @param name the name of the + * @return null if the name is null; null if the name is not a {@link String}; null if no such property exists; null if the property is read-only; or the + * mutator method for that property */ - protected Method getWriteMethod( final Object name ) { - return writeMethods.get( name ); + protected Method getWriteMethod(final Object name) { + return writeMethods.get(name); } /** * Returns the mutator for the property with the given name. * - * @param name the name of the property + * @param name the name of the property * @return the mutator method for the property, or null */ public Method getWriteMethod(final String name) { @@ -607,36 +542,35 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { } private void initialise() { - if(getBean() == null) { + if (getBean() == null) { return; } - final Class<? extends Object> beanClass = getBean().getClass(); + final Class<? extends Object> beanClass = getBean().getClass(); try { - //BeanInfo beanInfo = Introspector.getBeanInfo( bean, null ); - final BeanInfo beanInfo = Introspector.getBeanInfo( beanClass ); + // BeanInfo beanInfo = Introspector.getBeanInfo( bean, null ); + final BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); - if ( propertyDescriptors != null ) { + if (propertyDescriptors != null) { for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) { - if ( propertyDescriptor != null ) { + if (propertyDescriptor != null) { final String name = propertyDescriptor.getName(); final Method readMethod = propertyDescriptor.getReadMethod(); final Method writeMethod = propertyDescriptor.getWriteMethod(); final Class<? extends Object> aType = propertyDescriptor.getPropertyType(); - if ( readMethod != null ) { - readMethods.put( name, readMethod ); + if (readMethod != null) { + readMethods.put(name, readMethod); } - if ( writeMethod != null ) { - writeMethods.put( name, writeMethod ); + if (writeMethod != null) { + writeMethods.put(name, writeMethod); } - types.put( name, aType ); + types.put(name, aType); } } } - } - catch ( final IntrospectionException e ) { - logWarn( e ); + } catch (final IntrospectionException e) { + logWarn(e); } } @@ -656,12 +590,10 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { /** * Get the keys for this BeanMap. * <p> - * Write-only properties are <strong>not</strong> included in the returned set of - * property names, although it is possible to set their value and to get + * Write-only properties are <strong>not</strong> included in the returned set of property names, although it is possible to set their value and to get * their type. * - * @return BeanMap keys. The Set returned by this method is not - * modifiable. + * @return BeanMap keys. The Set returned by this method is not modifiable. */ @SuppressWarnings({ "unchecked", "rawtypes" }) // The set actually contains strings; however, because it cannot be @@ -672,25 +604,23 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { } /** - * Logs the given exception to <code>System.out</code>. Used to display - * warnings while accessing/mutating the bean. + * Logs the given exception to <code>System.out</code>. Used to display warnings while accessing/mutating the bean. * - * @param ex the exception to log + * @param ex the exception to log */ protected void logInfo(final Exception ex) { // Deliberately do not use LOG4J or Commons Logging to avoid dependencies - System.out.println( "INFO: Exception: " + ex ); + System.out.println("INFO: Exception: " + ex); } /** - * Logs the given exception to <code>System.err</code>. Used to display - * errors while accessing/mutating the bean. + * Logs the given exception to <code>System.err</code>. Used to display errors while accessing/mutating the bean. * - * @param ex the exception to log + * @param ex the exception to log */ protected void logWarn(final Exception ex) { // Deliberately do not use LOG4J or Commons Logging to avoid dependencies - System.out.println( "WARN: Exception: " + ex ); + System.out.println("WARN: Exception: " + ex); ex.printStackTrace(); } @@ -698,31 +628,27 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { * Sets the bean property with the given name to the given value. * * @param name the name of the property to set - * @param value the value to set that property to - * @return the previous value of that property - * @throws IllegalArgumentException if the given name is null; - * if the given name is not a {@link String}; if the bean doesn't - * define a property with that name; or if the bean property with - * that name is read-only - * @throws ClassCastException if an error occurs creating the method args + * @param value the value to set that property to + * @return the previous value of that property + * @throws IllegalArgumentException if the given name is null; if the given name is not a {@link String}; if the bean doesn't define a property with that + * name; or if the bean property with that name is read-only + * @throws ClassCastException if an error occurs creating the method args */ @Override public Object put(final Object name, final Object value) throws IllegalArgumentException, ClassCastException { - if ( bean != null ) { - final Object oldValue = get( name ); - final Method method = getWriteMethod( name ); - if ( method == null ) { - throw new IllegalArgumentException( "The bean of type: "+ - bean.getClass().getName() + " has no property called: " + name ); + if (bean != null) { + final Object oldValue = get(name); + final Method method = getWriteMethod(name); + if (method == null) { + throw new IllegalArgumentException("The bean of type: " + bean.getClass().getName() + " has no property called: " + name); } try { - final Object[] arguments = createWriteMethodArguments( method, value ); - method.invoke( bean, arguments ); + final Object[] arguments = createWriteMethodArguments(method, value); + method.invoke(bean, arguments); - final Object newValue = get( name ); - firePropertyChange( name, oldValue, newValue ); - } - catch ( final InvocationTargetException | IllegalAccessException e ) { + final Object newValue = get(name); + firePropertyChange(name, oldValue, newValue); + } catch (final InvocationTargetException | IllegalAccessException e) { throw new IllegalArgumentException(e.getMessage(), e); } return oldValue; @@ -731,10 +657,9 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { } /** - * Puts all of the writable properties from the given BeanMap into this - * BeanMap. Read-only and Write-only properties will be ignored. + * Puts all of the writable properties from the given BeanMap into this BeanMap. Read-only and Write-only properties will be ignored. * - * @param map the BeanMap whose properties to put + * @param map the BeanMap whose properties to put */ public void putAllWriteable(final BeanMap map) { for (final Object key : map.readMethods.keySet()) { @@ -747,8 +672,7 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { // Implementation classes /** - * Reinitializes this bean. Called during {@link #setBean(Object)}. - * Does introspection to find properties. + * Reinitializes this bean. Called during {@link #setBean(Object)}. Does introspection to find properties. */ protected void reinitialise() { readMethods.clear(); @@ -758,12 +682,11 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { } /** - * Sets the bean to be operated on by this map. The given value may - * be null, in which case this map will be empty. + * Sets the bean to be operated on by this map. The given value may be null, in which case this map will be empty. * - * @param newBean the new bean to operate on + * @param newBean the new bean to operate on */ - public void setBean( final Object newBean ) { + public void setBean(final Object newBean) { bean = newBean; reinitialise(); } @@ -771,7 +694,7 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { /** * Returns the number of properties defined by the bean. * - * @return the number of properties defined by the bean + * @return the number of properties defined by the bean */ @Override public int size() { @@ -780,6 +703,7 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { /** * Renders a string representation of this object. + * * @return a <code>String</code> representation of this object */ @Override @@ -799,14 +723,16 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { public boolean hasNext() { return iter.hasNext(); } + @Override public Object next() { final Object key = iter.next(); return get(key); } + @Override public void remove() { - throw new UnsupportedOperationException( "remove() not supported for BeanMap" ); + throw new UnsupportedOperationException("remove() not supported for BeanMap"); } }; } @@ -814,14 +740,13 @@ public class BeanMap extends AbstractMap<Object, Object> implements Cloneable { /** * Returns the values for the BeanMap. * - * @return values for the BeanMap. The returned collection is not - * modifiable. + * @return values for the BeanMap. The returned collection is not modifiable. */ @Override public Collection<Object> values() { - final ArrayList<Object> answer = new ArrayList<>( readMethods.size() ); - for ( final Iterator<Object> iter = valueIterator(); iter.hasNext(); ) { - answer.add( iter.next() ); + final ArrayList<Object> answer = new ArrayList<>(readMethods.size()); + for (final Iterator<Object> iter = valueIterator(); iter.hasNext();) { + answer.add(iter.next()); } return Collections.unmodifiableList(answer); } diff --git a/src/main/java/org/apache/commons/beanutils/BeanPredicate.java b/src/main/java/org/apache/commons/beanutils/BeanPredicate.java index a05bcb76..da8b10f2 100644 --- a/src/main/java/org/apache/commons/beanutils/BeanPredicate.java +++ b/src/main/java/org/apache/commons/beanutils/BeanPredicate.java @@ -65,7 +65,7 @@ public class BeanPredicate implements Predicate { boolean evaluation = false; try { - final Object propValue = PropertyUtils.getProperty( object, propertyName ); + final Object propValue = PropertyUtils.getProperty(object, propertyName); evaluation = predicate.evaluate(propValue); } catch (final IllegalArgumentException e) { final String errorMsg = "Problem during evaluation."; diff --git a/src/main/java/org/apache/commons/beanutils/LazyDynaList.java b/src/main/java/org/apache/commons/beanutils/LazyDynaList.java index 1465090a..56ea1098 100644 --- a/src/main/java/org/apache/commons/beanutils/LazyDynaList.java +++ b/src/main/java/org/apache/commons/beanutils/LazyDynaList.java @@ -514,10 +514,10 @@ public class LazyDynaList extends ArrayList<Object> { this.elementDynaBeanType = dynaBean.getClass(); // Re-calculate the type - if (WrapDynaBean.class.isAssignableFrom(elementDynaBeanType )) { - this.elementType = ((WrapDynaBean)dynaBean).getInstance().getClass(); - } else if (LazyDynaMap.class.isAssignableFrom(elementDynaBeanType )) { - this.elementType = ((LazyDynaMap)dynaBean).getMap().getClass(); + if (WrapDynaBean.class.isAssignableFrom(elementDynaBeanType)) { + this.elementType = ((WrapDynaBean) dynaBean).getInstance().getClass(); + } else if (LazyDynaMap.class.isAssignableFrom(elementDynaBeanType)) { + this.elementType = ((LazyDynaMap) dynaBean).getMap().getClass(); } } diff --git a/src/main/java/org/apache/commons/beanutils/MethodUtils.java b/src/main/java/org/apache/commons/beanutils/MethodUtils.java index a404a2ac..2522533c 100644 --- a/src/main/java/org/apache/commons/beanutils/MethodUtils.java +++ b/src/main/java/org/apache/commons/beanutils/MethodUtils.java @@ -521,9 +521,9 @@ public class MethodUtils { } setMethodAccessible(method); // Default access superclass workaround myCost = getTotalTransformationCost(parameterTypes,method.getParameterTypes()); - if ( myCost < bestMatchCost ) { - bestMatch = method; - bestMatchCost = myCost; + if (myCost < bestMatchCost) { + bestMatch = method; + bestMatchCost = myCost; } } @@ -532,11 +532,11 @@ public class MethodUtils { } } } - if ( bestMatch != null ){ - cacheMethod(md, bestMatch); + if (bestMatch != null) { + cacheMethod(md, bestMatch); } else { - // didn't find a match - log.trace("No match found."); + // didn't find a match + log.trace("No match found."); } return bestMatch; diff --git a/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java b/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java index 08faaf5a..eefe0c5b 100644 --- a/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils/PropertyUtilsBean.java @@ -1197,58 +1197,43 @@ public class PropertyUtilsBean { * @throws NoSuchMethodException if an accessor method for this * propety cannot be found */ - public Object getSimpleProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { + public Object getSimpleProperty(final Object bean, final String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (bean == null) { throw new IllegalArgumentException("No bean specified"); } if (name == null) { - throw new IllegalArgumentException("No name specified for bean class '" + - bean.getClass() + "'"); + throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'"); } // Validate the syntax of the property name if (resolver.hasNested(name)) { - throw new IllegalArgumentException - ("Nested property names are not allowed: Property '" + - name + "' on bean class '" + bean.getClass() + "'"); + throw new IllegalArgumentException("Nested property names are not allowed: Property '" + name + "' on bean class '" + bean.getClass() + "'"); } if (resolver.isIndexed(name)) { - throw new IllegalArgumentException - ("Indexed property names are not allowed: Property '" + - name + "' on bean class '" + bean.getClass() + "'"); + throw new IllegalArgumentException("Indexed property names are not allowed: Property '" + name + "' on bean class '" + bean.getClass() + "'"); } if (resolver.isMapped(name)) { - throw new IllegalArgumentException - ("Mapped property names are not allowed: Property '" + - name + "' on bean class '" + bean.getClass() + "'"); + throw new IllegalArgumentException("Mapped property names are not allowed: Property '" + name + "' on bean class '" + bean.getClass() + "'"); } // Handle DynaBean instances specially if (bean instanceof DynaBean) { - final DynaProperty descriptor = - ((DynaBean) bean).getDynaClass().getDynaProperty(name); + final DynaProperty descriptor = ((DynaBean) bean).getDynaClass().getDynaProperty(name); if (descriptor == null) { - throw new NoSuchMethodException("Unknown property '" + - name + "' on dynaclass '" + - ((DynaBean) bean).getDynaClass() + "'" ); + throw new NoSuchMethodException("Unknown property '" + name + "' on dynaclass '" + ((DynaBean) bean).getDynaClass() + "'"); } return ((DynaBean) bean).get(name); } // Retrieve the property getter method for the specified property - final PropertyDescriptor descriptor = - getPropertyDescriptor(bean, name); + final PropertyDescriptor descriptor = getPropertyDescriptor(bean, name); if (descriptor == null) { - throw new NoSuchMethodException("Unknown property '" + - name + "' on class '" + bean.getClass() + "'" ); + throw new NoSuchMethodException("Unknown property '" + name + "' on class '" + bean.getClass() + "'"); } final Method readMethod = getReadMethod(bean.getClass(), descriptor); if (readMethod == null) { - throw new NoSuchMethodException("Property '" + name + - "' has no getter method in class '" + bean.getClass() + "'"); + throw new NoSuchMethodException("Property '" + name + "' has no getter method in class '" + bean.getClass() + "'"); } return invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY); diff --git a/src/main/java/org/apache/commons/beanutils/RowSetDynaClass.java b/src/main/java/org/apache/commons/beanutils/RowSetDynaClass.java index b147508a..b4013591 100644 --- a/src/main/java/org/apache/commons/beanutils/RowSetDynaClass.java +++ b/src/main/java/org/apache/commons/beanutils/RowSetDynaClass.java @@ -243,7 +243,7 @@ public class RowSetDynaClass extends JDBCDynaClass { protected void copy(final ResultSet resultSet) throws SQLException { int cnt = 0; - while (resultSet.next() && (limit < 0 || cnt++ < limit) ) { + while (resultSet.next() && (limit < 0 || cnt++ < limit)) { final DynaBean bean = createDynaBean(); for (final DynaProperty propertie : properties) { final String name = propertie.getName(); diff --git a/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java b/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java index b9b7243a..f016dd7d 100644 --- a/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java +++ b/src/main/java/org/apache/commons/beanutils/locale/LocaleConvertUtilsBean.java @@ -417,9 +417,7 @@ public class LocaleConvertUtilsBean { // behaviour of toString and valueOf methods of these classes converter.put(java.sql.Date.class, new SqlDateLocaleConverter(locale, "yyyy-MM-dd")); converter.put(java.sql.Time.class, new SqlTimeLocaleConverter(locale, "HH:mm:ss")); - converter.put( java.sql.Timestamp.class, - new SqlTimestampLocaleConverter(locale, "yyyy-MM-dd HH:mm:ss.S") - ); + converter.put(java.sql.Timestamp.class, new SqlTimestampLocaleConverter(locale, "yyyy-MM-dd HH:mm:ss.S")); converter.setFast(true); diff --git a/src/main/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java b/src/main/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java index e23afcd7..4e32ca66 100644 --- a/src/main/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java +++ b/src/main/java/org/apache/commons/beanutils/locale/converters/DateLocaleConverter.java @@ -282,7 +282,7 @@ public class DateLocaleConverter extends BaseLocaleConverter { quoted = true; } else if (thisChar >= 'a' && thisChar <= 'z' || thisChar >= 'A' && thisChar <= 'Z') { - final int index = fromChars.indexOf(thisChar ); + final int index = fromChars.indexOf(thisChar); if (index == -1) { throw new IllegalArgumentException( "Illegal pattern character '" + thisChar + "'"); diff --git a/src/test/java/org/apache/commons/beanutils/BeanPredicateTestCase.java b/src/test/java/org/apache/commons/beanutils/BeanPredicateTestCase.java index 7e294434..6f3319b9 100644 --- a/src/test/java/org/apache/commons/beanutils/BeanPredicateTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/BeanPredicateTestCase.java @@ -33,29 +33,25 @@ public class BeanPredicateTestCase extends TestCase { } public void testEqual() { - final BeanPredicate predicate = - new BeanPredicate("stringProperty",new EqualPredicate("foo")); + final BeanPredicate predicate = new BeanPredicate("stringProperty", new EqualPredicate("foo")); assertTrue(predicate.evaluate(new TestBean("foo"))); assertTrue(!predicate.evaluate(new TestBean("bar"))); } public void testInstanceOf() { - final BeanPredicate predicate = - new BeanPredicate("stringProperty",new InstanceofPredicate( String.class )); + final BeanPredicate predicate = new BeanPredicate("stringProperty", new InstanceofPredicate(String.class)); assertTrue(predicate.evaluate(new TestBean("foo"))); assertTrue(predicate.evaluate(new TestBean("bar"))); } public void testNotEqual() { - final BeanPredicate predicate = - new BeanPredicate("stringProperty",new NotPredicate( new EqualPredicate("foo"))); + final BeanPredicate predicate = new BeanPredicate("stringProperty", new NotPredicate(new EqualPredicate("foo"))); assertTrue(!predicate.evaluate(new TestBean("foo"))); assertTrue(predicate.evaluate(new TestBean("bar"))); } public void testNull() { - final BeanPredicate predicate = - new BeanPredicate("stringProperty", NullPredicate.INSTANCE); + final BeanPredicate predicate = new BeanPredicate("stringProperty", NullPredicate.INSTANCE); final String nullString = null; assertTrue(predicate.evaluate(new TestBean(nullString))); assertTrue(!predicate.evaluate(new TestBean("bar"))); diff --git a/src/test/java/org/apache/commons/beanutils/BeanificationTestCase.java b/src/test/java/org/apache/commons/beanutils/BeanificationTestCase.java index de6a2934..193064bc 100644 --- a/src/test/java/org/apache/commons/beanutils/BeanificationTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/BeanificationTestCase.java @@ -479,8 +479,9 @@ public class BeanificationTestCase extends TestCase { public void testMemoryTestMethodology() throws Exception { // test methodology // many thanks to Juozas Baliuka for suggesting this method - ClassLoader loader = new ClassLoader(this.getClass().getClassLoader()) {}; - final WeakReference<ClassLoader> reference = new WeakReference<>(loader); + ClassLoader loader = new ClassLoader(this.getClass().getClassLoader()) { + }; + final WeakReference<ClassLoader> reference = new WeakReference<>(loader); @SuppressWarnings("unused") Class<?> myClass = loader.loadClass("org.apache.commons.beanutils.BetaBean"); @@ -492,19 +493,18 @@ public class BeanificationTestCase extends TestCase { int iterations = 0; int bytz = 2; - while(true) { + while (true) { System.gc(); - if(iterations++ > MAX_GC_ITERATIONS){ + if (iterations++ > MAX_GC_ITERATIONS) { fail("Max iterations reached before resource released."); } - if( reference.get() == null ) { + if (reference.get() == null) { break; } // create garbage: @SuppressWarnings("unused") - final - byte[] b = new byte[bytz]; + final byte[] b = new byte[bytz]; bytz = bytz * 2; } } diff --git a/src/test/java/org/apache/commons/beanutils/DynaPropertyUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils/DynaPropertyUtilsTestCase.java index 7077fbae..e255cb56 100644 --- a/src/test/java/org/apache/commons/beanutils/DynaPropertyUtilsTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/DynaPropertyUtilsTestCase.java @@ -1424,8 +1424,7 @@ public class DynaPropertyUtilsTestCase extends TestCase { fail("InvocationTargetException"); } catch (final NoSuchMethodException e) { // Correct result for this test - assertEquals("Unknown property 'unknown' on dynaclass '" + - bean.getDynaClass() + "'", e.getMessage() ); + assertEquals("Unknown property 'unknown' on dynaclass '" + bean.getDynaClass() + "'", e.getMessage()); } } @@ -2513,12 +2512,8 @@ public class DynaPropertyUtilsTestCase extends TestCase { try { final String oldValue = (String) bean.get("stringProperty"); final String newValue = oldValue + " Extra Value"; - PropertyUtils.setSimpleProperty(bean, - "stringProperty", - newValue); - assertEquals("Matched new value", - newValue, - (String) bean.get("stringProperty")); + PropertyUtils.setSimpleProperty(bean, "stringProperty", newValue); + assertEquals("Matched new value", newValue, (String) bean.get("stringProperty")); } catch (final IllegalAccessException e) { fail("IllegalAccessException"); } catch (final IllegalArgumentException e) { @@ -2538,9 +2533,7 @@ public class DynaPropertyUtilsTestCase extends TestCase { try { final String newValue = "New String Value"; - PropertyUtils.setSimpleProperty(bean, - "unknown", - newValue); + PropertyUtils.setSimpleProperty(bean, "unknown", newValue); fail("Should have thrown NoSuchMethodException"); } catch (final IllegalAccessException e) { fail("IllegalAccessException"); @@ -2550,8 +2543,7 @@ public class DynaPropertyUtilsTestCase extends TestCase { fail("InvocationTargetException"); } catch (final NoSuchMethodException e) { // Correct result for this test - assertEquals("Unknown property 'unknown' on dynaclass '" + - bean.getDynaClass() + "'", e.getMessage() ); + assertEquals("Unknown property 'unknown' on dynaclass '" + bean.getDynaClass() + "'", e.getMessage()); } } diff --git a/src/test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java index e918ec52..50c7f875 100644 --- a/src/test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/MethodUtilsTestCase.java @@ -599,14 +599,13 @@ public class MethodUtilsTestCase extends TestCase { value = MethodUtils.invokeStaticMethod(TestBean.class, "currentCounter", new Object[0]); assertEquals("currentCounter value", current, ((Integer) value).intValue()); - MethodUtils.invokeStaticMethod(TestBean.class, "incrementCounter", new Object[] { Integer.valueOf(8) } ); + MethodUtils.invokeStaticMethod(TestBean.class, "incrementCounter", new Object[] { Integer.valueOf(8) }); current += 8; value = MethodUtils.invokeStaticMethod(TestBean.class, "currentCounter", new Object[0]); assertEquals("currentCounter value", current, ((Integer) value).intValue()); - MethodUtils.invokeExactStaticMethod(TestBean.class, "incrementCounter", - new Object[] { Integer.valueOf(8) }, new Class[] { Number.class } ); + MethodUtils.invokeExactStaticMethod(TestBean.class, "incrementCounter", new Object[] { Integer.valueOf(8) }, new Class[] { Number.class }); current += 16; value = MethodUtils.invokeStaticMethod(TestBean.class, "currentCounter", new Object[0]); diff --git a/src/test/java/org/apache/commons/beanutils/PropertyUtilsTestCase.java b/src/test/java/org/apache/commons/beanutils/PropertyUtilsTestCase.java index 1ba27f71..dccbac93 100644 --- a/src/test/java/org/apache/commons/beanutils/PropertyUtilsTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/PropertyUtilsTestCase.java @@ -2395,8 +2395,7 @@ public class PropertyUtilsTestCase extends TestCase { fail("InvocationTargetException"); } catch (final NoSuchMethodException e) { // Correct result for this test - assertEquals("Unknown property 'unknown' on class '" + - bean.getClass() + "'", e.getMessage() ); + assertEquals("Unknown property 'unknown' on class '" + bean.getClass() + "'", e.getMessage()); } } @@ -2417,8 +2416,7 @@ public class PropertyUtilsTestCase extends TestCase { fail("InvocationTargetException"); } catch (final NoSuchMethodException e) { // Correct result for this test - assertEquals("Property 'writeOnlyProperty' has no getter method in class '" + - bean.getClass() + "'", e.getMessage() ); + assertEquals("Property 'writeOnlyProperty' has no getter method in class '" + bean.getClass() + "'", e.getMessage()); } } @@ -2431,10 +2429,9 @@ public class PropertyUtilsTestCase extends TestCase { * @param className Class name where this method should be defined */ protected void testGetWriteMethod(final Object bean, final String properties[], - final String className) { + final String className) { - final PropertyDescriptor pd[] = - PropertyUtils.getPropertyDescriptors(bean); + final PropertyDescriptor pd[] = PropertyUtils.getPropertyDescriptors(bean); for (final String propertie : properties) { // Identify the property descriptor for this property @@ -2459,19 +2456,14 @@ public class PropertyUtilsTestCase extends TestCase { break; } } - assertTrue("PropertyDescriptor for " + propertie, - n >= 0); + assertTrue("PropertyDescriptor for " + propertie, n >= 0); // Locate an accessible property reader method for it final Method writer = PropertyUtils.getWriteMethod(pd[n]); - assertNotNull("Writer for " + propertie, - writer); + assertNotNull("Writer for " + propertie, writer); final Class<?> clazz = writer.getDeclaringClass(); - assertNotNull("Declaring class for " + propertie, - clazz); - assertEquals("Correct declaring class for " + propertie, - clazz.getName(), - className); + assertNotNull("Declaring class for " + propertie, clazz); + assertEquals("Correct declaring class for " + propertie, clazz.getName(), className); } @@ -4286,9 +4278,7 @@ public class PropertyUtilsTestCase extends TestCase { try { final String oldValue = bean.getWriteOnlyPropertyValue(); final String newValue = oldValue + " Extra Value"; - PropertyUtils.setSimpleProperty(bean, - "readOnlyProperty", - newValue); + PropertyUtils.setSimpleProperty(bean, "readOnlyProperty", newValue); fail("Should have thrown NoSuchMethodException"); } catch (final IllegalAccessException e) { fail("IllegalAccessException"); @@ -4298,8 +4288,7 @@ public class PropertyUtilsTestCase extends TestCase { fail("InvocationTargetException"); } catch (final NoSuchMethodException e) { // Correct result for this test - assertEquals("Property 'readOnlyProperty' has no setter method in class '" + - bean.getClass() + "'", e.getMessage() ); + assertEquals("Property 'readOnlyProperty' has no setter method in class '" + bean.getClass() + "'", e.getMessage()); } } @@ -4313,12 +4302,8 @@ public class PropertyUtilsTestCase extends TestCase { final short oldValue = bean.getShortProperty(); short newValue = oldValue; newValue++; - PropertyUtils.setSimpleProperty(bean, - "shortProperty", - Short.valueOf(newValue)); - assertEquals("Matched new value", - newValue, - bean.getShortProperty()); + PropertyUtils.setSimpleProperty(bean, "shortProperty", Short.valueOf(newValue)); + assertEquals("Matched new value", newValue, bean.getShortProperty()); } catch (final IllegalAccessException e) { fail("IllegalAccessException"); } catch (final IllegalArgumentException e) { @@ -4339,12 +4324,8 @@ public class PropertyUtilsTestCase extends TestCase { try { final String oldValue = bean.getStringProperty(); final String newValue = oldValue + " Extra Value"; - PropertyUtils.setSimpleProperty(bean, - "stringProperty", - newValue); - assertEquals("Matched new value", - newValue, - bean.getStringProperty()); + PropertyUtils.setSimpleProperty(bean, "stringProperty", newValue); + assertEquals("Matched new value", newValue, bean.getStringProperty()); } catch (final IllegalAccessException e) { fail("IllegalAccessException"); } catch (final IllegalArgumentException e) { @@ -4364,9 +4345,7 @@ public class PropertyUtilsTestCase extends TestCase { try { final String newValue = "New String Value"; - PropertyUtils.setSimpleProperty(bean, - "unknown", - newValue); + PropertyUtils.setSimpleProperty(bean, "unknown", newValue); fail("Should have thrown NoSuchMethodException"); } catch (final IllegalAccessException e) { fail("IllegalAccessException"); @@ -4376,8 +4355,7 @@ public class PropertyUtilsTestCase extends TestCase { fail("InvocationTargetException"); } catch (final NoSuchMethodException e) { // Correct result for this test - assertEquals("Unknown property 'unknown' on class '" + - bean.getClass() + "'", e.getMessage() ); + assertEquals("Unknown property 'unknown' on class '" + bean.getClass() + "'", e.getMessage()); } } @@ -4390,12 +4368,8 @@ public class PropertyUtilsTestCase extends TestCase { try { final String oldValue = bean.getWriteOnlyPropertyValue(); final String newValue = oldValue + " Extra Value"; - PropertyUtils.setSimpleProperty(bean, - "writeOnlyProperty", - newValue); - assertEquals("Matched new value", - newValue, - bean.getWriteOnlyPropertyValue()); + PropertyUtils.setSimpleProperty(bean, "writeOnlyProperty", newValue); + assertEquals("Matched new value", newValue, bean.getWriteOnlyPropertyValue()); } catch (final IllegalAccessException e) { fail("IllegalAccessException"); } catch (final IllegalArgumentException e) { @@ -4417,9 +4391,7 @@ public class PropertyUtilsTestCase extends TestCase { // don't init! try { - PropertyUtils.getProperty( - nestedBean, - "simpleBeanProperty.indexedProperty[0]"); + PropertyUtils.getProperty(nestedBean, "simpleBeanProperty.indexedProperty[0]"); fail("NestedNullException not thrown"); } catch (final NestedNullException e) { // that's what we wanted! diff --git a/src/test/java/org/apache/commons/beanutils/TestBean.java b/src/test/java/org/apache/commons/beanutils/TestBean.java index 65990c50..8b2c4ea5 100644 --- a/src/test/java/org/apache/commons/beanutils/TestBean.java +++ b/src/test/java/org/apache/commons/beanutils/TestBean.java @@ -461,9 +461,9 @@ private java.util.Date dateProperty; return this.invalidBoolean; } - public void setAnotherNested( final TestBean anotherNested ) { - this.anotherNested = anotherNested; - } + public void setAnotherNested(final TestBean anotherNested) { + this.anotherNested = anotherNested; + } public void setBooleanProperty(final boolean booleanProperty) { this.booleanProperty = booleanProperty; 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 64aca885..7ddd56b3 100644 --- a/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTestCase.java +++ b/src/test/java/org/apache/commons/beanutils/locale/LocaleBeanificationTestCase.java @@ -517,8 +517,9 @@ public class LocaleBeanificationTestCase extends TestCase { public void testMemoryTestMethodology() throws Exception { // test methodology // many thanks to Juozas Baliuka for suggesting this method - ClassLoader loader = new ClassLoader(this.getClass().getClassLoader()) {}; - final WeakReference<ClassLoader> reference = new WeakReference<>(loader); + ClassLoader loader = new ClassLoader(this.getClass().getClassLoader()) { + }; + final WeakReference<ClassLoader> reference = new WeakReference<>(loader); Class<?> myClass = loader.loadClass("org.apache.commons.beanutils.BetaBean"); assertNotNull("Weak reference released early", reference.get()); @@ -529,17 +530,17 @@ public class LocaleBeanificationTestCase extends TestCase { int iterations = 0; int bytz = 2; - while(true) { + while (true) { System.gc(); - if(iterations++ > MAX_GC_ITERATIONS){ + if (iterations++ > MAX_GC_ITERATIONS) { fail("Max iterations reached before resource released."); } - if( reference.get() == null ) { + if (reference.get() == null) { break; } // create garbage: - final byte[] b = new byte[bytz]; + final byte[] b = new byte[bytz]; bytz = bytz * 2; } }