- *
- * @param the type of the object to be constructed
- * @param klass the class to be constructed.
- * @param args actual argument array. May be null (this will result in calling the default constructor).
- * @return new instance of {@code klazz}
- *
- * @throws NoSuchMethodException If the constructor cannot be found
- * @throws IllegalAccessException If an error occurs accessing the constructor
- * @throws InvocationTargetException If an error occurs invoking the constructor
- * @throws InstantiationException If an error occurs instantiating the class
- *
- * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
- */
- public static T invokeConstructor(final Class klass, Object[] args)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException,
- InstantiationException {
-
- if (null == args) {
- args = EMPTY_OBJECT_ARRAY;
- }
- final int arguments = args.length;
- final Class>[] parameterTypes = new Class>[arguments];
- for (int i = 0; i < arguments; i++) {
- parameterTypes[i] = args[i].getClass();
- }
- return invokeConstructor(klass, args, parameterTypes);
- }
-
- /**
- *
Returns new instance of {@code klazz} created using constructor
- * with signature {@code parameterTypes and actual arguments args}.
- *
- *
The signatures should be assignment compatible.
- *
- * @param the type of the object to be constructed
- * @param klass the class to be constructed.
- * @param args actual argument array. May be null (this will result in calling the default constructor).
- * @param parameterTypes parameter types array
- * @return new instance of {@code klazz}
- *
- * @throws NoSuchMethodException if matching constructor cannot be found
- * @throws IllegalAccessException thrown on the constructor's invocation
- * @throws InvocationTargetException thrown on the constructor's invocation
- * @throws InstantiationException thrown on the constructor's invocation
- * @see Constructor#newInstance
- */
- public static T invokeConstructor(
- final Class klass,
- Object[] args,
- Class>[] parameterTypes)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException,
- InstantiationException {
-
- if (parameterTypes == null) {
- parameterTypes = EMPTY_CLASS_PARAMETERS;
- }
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
-
- final Constructor ctor =
- getMatchingAccessibleConstructor(klass, parameterTypes);
- if (null == ctor) {
- throw new NoSuchMethodException(
- "No such accessible constructor on object: " + klass.getName());
- }
- return ctor.newInstance(args);
- }
-
- /**
- *
Convenience method returning new instance of {@code klazz} using a single argument constructor.
- * The formal parameter type is inferred from the actual values of {@code arg}.
- * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.
- *
- *
The signatures should match exactly.
- *
- * @param the type of the object to be constructed
- * @param klass the class to be constructed.
- * @param arg the actual argument. May be null (this will result in calling the default constructor).
- * @return new instance of {@code klazz}
- *
- * @throws NoSuchMethodException If the constructor cannot be found
- * @throws IllegalAccessException If an error occurs accessing the constructor
- * @throws InvocationTargetException If an error occurs invoking the constructor
- * @throws InstantiationException If an error occurs instantiating the class
- *
- * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
- */
- public static T invokeExactConstructor(final Class klass, final Object arg)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException,
- InstantiationException {
-
- final Object[] args = toArray(arg);
- return invokeExactConstructor(klass, args);
- }
-
- /**
- *
Returns new instance of {@code klazz created using the actual arguments args}.
- * The formal parameter types are inferred from the actual values of {@code args}.
- * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.
- *
- *
The signatures should match exactly.
- *
- * @param the type of the object to be constructed
- * @param klass the class to be constructed.
- * @param args actual argument array. May be null (this will result in calling the default constructor).
- * @return new instance of {@code klazz}
- *
- * @throws NoSuchMethodException If the constructor cannot be found
- * @throws IllegalAccessException If an error occurs accessing the constructor
- * @throws InvocationTargetException If an error occurs invoking the constructor
- * @throws InstantiationException If an error occurs instantiating the class
- *
- * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[])
- */
- public static T invokeExactConstructor(final Class klass, Object[] args)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException,
- InstantiationException {
-
- if (null == args) {
- args = EMPTY_OBJECT_ARRAY;
- }
- final int arguments = args.length;
- final Class>[] parameterTypes = new Class[arguments];
- for (int i = 0; i < arguments; i++) {
- parameterTypes[i] = args[i].getClass();
- }
- return invokeExactConstructor(klass, args, parameterTypes);
- }
-
- /**
- *
Returns new instance of {@code klazz} created using constructor
- * with signature {@code parameterTypes} and actual arguments
- * {@code args}.
- *
- *
The signatures should match exactly.
- *
- * @param the type of the object to be constructed
- * @param klass the class to be constructed.
- * @param args actual argument array. May be null (this will result in calling the default constructor).
- * @param parameterTypes parameter types array
- * @return new instance of {@code klazz}
- *
- * @throws NoSuchMethodException if matching constructor cannot be found
- * @throws IllegalAccessException thrown on the constructor's invocation
- * @throws InvocationTargetException thrown on the constructor's invocation
- * @throws InstantiationException thrown on the constructor's invocation
- * @see Constructor#newInstance
- */
- public static T invokeExactConstructor(
- final Class klass,
- Object[] args,
- Class>[] parameterTypes)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException,
- InstantiationException {
-
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
-
- if (parameterTypes == null) {
- parameterTypes = EMPTY_CLASS_PARAMETERS;
- }
-
- final Constructor ctor = getAccessibleConstructor(klass, parameterTypes);
- if (null == ctor) {
- throw new NoSuchMethodException(
- "No such accessible constructor on object: " + klass.getName());
- }
- return ctor.newInstance(args);
- }
-
- /**
- * Returns a constructor with single argument.
- * @param the type of the constructor
- * @param klass the class to be constructed
- * @param parameterType The constructor parameter type
- * @return null if matching accessible constructor can not be found.
- * @see Class#getConstructor
- * @see #getAccessibleConstructor(java.lang.reflect.Constructor)
- */
- public static Constructor getAccessibleConstructor(
- final Class klass,
- final Class> parameterType) {
-
- final Class>[] parameterTypes = { parameterType };
- return getAccessibleConstructor(klass, parameterTypes);
- }
-
- /**
- * Returns a constructor given a class and signature.
- * @param the type to be constructed
- * @param klass the class to be constructed
- * @param parameterTypes the parameter array
- * @return null if matching accessible constructor can not be found
- * @see Class#getConstructor
- * @see #getAccessibleConstructor(java.lang.reflect.Constructor)
- */
- public static Constructor getAccessibleConstructor(
- final Class klass,
- final Class>[] parameterTypes) {
-
- try {
- return getAccessibleConstructor(
- klass.getConstructor(parameterTypes));
- } catch (final NoSuchMethodException e) {
- return null;
- }
- }
-
- /**
- * Returns accessible version of the given constructor.
- * @param the type of the constructor
- * @param ctor prototype constructor object.
- * @return {@code null} if accessible constructor can not be found.
- * @see java.lang.SecurityManager
- */
- 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())) {
- return null;
- }
-
- // If the declaring class is public, we are done
- final Class clazz = ctor.getDeclaringClass();
- if (Modifier.isPublic(clazz.getModifiers())) {
- return ctor;
- }
-
- // what else can we do?
- return null;
- }
-
- private static Object[] toArray(final Object arg) {
- Object[] args = null;
- if (arg != null) {
- args = new Object[] { arg };
- }
- return args;
- }
-
-
- /**
- *
Find an accessible constructor with compatible parameters.
- * Compatible parameters mean that every method parameter is assignable from
- * the given parameters. In other words, it finds constructor that will take
- * the parameters given.
- *
- *
First it checks if there is constructor matching the exact signature.
- * If no such, all the constructors of the class are tested if their signatures
- * are assignment compatible with the parameter types.
- * The first matching constructor is returned.
- *
- * @param the type of the class to be inspected
- * @param clazz find constructor for this class
- * @param parameterTypes find method with compatible parameters
- * @return a valid Constructor object. If there's no matching constructor, returns {@code null}.
- */
- private static Constructor getMatchingAccessibleConstructor(
- final Class clazz,
- final Class>[] parameterTypes) {
- // see if we can find the method directly
- // most of the time this works and it's much faster
- try {
- final Constructor ctor = clazz.getConstructor(parameterTypes);
- try {
- //
- // XXX Default access superclass workaround
- //
- // When a public class has a default access superclass
- // with public methods, these methods are accessible.
- // Calling them from compiled code works fine.
- //
- // Unfortunately, using reflection to invoke these methods
- // seems to (wrongly) to prevent access even when the method
- // modifier is public.
- //
- // The following workaround solves the problem but will only
- // work from sufficiently privileges code.
- //
- // Better workarounds would be gratefully accepted.
- //
- ctor.setAccessible(true);
- } catch (final SecurityException se) {
- /* SWALLOW, if workaround fails don't fret. */
- }
- return ctor;
-
- } catch (final NoSuchMethodException e) { /* SWALLOW */
- }
-
- // search through all methods
- final int paramSize = parameterTypes.length;
- final Constructor>[] ctors = clazz.getConstructors();
- for (final Constructor> ctor2 : ctors) {
- // compare parameters
- final Class>[] ctorParams = ctor2.getParameterTypes();
- final int ctorParamSize = ctorParams.length;
- if (ctorParamSize == paramSize) {
- boolean match = true;
- for (int n = 0; n < ctorParamSize; n++) {
- if (!MethodUtils
- .isAssignmentCompatible(
- ctorParams[n],
- parameterTypes[n])) {
- match = false;
- break;
- }
- }
-
- if (match) {
- // get accessible version of method
- final Constructor> ctor = getAccessibleConstructor(ctor2);
- if (ctor != null) {
- try {
- ctor.setAccessible(true);
- } catch (final SecurityException se) {
- /* Swallow SecurityException
- * TODO: Why?
- */
- }
- @SuppressWarnings("unchecked")
- final
- // Class.getConstructors() actually returns constructors
- // of type T, so it is safe to cast.
- Constructor typedCtor = (Constructor) ctor;
- return typedCtor;
- }
- }
- }
- }
-
- return null;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ContextClassLoaderLocal.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ContextClassLoaderLocal.java
deleted file mode 100644
index cb61ea930..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ContextClassLoaderLocal.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.util.Map;
-import java.util.WeakHashMap;
-
-/**
- * An instance of this class represents a value that is provided per (thread)
- * context classloader.
- *
- *
Occasionally it is necessary to store data in "global" variables
- * (including uses of the Singleton pattern). In applications which have only
- * a single classloader such data can simply be stored as "static" members on
- * some class. When multiple classloaders are involved, however, this approach
- * can fail; in particular, this doesn't work when the code may be run within a
- * servlet container or a j2ee container, and the class on which the static
- * member is defined is loaded via a "shared" classloader that is visible to all
- * components running within the container. This class provides a mechanism for
- * associating data with a ClassLoader instance, which ensures that when the
- * code runs in such a container each component gets its own copy of the
- * "global" variable rather than unexpectedly sharing a single copy of the
- * variable with other components that happen to be running in the same
- * container at the same time (eg servlets or EJBs.)
- *
- *
This class is strongly patterned after the java.lang.ThreadLocal
- * class, which performs a similar task in allowing data to be associated
- * with a particular thread.
- *
- *
When code that uses this class is run as a "normal" application, ie
- * not within a container, the effect is identical to just using a static
- * member variable to store the data, because Thread.getContextClassLoader
- * always returns the same classloader (the system classloader).
- *
- *
Expected usage is as follows:
- *
- *
- * public class SomeClass {
- * private static final ContextClassLoaderLocal<String> global
- * = new ContextClassLoaderLocal<String>() {
- * protected String initialValue() {
- * return new String("Initial value");
- * };
- *
- * public void testGlobal() {
- * String s = global.get();
- * System.out.println("global value:" + s);
- * buf.set("New Value");
- * }
- *
- *
- *
- *
Note: This class takes some care to ensure that when
- * a component which uses this class is "undeployed" by a container the
- * component-specific classloader and all its associated classes (and their
- * static variables) are garbage-collected. Unfortunately there is one
- * scenario in which this does not work correctly and there
- * is unfortunately no known workaround other than ensuring that the
- * component (or its container) calls the "unset" method on this class for
- * each instance of this class when the component is undeployed. The problem
- * occurs if:
- *
- *
the class containing a static instance of this class was loaded via
- * a shared classloader, and
- *
the value stored in the instance is an object whose class was loaded
- * via the component-specific classloader (or any of the objects it refers
- * to were loaded via that classloader).
- *
- *
The result is that the map managed by this object still contains a strong
- * reference to the stored object, which contains a strong reference to the
- * classloader that loaded it, meaning that although the container has
- * "undeployed" the component the component-specific classloader and all the
- * related classes and static variables cannot be garbage-collected. This is
- * not expected to be an issue with the commons-beanutils library as the only
- * classes which use this class are BeanUtilsBean and ConvertUtilsBean and
- * there is no obvious reason for a user of the beanutils library to subclass
- * either of those classes.
- *
- *
Note: A WeakHashMap bug in several 1.3 JVMs results in
- * a memory leak for those JVMs.
- *
- *
Note: Of course all of this would be unnecessary if
- * containers required each component to load the full set of classes it
- * needs, ie avoided providing classes loaded via a "shared" classloader.
- *
- * @param the type of data stored in an instance
- * @see java.lang.Thread#getContextClassLoader
- */
-public class ContextClassLoaderLocal {
- private final Map valueByClassLoader = new WeakHashMap<>();
- private boolean globalValueInitialized = false;
- private T globalValue;
-
- /**
- * Construct a context classloader instance
- */
- public ContextClassLoaderLocal() {
- super();
- }
-
- /**
- * Returns the initial value for this ContextClassLoaderLocal
- * variable. This method will be called once per Context ClassLoader for
- * each ContextClassLoaderLocal, the first time it is accessed
- * with get or set. If the programmer desires ContextClassLoaderLocal variables
- * to be initialized to some value other than null, ContextClassLoaderLocal must
- * be subclassed, and this method overridden. Typically, an anonymous
- * inner class will be used. Typical implementations of initialValue
- * will call an appropriate constructor and return the newly constructed
- * object.
- *
- * @return a new Object to be used as an initial value for this ContextClassLoaderLocal
- */
- protected T initialValue() {
- return null;
- }
-
- /**
- * Gets the instance which provides the functionality for {@link BeanUtils}.
- * This is a pseudo-singleton - an single instance is provided per (thread) context classloader.
- * This mechanism provides isolation for web apps deployed in the same container.
- * @return the object currently associated with the context-classloader of the current thread.
- */
- public synchronized T get() {
- // synchronizing the whole method is a bit slower
- // but guarantees no subtle threading problems, and there's no
- // need to synchronize valueByClassLoader
-
- // make sure that the map is given a change to purge itself
- valueByClassLoader.isEmpty();
- try {
-
- final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- if (contextClassLoader != null) {
-
- T value = valueByClassLoader.get(contextClassLoader);
- if (value == null
- && !valueByClassLoader.containsKey(contextClassLoader)) {
- value = initialValue();
- valueByClassLoader.put(contextClassLoader, value);
- }
- return value;
-
- }
-
- } catch (final SecurityException e) { /* SWALLOW - should we log this? */ }
-
- // if none or exception, return the globalValue
- if (!globalValueInitialized) {
- globalValue = initialValue();
- globalValueInitialized = true;
- }//else already set
- return globalValue;
- }
-
- /**
- * Sets the value - a value is provided per (thread) context classloader.
- * This mechanism provides isolation for web apps deployed in the same container.
- *
- * @param value the object to be associated with the entrant thread's context classloader
- */
- public synchronized void set(final T value) {
- // synchronizing the whole method is a bit slower
- // but guarantees no subtle threading problems
-
- // make sure that the map is given a change to purge itself
- valueByClassLoader.isEmpty();
- try {
-
- final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- if (contextClassLoader != null) {
- valueByClassLoader.put(contextClassLoader, value);
- return;
- }
-
- } catch (final SecurityException e) { /* SWALLOW - should we log this? */ }
-
- // if in doubt, set the global value
- globalValue = value;
- globalValueInitialized = true;
- }
-
- /**
- * Unsets the value associated with the current thread's context classloader
- */
- public synchronized void unset() {
- try {
-
- final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- unset(contextClassLoader);
-
- } catch (final SecurityException e) { /* SWALLOW - should we log this? */ }
- }
-
- /**
- * Unsets the value associated with the given classloader
- * @param classLoader The classloader to unset for
- */
- public synchronized void unset(final ClassLoader classLoader) {
- valueByClassLoader.remove(classLoader);
- }
-}
\ No newline at end of file
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConversionException.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConversionException.java
deleted file mode 100644
index d6b031d42..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConversionException.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- *
A ConversionException indicates that a call to
- * {@code Converter.convert()} has failed to complete successfully.
- *
- * @since 1.3
- */
-
-public class ConversionException extends RuntimeException {
-
- private static final long serialVersionUID = 1L;
-
-
-
- /**
- * Construct a new exception with the specified message.
- *
- * @param message The message describing this exception
- */
- public ConversionException(final String message) {
-
- super(message);
-
- }
-
- /**
- * Construct a new exception with the specified message and root cause.
- *
- * @param message The message describing this exception
- * @param cause The root cause of this exception
- */
- public ConversionException(final String message, final Throwable cause) {
-
- super(message);
- this.cause = cause;
-
- }
-
- /**
- * Construct a new exception with the specified root cause.
- *
- * @param cause The root cause of this exception
- */
- public ConversionException(final Throwable cause) {
-
- super(cause.getMessage());
- this.cause = cause;
-
- }
-
-
-
- /**
- * The root cause of this {@code ConversionException}, compatible with
- * JDK 1.4's extensions to {@code java.lang.Throwable}.
- */
- protected Throwable cause = null;
-
- /**
- * Return the root cause of this conversion exception.
- * @return the root cause of this conversion exception
- */
- @Override
- public Throwable getCause() {
- return this.cause;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java
deleted file mode 100644
index 4d5ee2289..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.commons.beanutils2;
-
-/**
- *
Utility methods for converting String scalar values to objects of the
- * specified Class, String arrays to arrays of the specified Class.
- *
- *
For more details, see {@code ConvertUtilsBean} which provides the
- * implementations for these methods.
- *
- * @param value Value to be converted (may be null)
- * @return The converted String value or null if value is null
- *
- * @see ConvertUtilsBean#convert(Object)
- */
- public static String convert(final Object value) {
- return ConvertUtilsBean.getInstance().convert(value);
- }
-
-
- /**
- *
Convert the specified value to an object of the specified class (if
- * possible). Otherwise, return a String representation of the value.
- *
- *
For more details see {@code ConvertUtilsBean}.
- *
- * @param value Value to be converted (may be null)
- * @param clazz Java class to be converted to (must not be null)
- * @return The converted value
- *
- * @see ConvertUtilsBean#convert(String, Class)
- */
- public static Object convert(final String value, final Class> clazz) {
- return ConvertUtilsBean.getInstance().convert(value, clazz);
- }
-
-
- /**
- *
Convert an array of specified values to an array of objects of the
- * specified class (if possible).
- *
- *
For more details see {@code ConvertUtilsBean}.
- *
- * @param values Array of values to be converted
- * @param clazz Java array or element class to be converted to (must not be null)
- * @return The converted value
- *
- * @see ConvertUtilsBean#convert(String[], Class)
- */
- public static Object convert(final String[] values, final Class> clazz) {
- return ConvertUtilsBean.getInstance().convert(values, clazz);
- }
-
- /**
- *
Convert the value to an object of the specified class (if
- * possible).
- *
- * @param value Value to be converted (may be null)
- * @param targetType Class of the value to be converted to (must not be null)
- * @return The converted value
- *
- * @throws ConversionException if thrown by an underlying Converter
- */
- public static Object convert(final Object value, final Class> targetType) {
- return ConvertUtilsBean.getInstance().convert(value, targetType);
- }
-
- /**
- *
Remove all registered {@link Converter}s, and re-establish the
- * standard Converters.
Remove any registered {@link Converter} for the specified destination
- * {@code Class}.
- *
- *
For more details see {@code ConvertUtilsBean}.
- *
- * @param clazz Class for which to remove a registered Converter
- * @see ConvertUtilsBean#deregister(Class)
- */
- public static void deregister(final Class> clazz) {
- ConvertUtilsBean.getInstance().deregister(clazz);
- }
-
-
- /**
- *
Look up and return any registered {@link Converter} for the specified
- * destination class; if there is no registered Converter, return
- * {@code null}.
- *
- *
For more details see {@code ConvertUtilsBean}.
- *
- * @param clazz Class for which to return a registered Converter
- * @return The registered {@link Converter} or {@code null} if not found
- * @see ConvertUtilsBean#lookup(Class)
- */
- public static Converter lookup(final Class> clazz) {
- return ConvertUtilsBean.getInstance().lookup(clazz);
- }
-
- /**
- * Look up and return any registered {@link Converter} for the specified
- * source and destination class; if there is no registered Converter,
- * return {@code null}.
- *
- * @param sourceType Class of the value being converted
- * @param targetType Class of the value to be converted to
- * @return The registered {@link Converter} or {@code null} if not found
- */
- public static Converter lookup(final Class> sourceType, final Class> targetType) {
- return ConvertUtilsBean.getInstance().lookup(sourceType, targetType);
- }
-
- /**
- *
Register a custom {@link Converter} for the specified destination
- * {@code Class}, replacing any previously registered Converter.
- *
- *
For more details see {@code ConvertUtilsBean}.
- *
- * @param converter Converter to be registered
- * @param clazz Destination class for conversions performed by this
- * Converter
- * @see ConvertUtilsBean#register(Converter, Class)
- */
- public static void register(final Converter converter, final Class> clazz) {
- ConvertUtilsBean.getInstance().register(converter, clazz);
- }
-
-
- /**
- * Change primitive Class types to the associated wrapper class. This is
- * useful for concrete converter implementations which typically treat
- * primitive types like their corresponding wrapper types.
- *
- * @param The type to be checked.
- * @param type The class type to check.
- * @return The converted type.
- * @since 1.9
- */
- // All type casts are safe because the TYPE members of the wrapper types
- // return their own class.
- @SuppressWarnings("unchecked")
- public static Class primitiveToWrapper(final Class type) {
- if (type == null || !type.isPrimitive()) {
- return type;
- }
-
- if (type == Integer.TYPE) {
- return (Class) Integer.class;
- } else if (type == Double.TYPE) {
- return (Class) Double.class;
- } else if (type == Long.TYPE) {
- return (Class) Long.class;
- } else if (type == Boolean.TYPE) {
- return (Class) Boolean.class;
- } else if (type == Float.TYPE) {
- return (Class) Float.class;
- } else if (type == Short.TYPE) {
- return (Class) Short.class;
- } else if (type == Byte.TYPE) {
- return (Class) Byte.class;
- } else if (type == Character.TYPE) {
- return (Class) Character.class;
- } else {
- return type;
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java
deleted file mode 100644
index 54117cd75..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java
+++ /dev/null
@@ -1,725 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.io.File;
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.URI;
-import java.net.URL;
-import java.nio.file.Path;
-import java.sql.Timestamp;
-import java.time.Duration;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.MonthDay;
-import java.time.OffsetDateTime;
-import java.time.OffsetTime;
-import java.time.Period;
-import java.time.Year;
-import java.time.YearMonth;
-import java.time.ZoneId;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.UUID;
-
-import org.apache.commons.beanutils2.converters.ArrayConverter;
-import org.apache.commons.beanutils2.converters.BigDecimalConverter;
-import org.apache.commons.beanutils2.converters.BigIntegerConverter;
-import org.apache.commons.beanutils2.converters.BooleanConverter;
-import org.apache.commons.beanutils2.converters.ByteConverter;
-import org.apache.commons.beanutils2.converters.CalendarConverter;
-import org.apache.commons.beanutils2.converters.CharacterConverter;
-import org.apache.commons.beanutils2.converters.ClassConverter;
-import org.apache.commons.beanutils2.converters.ConverterFacade;
-import org.apache.commons.beanutils2.converters.DateConverter;
-import org.apache.commons.beanutils2.converters.DoubleConverter;
-import org.apache.commons.beanutils2.converters.EnumConverter;
-import org.apache.commons.beanutils2.converters.DurationConverter;
-import org.apache.commons.beanutils2.converters.FileConverter;
-import org.apache.commons.beanutils2.converters.FloatConverter;
-import org.apache.commons.beanutils2.converters.IntegerConverter;
-import org.apache.commons.beanutils2.converters.LocalDateConverter;
-import org.apache.commons.beanutils2.converters.LocalDateTimeConverter;
-import org.apache.commons.beanutils2.converters.LocalTimeConverter;
-import org.apache.commons.beanutils2.converters.LongConverter;
-import org.apache.commons.beanutils2.converters.MonthDayConverter;
-import org.apache.commons.beanutils2.converters.OffsetDateTimeConverter;
-import org.apache.commons.beanutils2.converters.OffsetTimeConverter;
-import org.apache.commons.beanutils2.converters.PathConverter;
-import org.apache.commons.beanutils2.converters.PeriodConverter;
-import org.apache.commons.beanutils2.converters.ShortConverter;
-import org.apache.commons.beanutils2.converters.SqlDateConverter;
-import org.apache.commons.beanutils2.converters.SqlTimeConverter;
-import org.apache.commons.beanutils2.converters.SqlTimestampConverter;
-import org.apache.commons.beanutils2.converters.StringConverter;
-import org.apache.commons.beanutils2.converters.URIConverter;
-import org.apache.commons.beanutils2.converters.URLConverter;
-import org.apache.commons.beanutils2.converters.UUIDConverter;
-import org.apache.commons.beanutils2.converters.YearConverter;
-import org.apache.commons.beanutils2.converters.YearMonthConverter;
-import org.apache.commons.beanutils2.converters.ZoneIdConverter;
-import org.apache.commons.beanutils2.converters.ZoneOffsetConverter;
-import org.apache.commons.beanutils2.converters.ZonedDateTimeConverter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
Utility methods for converting String scalar values to objects of the
- * specified Class, String arrays to arrays of the specified Class. The
- * actual {@link Converter} instance to be used can be registered for each
- * possible destination Class. Unless you override them, standard
- * {@link Converter} instances are provided for all of the following
- * destination Classes:
- *
- *
java.lang.BigDecimal (no default value)
- *
java.lang.BigInteger (no default value)
- *
boolean and java.lang.Boolean (default to false)
- *
byte and java.lang.Byte (default to zero)
- *
char and java.lang.Character (default to a space)
- *
java.lang.Class (no default value)
- *
double and java.lang.Double (default to zero)
- *
float and java.lang.Float (default to zero)
- *
int and java.lang.Integer (default to zero)
- *
long and java.lang.Long (default to zero)
- *
short and java.lang.Short (default to zero)
- *
java.lang.String (default to null)
- *
java.lang.Enum (default to null)
- *
java.io.File (no default value)
- *
java.nio.file.Path (no default value)
- *
java.net.URL (no default value)
- *
java.net.URI (no default value)
- *
java.util.UUID (no default value)
- *
java.sql.Date (no default value)
- *
java.sql.Time (no default value)
- *
java.sql.Timestamp (no default value)
- *
java.time.LocalDate (no default value)
- *
java.time.LocalDateTime (no default value)
- *
java.time.LocalTime (no default value)
- *
java.time.OffsetDateTime (no default value)
- *
java.time.OffsetTime (no default value)
- *
java.time.ZonedDateTime (no default value)
- *
java.time.Duration (no default value)
- *
java.time.MonthDay (no default value)
- *
java.time.Period (no default value)
- *
java.time.Year (no default value)
- *
java.time.YearMonth (no default value)
- *
java.time.ZoneId (no default value)
- *
java.time.ZoneOffset (no default value)
- *
- *
- *
For backwards compatibility, the standard Converters for primitive
- * types (and the corresponding wrapper classes) return a defined
- * default value when a conversion error occurs. If you prefer to have a
- * {@link ConversionException} thrown instead, replace the standard Converter
- * instances with instances created with the zero-arguments constructor. For
- * example, to cause the Converters for integers to throw an exception on
- * conversion errors, you could do this:
- *
- * // No-args constructor gets the version that throws exceptions
- * Converter myConverter =
- * new org.apache.commons.beanutils2.converter.IntegerConverter();
- * ConvertUtils.register(myConverter, Integer.TYPE); // Native type
- * ConvertUtils.register(myConverter, Integer.class); // Wrapper class
- *
- *
- *
- * Converters generally treat null input as if it were invalid
- * input, ie they return their default value if one was specified when the
- * converter was constructed, and throw an exception otherwise. If you prefer
- * nulls to be preserved for converters that are converting to objects (not
- * primitives) then register a converter as above, passing a default value of
- * null to the converter constructor (and of course registering that converter
- * only for the .class target).
- *
- *
- *
- * When a converter is listed above as having no default value, then that
- * converter will throw an exception when passed null or an invalid value
- * as its input. In particular, by default the BigInteger and BigDecimal
- * converters have no default (and are therefore somewhat inconsistent
- * with the other numerical converters which all have zero as their default).
- *
- *
- *
- * Converters that generate arrays of each of the primitive types are
- * also automatically configured (including String[]). When passed null
- * or invalid input, these return an empty array (not null). See class
- * AbstractArrayConverter for the supported input formats for these converters.
- *
- *
- * @since 1.7
- */
-
-public class ConvertUtilsBean {
-
- private static final Integer ZERO = Integer.valueOf(0);
- private static final Character SPACE = Character.valueOf(' ');
-
-
- /**
- * Get singleton instance
- * @return The singleton instance
- */
- protected static ConvertUtilsBean getInstance() {
- return BeanUtilsBean.getInstance().getConvertUtils();
- }
-
-
-
- /**
- * The set of {@link Converter}s that can be used to convert Strings
- * into objects of a specified Class, keyed by the destination Class.
- */
- private final WeakFastHashMap, Converter> converters =
- new WeakFastHashMap<>();
-
- /**
- * The {@code Log} instance for this class.
- */
- private final Log log = LogFactory.getLog(ConvertUtilsBean.class);
-
-
-
- /** Construct a bean with standard converters registered */
- public ConvertUtilsBean() {
- converters.setFast(false);
- deregister();
- converters.setFast(true);
- }
-
-
-
- /**
- * Convert the specified value into a String. If the specified value
- * is an array, the first element (converted to a String) will be
- * returned. The registered {@link Converter} for the
- * {@code java.lang.String} class will be used, which allows
- * applications to customize Object->String conversions (the default
- * implementation simply uses toString()).
- *
- * @param value Value to be converted (may be null)
- * @return The converted String value or null if value is null
- */
- public String convert(Object value) {
-
- if (value == null) {
- return null;
- } else if (value.getClass().isArray()) {
- if (Array.getLength(value) < 1) {
- return null;
- }
- value = Array.get(value, 0);
- if (value == null) {
- return null;
- }
- final Converter converter = lookup(String.class);
- return converter.convert(String.class, value);
- } else {
- final Converter converter = lookup(String.class);
- return converter.convert(String.class, value);
- }
-
- }
-
- /**
- * Convert the specified value to an object of the specified class (if
- * possible). Otherwise, return a String representation of the value.
- *
- * @param value Value to be converted (may be null)
- * @param clazz Java class to be converted to (must not be null)
- * @return The converted value
- *
- * @throws ConversionException if thrown by an underlying Converter
- */
- public Object convert(final String value, final Class> clazz) {
-
- if (log.isDebugEnabled()) {
- log.debug("Convert string '" + value + "' to class '" +
- clazz.getName() + "'");
- }
- Converter converter = lookup(clazz);
- if (converter == null) {
- converter = lookup(String.class);
- }
- if (log.isTraceEnabled()) {
- log.trace(" Using converter " + converter);
- }
- return converter.convert(clazz, value);
-
- }
-
- /**
- * Convert an array of specified values to an array of objects of the
- * specified class (if possible). If the specified Java class is itself
- * an array class, this class will be the type of the returned value.
- * Otherwise, an array will be constructed whose component type is the
- * specified class.
- *
- * @param values Array of values to be converted
- * @param clazz Java array or element class to be converted to (must not be null)
- * @return The converted value
- *
- * @throws ConversionException if thrown by an underlying Converter
- */
- public Object convert(final String[] values, final Class> clazz) {
-
- Class> type = clazz;
- if (clazz.isArray()) {
- type = clazz.getComponentType();
- }
- if (log.isDebugEnabled()) {
- log.debug("Convert String[" + values.length + "] to class '" +
- type.getName() + "[]'");
- }
- Converter converter = lookup(type);
- if (converter == null) {
- converter = lookup(String.class);
- }
- if (log.isTraceEnabled()) {
- log.trace(" Using converter " + converter);
- }
- final Object array = Array.newInstance(type, values.length);
- for (int i = 0; i < values.length; i++) {
- Array.set(array, i, converter.convert(type, values[i]));
- }
- return array;
-
- }
-
- /**
- * Convert the value to an object of the specified class (if
- * possible). If no converter for the desired target type is registered,
- * the passed in object is returned unchanged.
- *
- * @param value Value to be converted (may be null)
- * @param targetType Class of the value to be converted to (must not be null)
- * @return The converted value
- *
- * @throws ConversionException if thrown by an underlying Converter
- */
- public Object convert(final Object value, final Class> targetType) {
-
- final Class> sourceType = value == null ? null : value.getClass();
-
- if (log.isDebugEnabled()) {
- if (value == null) {
- log.debug("Convert null value to type '" +
- targetType.getName() + "'");
- } else {
- log.debug("Convert type '" + sourceType.getName() + "' value '" + value +
- "' to type '" + targetType.getName() + "'");
- }
- }
-
- Object converted = value;
- Converter converter = lookup(sourceType, targetType);
- if (converter != null) {
- if (log.isTraceEnabled()) {
- log.trace(" Using converter " + converter);
- }
- converted = converter.convert(targetType, value);
- }
- if (String.class.equals(targetType) && converted != null &&
- !(converted instanceof String)) {
-
- // NOTE: For backwards compatibility, if the Converter
- // doesn't handle conversion-->String then
- // use the registered String Converter
- converter = lookup(String.class);
- if (converter != null) {
- if (log.isTraceEnabled()) {
- log.trace(" Using converter " + converter);
- }
- converted = converter.convert(String.class, converted);
- }
-
- // If the object still isn't a String, use toString() method
- if (converted != null && !(converted instanceof String)) {
- converted = converted.toString();
- }
-
- }
- return converted;
-
- }
-
- /**
- * Remove all registered {@link Converter}s, and re-establish the
- * standard Converters.
- */
- public void deregister() {
-
- converters.clear();
-
- registerPrimitives(false);
- registerStandard(false, false);
- registerOther(true);
- registerArrays(false, 0);
- register(BigDecimal.class, new BigDecimalConverter());
- register(BigInteger.class, new BigIntegerConverter());
- }
-
- /**
- * Register the provided converters with the specified defaults.
- *
- * @param throwException {@code true} if the converters should
- * throw an exception when a conversion error occurs, otherwise
- * {@code false} if a default value should be used.
- * @param defaultNull {@code true}if the standard converters
- * (see {@link ConvertUtilsBean#registerStandard(boolean, boolean)})
- * should use a default value of {@code null, otherwise false}.
- * N.B. This values is ignored if {@code throwException is true}
- * @param defaultArraySize The size of the default array value for array converters
- * (N.B. This values is ignored if {@code throwException is true}).
- * Specifying a value less than zero causes a {@code null} value to be used for
- * the default.
- */
- public void register(final boolean throwException, final boolean defaultNull, final int defaultArraySize) {
- registerPrimitives(throwException);
- registerStandard(throwException, defaultNull);
- registerOther(throwException);
- registerArrays(throwException, defaultArraySize);
- }
-
- /**
- * Register the converters for primitive types.
- *
- * This method registers the following converters:
- *
- * @param throwException {@code true} if the converters should
- * throw an exception when a conversion error occurs, otherwise
- * {@code false} if a default value should be used.
- */
- private void registerPrimitives(final boolean throwException) {
- register(Boolean.TYPE, throwException ? new BooleanConverter() : new BooleanConverter(Boolean.FALSE));
- register(Byte.TYPE, throwException ? new ByteConverter() : new ByteConverter(ZERO));
- register(Character.TYPE, throwException ? new CharacterConverter() : new CharacterConverter(SPACE));
- register(Double.TYPE, throwException ? new DoubleConverter() : new DoubleConverter(ZERO));
- register(Float.TYPE, throwException ? new FloatConverter() : new FloatConverter(ZERO));
- register(Integer.TYPE, throwException ? new IntegerConverter() : new IntegerConverter(ZERO));
- register(Long.TYPE, throwException ? new LongConverter() : new LongConverter(ZERO));
- register(Short.TYPE, throwException ? new ShortConverter() : new ShortConverter(ZERO));
- }
-
- /**
- * Register the converters for standard types.
- *
- * This method registers the following converters:
- *
- * @param throwException {@code true} if the converters should
- * throw an exception when a conversion error occurs, otherwise
- * {@code false} if a default value should be used.
- * @param defaultNull {@code true}if the standard converters
- * (see {@link ConvertUtilsBean#registerStandard(boolean, boolean)})
- * should use a default value of {@code null, otherwise false}.
- * N.B. This values is ignored if {@code throwException is true}
- */
- private void registerStandard(final boolean throwException, final boolean defaultNull) {
-
- final Number defaultNumber = defaultNull ? null : ZERO;
- final BigDecimal bigDecDeflt = defaultNull ? null : new BigDecimal("0.0");
- final BigInteger bigIntDeflt = defaultNull ? null : new BigInteger("0");
- final Boolean booleanDefault = defaultNull ? null : Boolean.FALSE;
- final Character charDefault = defaultNull ? null : SPACE;
- final String stringDefault = defaultNull ? null : "";
-
- register(BigDecimal.class, throwException ? new BigDecimalConverter() : new BigDecimalConverter(bigDecDeflt));
- register(BigInteger.class, throwException ? new BigIntegerConverter() : new BigIntegerConverter(bigIntDeflt));
- register(Boolean.class, throwException ? new BooleanConverter() : new BooleanConverter(booleanDefault));
- register(Byte.class, throwException ? new ByteConverter() : new ByteConverter(defaultNumber));
- register(Character.class, throwException ? new CharacterConverter() : new CharacterConverter(charDefault));
- register(Double.class, throwException ? new DoubleConverter() : new DoubleConverter(defaultNumber));
- register(Float.class, throwException ? new FloatConverter() : new FloatConverter(defaultNumber));
- register(Integer.class, throwException ? new IntegerConverter() : new IntegerConverter(defaultNumber));
- register(Long.class, throwException ? new LongConverter() : new LongConverter(defaultNumber));
- register(Short.class, throwException ? new ShortConverter() : new ShortConverter(defaultNumber));
- register(String.class, throwException ? new StringConverter() : new StringConverter(stringDefault));
-
- }
-
- /**
- * Register the converters for other types.
- *
- * This method registers the following converters:
- *
- * @param throwException {@code true} if the converters should
- * throw an exception when a conversion error occurs, otherwise
- * {@code false} if a default value should be used.
- */
- private void registerOther(final boolean throwException) {
- // @formatter:off
- register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null));
- register(Enum.class, throwException ? new EnumConverter() : new EnumConverter(null));
- register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null));
- register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null));
- register(File.class, throwException ? new FileConverter() : new FileConverter(null));
- register(Path.class, throwException ? new PathConverter() : new PathConverter(null));
- register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null));
- register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null));
- register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null));
- register(URL.class, throwException ? new URLConverter() : new URLConverter(null));
- register(URI.class, throwException ? new URIConverter() : new URIConverter(null));
- register(UUID.class, throwException ? new UUIDConverter() : new UUIDConverter(null));
- register(LocalDate.class, throwException ? new LocalDateConverter() : new LocalDateConverter(null));
- register(LocalDateTime.class, throwException ? new LocalDateTimeConverter() : new LocalDateTimeConverter(null));
- register(LocalTime.class, throwException ? new LocalTimeConverter() : new LocalTimeConverter(null));
- register(OffsetDateTime.class, throwException ? new OffsetDateTimeConverter() : new OffsetDateTimeConverter(null));
- register(OffsetTime.class, throwException ? new OffsetTimeConverter() : new OffsetTimeConverter(null));
- register(ZonedDateTime.class, throwException ? new ZonedDateTimeConverter() : new ZonedDateTimeConverter(null));
- register(Duration.class, throwException ? new DurationConverter() : new DurationConverter(null));
- register(MonthDay.class, throwException ? new MonthDayConverter() : new MonthDayConverter(null));
- register(Period.class, throwException ? new PeriodConverter() : new PeriodConverter(null));
- register(Year.class, throwException ? new YearConverter() : new YearConverter(null));
- register(YearMonth.class, throwException ? new YearMonthConverter() : new YearMonthConverter(null));
- register(ZoneId.class, throwException ? new ZoneIdConverter() : new ZoneIdConverter(null));
- register(ZoneOffset.class, throwException ? new ZoneOffsetConverter() : new ZoneOffsetConverter(null));
- // @formatter:on
- }
-
- /**
- * Register array converters.
- *
- * @param throwException {@code true} if the converters should
- * throw an exception when a conversion error occurs, otherwise
- * {@code false} if a default value should be used.
- * @param defaultArraySize The size of the default array value for array converters
- * (N.B. This values is ignored if {@code throwException is true}).
- * Specifying a value less than zero causes a null value to be used for
- * the default.
- */
- private void registerArrays(final boolean throwException, final int defaultArraySize) {
- // @formatter:off
-
- // Primitives
- registerArrayConverter(Boolean.TYPE, new BooleanConverter(), throwException, defaultArraySize);
- registerArrayConverter(Byte.TYPE, new ByteConverter(), throwException, defaultArraySize);
- registerArrayConverter(Character.TYPE, new CharacterConverter(), throwException, defaultArraySize);
- registerArrayConverter(Double.TYPE, new DoubleConverter(), throwException, defaultArraySize);
- registerArrayConverter(Float.TYPE, new FloatConverter(), throwException, defaultArraySize);
- registerArrayConverter(Integer.TYPE, new IntegerConverter(), throwException, defaultArraySize);
- registerArrayConverter(Long.TYPE, new LongConverter(), throwException, defaultArraySize);
- registerArrayConverter(Short.TYPE, new ShortConverter(), throwException, defaultArraySize);
-
- // Standard
- registerArrayConverter(BigDecimal.class, new BigDecimalConverter(), throwException, defaultArraySize);
- registerArrayConverter(BigInteger.class, new BigIntegerConverter(), throwException, defaultArraySize);
- registerArrayConverter(Boolean.class, new BooleanConverter(), throwException, defaultArraySize);
- registerArrayConverter(Byte.class, new ByteConverter(), throwException, defaultArraySize);
- registerArrayConverter(Character.class, new CharacterConverter(), throwException, defaultArraySize);
- registerArrayConverter(Double.class, new DoubleConverter(), throwException, defaultArraySize);
- registerArrayConverter(Float.class, new FloatConverter(), throwException, defaultArraySize);
- registerArrayConverter(Integer.class, new IntegerConverter(), throwException, defaultArraySize);
- registerArrayConverter(Long.class, new LongConverter(), throwException, defaultArraySize);
- registerArrayConverter(Short.class, new ShortConverter(), throwException, defaultArraySize);
- registerArrayConverter(String.class, new StringConverter(), throwException, defaultArraySize);
-
- // Other
- registerArrayConverter(Class.class, new ClassConverter(), throwException, defaultArraySize);
- registerArrayConverter(Enum.class, new EnumConverter(), throwException, defaultArraySize);
- registerArrayConverter(java.util.Date.class, new DateConverter(), throwException, defaultArraySize);
- registerArrayConverter(Calendar.class, new DateConverter(), throwException, defaultArraySize);
- registerArrayConverter(File.class, new FileConverter(), throwException, defaultArraySize);
- registerArrayConverter(Path.class, new PathConverter(), throwException, defaultArraySize);
- registerArrayConverter(java.sql.Date.class, new SqlDateConverter(), throwException, defaultArraySize);
- registerArrayConverter(java.sql.Time.class, new SqlTimeConverter(), throwException, defaultArraySize);
- registerArrayConverter(Timestamp.class, new SqlTimestampConverter(), throwException, defaultArraySize);
- registerArrayConverter(URL.class, new URLConverter(), throwException, defaultArraySize);
- registerArrayConverter(URI.class, new URIConverter(), throwException, defaultArraySize);
- registerArrayConverter(UUID.class, new UUIDConverter(), throwException, defaultArraySize);
- registerArrayConverter(LocalDate.class, new LocalDateConverter(), throwException, defaultArraySize);
- registerArrayConverter(LocalDateTime.class, new LocalDateTimeConverter(), throwException, defaultArraySize);
- registerArrayConverter(LocalTime.class, new LocalTimeConverter(), throwException, defaultArraySize);
- registerArrayConverter(OffsetDateTime.class, new OffsetDateTimeConverter(),throwException, defaultArraySize);
- registerArrayConverter(OffsetTime.class, new OffsetTimeConverter(), throwException, defaultArraySize);
- registerArrayConverter(ZonedDateTime.class, new ZonedDateTimeConverter(), throwException, defaultArraySize);
- registerArrayConverter(Duration.class, new DurationConverter(), throwException, defaultArraySize);
- registerArrayConverter(MonthDay.class, new MonthDayConverter(), throwException, defaultArraySize);
- registerArrayConverter(Period.class, new PeriodConverter(), throwException, defaultArraySize);
- registerArrayConverter(Year.class, new YearConverter(), throwException, defaultArraySize);
- registerArrayConverter(YearMonth.class, new YearMonthConverter(), throwException, defaultArraySize);
- registerArrayConverter(ZoneId.class, new ZoneIdConverter(), throwException, defaultArraySize);
- registerArrayConverter(ZoneOffset.class, new ZoneOffsetConverter(), throwException, defaultArraySize);
- // @formatter:on
- }
-
- /**
- * Register a new ArrayConverter with the specified element delegate converter
- * that returns a default array of the specified size in the event of conversion errors.
- *
- * @param componentType The component type of the array
- * @param componentConverter The converter to delegate to for the array elements
- * @param throwException Whether a conversion exception should be thrown or a default
- * value used in the event of a conversion error
- * @param defaultArraySize The size of the default array
- */
- private void registerArrayConverter(final Class> componentType, final Converter componentConverter,
- final boolean throwException, final int defaultArraySize) {
- final Class> arrayType = Array.newInstance(componentType, 0).getClass();
- Converter arrayConverter = null;
- if (throwException) {
- arrayConverter = new ArrayConverter(arrayType, componentConverter);
- } else {
- arrayConverter = new ArrayConverter(arrayType, componentConverter, defaultArraySize);
- }
- register(arrayType, arrayConverter);
- }
-
- /** strictly for convenience since it has same parameter order as Map.put */
- private void register(final Class> clazz, final Converter converter) {
- register(new ConverterFacade(converter), clazz);
- }
-
- /**
- * Remove any registered {@link Converter} for the specified destination
- * {@code Class}.
- *
- * @param clazz Class for which to remove a registered Converter
- */
- public void deregister(final Class> clazz) {
-
- converters.remove(clazz);
-
- }
-
- /**
- * Look up and return any registered {@link Converter} for the specified
- * destination class; if there is no registered Converter, return
- * {@code null}.
- *
- * @param clazz Class for which to return a registered Converter
- * @return The registered {@link Converter} or {@code null} if not found
- */
- public Converter lookup(final Class> clazz) {
-
- return converters.get(clazz);
-
- }
-
- /**
- * Look up and return any registered {@link Converter} for the specified
- * source and destination class; if there is no registered Converter,
- * return {@code null}.
- *
- * @param sourceType Class of the value being converted
- * @param targetType Class of the value to be converted to
- * @return The registered {@link Converter} or {@code null} if not found
- */
- public Converter lookup(final Class> sourceType, final Class> targetType) {
-
- if (targetType == null) {
- throw new IllegalArgumentException("Target type is missing");
- }
- if (sourceType == null) {
- return lookup(targetType);
- }
-
- Converter converter = null;
- // Convert --> String
- if (targetType == String.class) {
- converter = lookup(sourceType);
- if (converter == null && (sourceType.isArray() ||
- Collection.class.isAssignableFrom(sourceType))) {
- converter = lookup(String[].class);
- }
- if (converter == null) {
- converter = lookup(String.class);
- }
- return converter;
- }
-
- // Convert --> String array
- if (targetType == String[].class) {
- if (sourceType.isArray() || Collection.class.isAssignableFrom(sourceType)) {
- converter = lookup(sourceType);
- }
- if (converter == null) {
- converter = lookup(String[].class);
- }
- return converter;
- }
-
- return lookup(targetType);
-
- }
-
- /**
- * Register a custom {@link Converter} for the specified destination
- * {@code Class}, replacing any previously registered Converter.
- *
- * @param converter Converter to be registered
- * @param clazz Destination class for conversions performed by this
- * Converter
- */
- public void register(final Converter converter, final Class> clazz) {
-
- converters.put(clazz, converter);
-
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java
deleted file mode 100644
index f06958e19..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-/**
- * {@link ConvertUtilsBean} implementation that delegates {@code convert()}
- * methods to the new {@link ConvertUtilsBean#convert(Object, Class)} method.
- *
- *
- * To configure this implementation for the current context ClassLoader invoke
- * {@code BeanUtilsBean.setInstance(new BeanUtilsBean2());}
- *
- *
- * @see BeanUtilsBean2
- * @since 1.8.0
- */
-public class ConvertUtilsBean2 extends ConvertUtilsBean {
-
- /**
- * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)}
- * method.
- *
- * @param value Value to be converted (may be null)
- * @return The converted String value or null if value is null
- *
- * @see ConvertUtilsBean#convert(String[], Class)
- */
- @Override
- public String convert(final Object value) {
- return (String)convert(value, String.class);
- }
-
- /**
- * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)}
- * method.
- *
- * @param value Value to be converted (may be null)
- * @param clazz Java class to be converted to (must not be null)
- * @return The converted value or null if value is null
- *
- * @see ConvertUtilsBean#convert(String[], Class)
- */
- @Override
- public Object convert(final String value, final Class> clazz) {
- return convert((Object)value, clazz);
- }
-
- /**
- * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)}
- * method.
- *
- * @param value Array of values to be converted
- * @param clazz Java array or element class to be converted to (must not be null)
- * @return The converted value
- *
- * @see ConvertUtilsBean#convert(String[], Class)
- */
- @Override
- public Object convert(final String[] value, final Class> clazz) {
- return convert((Object)value, clazz);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/Converter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/Converter.java
deleted file mode 100644
index 34e9ef083..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/Converter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- *
General purpose data type converter that can be registered and used
- * within the BeanUtils package to manage the conversion of objects from
- * one type to another.
- *
- *
Converter subclasses bundled with the BeanUtils library are required
- * to be thread-safe, as users of the library may call conversion methods
- * from more than one thread simultaneously.
- *
- *
Custom converter subclasses created by users of the library can be
- * non-thread-safe if the application using them is single-threaded. However
- * it is recommended that they be written in a thread-safe manner anyway.
- *
- * @since 1.3
- */
-public interface Converter {
-
- /**
- * Convert the specified input object into an output object of the
- * specified type.
- *
- * @param the desired result type
- * @param type Data type to which this value should be converted
- * @param value The input value to be converted
- * @return The converted value
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- */
- T convert(Class type, Object value);
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertingWrapDynaBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertingWrapDynaBean.java
deleted file mode 100644
index 588bf5d9f..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertingWrapDynaBean.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.lang.reflect.InvocationTargetException;
-
-/**
- *
Implementation of {@code DynaBean} that wraps a standard JavaBean
- * instance, so that DynaBean APIs can be used to access its properties,
- * though this implementation allows type conversion to occur when properties are set.
- * This means that (say) Strings can be passed in as values in setter methods and
- * this DynaBean will convert them to the correct primitive data types.
- *
- *
IMPLEMENTATION NOTE - This implementation does not
- * support the {@code contains()
and remove()} methods.
- *
- */
-
-public class ConvertingWrapDynaBean extends WrapDynaBean {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Construct a new {@code DynaBean} associated with the specified
- * JavaBean instance.
- *
- * @param instance JavaBean instance to be wrapped
- */
- public ConvertingWrapDynaBean(final Object instance) {
-
- super(instance);
-
- }
-
- /**
- * Set the value of the property with the specified name
- * performing any type conversions if necessary. So this method
- * can accept String values for primitive numeric data types for example.
- *
- * @param name Name of the property whose value is to be set
- * @param value Value to which this property is to be set
- *
- * @throws IllegalArgumentException if there are any problems
- * copying the property.
- */
- @Override
- public void set(final String name, final Object value) {
-
- try {
- BeanUtils.copyProperty(instance, name, value);
- } catch (final InvocationTargetException ite) {
- final Throwable cause = ite.getTargetException();
- throw new IllegalArgumentException
- ("Error setting property '" + name +
- "' nested exception - " + cause);
- } catch (final Throwable t) {
- final IllegalArgumentException iae = new IllegalArgumentException
- ("Error setting property '" + name +
- "', exception - " + t);
- BeanUtils.initCause(iae, t);
- throw iae;
- }
-
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultBeanIntrospector.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultBeanIntrospector.java
deleted file mode 100644
index 8483f9fde..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultBeanIntrospector.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.beans.BeanInfo;
-import java.beans.IndexedPropertyDescriptor;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
- * The default {@link BeanIntrospector} implementation.
- *
- *
- * This class implements a default bean introspection algorithm based on the JDK
- * classes in the {@code java.beans} package. It discovers properties
- * conforming to the Java Beans specification.
- *
- *
- * This class is a singleton. The single instance can be obtained using the
- * {@code INSTANCE} field. It does not define any state and thus can be
- * shared by arbitrary clients. {@link PropertyUtils} per default uses this
- * instance as its only {@code BeanIntrospector} object.
- *
- *
- * @since 1.9
- */
-public class DefaultBeanIntrospector implements BeanIntrospector {
- /** The singleton instance of this class. */
- public static final BeanIntrospector INSTANCE = new DefaultBeanIntrospector();
-
- /** Constant for argument types of a method that expects no arguments. */
- private static final Class>[] EMPTY_CLASS_PARAMETERS = new Class[0];
-
- /** Constant for arguments types of a method that expects a list argument. */
- private static final Class>[] LIST_CLASS_PARAMETER = new Class[] { java.util.List.class };
-
- /** Log instance */
- private final Log log = LogFactory.getLog(getClass());
-
- /**
- * Private constructor so that no instances can be created.
- */
- private DefaultBeanIntrospector() {
- }
-
- /**
- * Performs introspection of a specific Java class. This implementation uses
- * the {@code java.beans.Introspector.getBeanInfo()} method to obtain
- * all property descriptors for the current class and adds them to the
- * passed in introspection context.
- *
- * @param icontext the introspection context
- */
- @Override
- public void introspect(final IntrospectionContext icontext) {
- BeanInfo beanInfo = null;
- try {
- beanInfo = Introspector.getBeanInfo(icontext.getTargetClass());
- } catch (final IntrospectionException e) {
- // no descriptors are added to the context
- log.error(
- "Error when inspecting class " + icontext.getTargetClass(),
- e);
- return;
- }
-
- PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
- if (descriptors == null) {
- descriptors = new PropertyDescriptor[0];
- }
-
- handleIndexedPropertyDescriptors(icontext.getTargetClass(),
- descriptors);
- icontext.addPropertyDescriptors(descriptors);
- }
-
- /**
- * This method fixes an issue where IndexedPropertyDescriptor behaves
- * differently in different versions of the JDK for 'indexed' properties
- * which use java.util.List (rather than an array). It implements a
- * workaround for Bug 28358. If you have a Bean with the following
- * getters/setters for an indexed property:
- *
- *
- * public List getFoo()
- * public Object getFoo(int index)
- * public void setFoo(List foo)
- * public void setFoo(int index, Object foo)
- *
- *
- * then the IndexedPropertyDescriptor's getReadMethod() and getWriteMethod()
- * behave as follows:
- *
- *
JDK 1.3.1_04: returns valid Method objects from these methods.
- *
JDK 1.4.2_05: returns null from these methods.
- *
- *
- * @param beanClass the current class to be inspected
- * @param descriptors the array with property descriptors
- */
- private void handleIndexedPropertyDescriptors(final Class> beanClass,
- final PropertyDescriptor[] descriptors) {
- for (final PropertyDescriptor pd : descriptors) {
- if (pd instanceof IndexedPropertyDescriptor) {
- final IndexedPropertyDescriptor descriptor = (IndexedPropertyDescriptor) pd;
- final String propName = descriptor.getName().substring(0, 1)
- .toUpperCase()
- + descriptor.getName().substring(1);
-
- if (descriptor.getReadMethod() == null) {
- final String methodName = descriptor.getIndexedReadMethod() != null ? descriptor
- .getIndexedReadMethod().getName() : "get"
- + propName;
- final Method readMethod = MethodUtils
- .getMatchingAccessibleMethod(beanClass, methodName,
- EMPTY_CLASS_PARAMETERS);
- if (readMethod != null) {
- try {
- descriptor.setReadMethod(readMethod);
- } catch (final Exception e) {
- log.error(
- "Error setting indexed property read method",
- e);
- }
- }
- }
- if (descriptor.getWriteMethod() == null) {
- final String methodName = descriptor.getIndexedWriteMethod() != null ? descriptor
- .getIndexedWriteMethod().getName() : "set"
- + propName;
- Method writeMethod = MethodUtils
- .getMatchingAccessibleMethod(beanClass, methodName,
- LIST_CLASS_PARAMETER);
- if (writeMethod == null) {
- for (final Method m : beanClass.getMethods()) {
- if (m.getName().equals(methodName)) {
- final Class>[] parameterTypes = m.getParameterTypes();
- if (parameterTypes.length == 1
- && List.class
- .isAssignableFrom(parameterTypes[0])) {
- writeMethod = m;
- break;
- }
- }
- }
- }
- if (writeMethod != null) {
- try {
- descriptor.setWriteMethod(writeMethod);
- } catch (final Exception e) {
- log.error(
- "Error setting indexed property write method",
- e);
- }
- }
- }
- }
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultIntrospectionContext.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultIntrospectionContext.java
deleted file mode 100644
index 9b56567ee..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultIntrospectionContext.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.beans.PropertyDescriptor;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- *
- * An implementation of the {@code IntrospectionContext} interface used by
- * {@link PropertyUtilsBean} when doing introspection of a bean class.
- *
- *
- * This class implements the methods required by the
- * {@code IntrospectionContext} interface in a straight-forward manner
- * based on a map. It is used internally only. It is not thread-safe.
- *
- *
- * @since 1.9
- */
-class DefaultIntrospectionContext implements IntrospectionContext {
- /** Constant for an empty array of property descriptors. */
- private static final PropertyDescriptor[] EMPTY_DESCRIPTORS = new PropertyDescriptor[0];
-
- /** The current class for introspection. */
- private final Class> currentClass;
-
- /** A map for storing the already added property descriptors. */
- private final Map descriptors;
-
- /**
- *
- * Creates a new instance of {@code DefaultIntrospectionContext} and sets
- * the current class for introspection.
- *
- * @param cls the current class
- */
- public DefaultIntrospectionContext(final Class> cls) {
- currentClass = cls;
- descriptors = new HashMap<>();
- }
-
- @Override
- public Class> getTargetClass() {
- return currentClass;
- }
-
- @Override
- public void addPropertyDescriptor(final PropertyDescriptor desc) {
- if (desc == null) {
- throw new IllegalArgumentException(
- "Property descriptor must not be null!");
- }
- descriptors.put(desc.getName(), desc);
- }
-
- @Override
- public void addPropertyDescriptors(final PropertyDescriptor[] descs) {
- if (descs == null) {
- throw new IllegalArgumentException(
- "Array with descriptors must not be null!");
- }
-
- for (final PropertyDescriptor desc : descs) {
- addPropertyDescriptor(desc);
- }
- }
-
- @Override
- public boolean hasProperty(final String name) {
- return descriptors.containsKey(name);
- }
-
- @Override
- public PropertyDescriptor getPropertyDescriptor(final String name) {
- return descriptors.get(name);
- }
-
- @Override
- public void removePropertyDescriptor(final String name) {
- descriptors.remove(name);
- }
-
- @Override
- public Set propertyNames() {
- return descriptors.keySet();
- }
-
- /**
- * Returns an array with all descriptors added to this context. This method
- * is used to obtain the results of introspection.
- *
- * @return an array with all known property descriptors
- */
- public PropertyDescriptor[] getPropertyDescriptors() {
- return descriptors.values().toArray(EMPTY_DESCRIPTORS);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBean.java
deleted file mode 100644
index c7ec3b498..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBean.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- *
A DynaBean is a Java object that supports properties
- * whose names and data types, as well as values, may be dynamically modified.
- * To the maximum degree feasible, other components of the BeanUtils package
- * will recognize such beans and treat them as standard JavaBeans for the
- * purpose of retrieving and setting property values.
- *
- */
-
-public interface DynaBean {
-
- /**
- * Does the specified mapped property contain a value for the specified
- * key value?
- *
- * @param name Name of the property to check
- * @param key Name of the key to check
- * @return {@code true} if the mapped property contains a value for
- * the specified key, otherwise {@code false}
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- boolean contains(String name, String key);
-
- /**
- * Return the value of a simple property with the specified name.
- *
- * @param name Name of the property whose value is to be retrieved
- * @return The property's value
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- Object get(String name);
-
- /**
- * Return the value of an indexed property with the specified name.
- *
- * @param name Name of the property whose value is to be retrieved
- * @param index Index of the value to be retrieved
- * @return The indexed property's value
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not indexed
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the range of the underlying property
- * @throws NullPointerException if no array or List has been
- * initialized for this property
- */
- Object get(String name, int index);
-
- /**
- * Return the value of a mapped property with the specified name,
- * or {@code null} if there is no value for the specified key.
- *
- * @param name Name of the property whose value is to be retrieved
- * @param key Key of the value to be retrieved
- * @return The mapped property's value
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not mapped
- */
- Object get(String name, String key);
-
- /**
- * Return the {@code DynaClass} instance that describes the set of
- * properties available for this DynaBean.
- *
- * @return The associated DynaClass
- */
- DynaClass getDynaClass();
-
- /**
- * Remove any existing value for the specified key on the
- * specified mapped property.
- *
- * @param name Name of the property for which a value is to
- * be removed
- * @param key Key of the value to be removed
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- void remove(String name, String key);
-
- /**
- * Set the value of a simple property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws NullPointerException if an attempt is made to set a
- * primitive property to null
- */
- void set(String name, Object value);
-
- /**
- * Set the value of an indexed property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param index Index of the property to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not indexed
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the range of the underlying property
- */
- void set(String name, int index, Object value);
-
- /**
- * Set the value of a mapped property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param key Key of the property to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not mapped
- */
- void set(String name, String key, Object value);
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBeanPropertyMapDecorator.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBeanPropertyMapDecorator.java
deleted file mode 100644
index 63c2e7606..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBeanPropertyMapDecorator.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-/**
- *
Decorates a {@link DynaBean} to provide {@code Map} behavior.
- *
- *
The motivation for this implementation is to provide access to {@link DynaBean}
- * properties in technologies that are unaware of BeanUtils and {@link DynaBean}s -
- * such as the expression languages of JSTL and JSF.
- *
- *
This can be achieved either by wrapping the {@link DynaBean} prior to
- * providing it to the technology to process or by providing a {@code Map}
- * accessor method on the DynaBean implementation:
- *
- * public Map<String, Object> getMap() {
- * return new DynaBeanPropertyMapDecorator(this);
- * }
- *
- *
This, for example, could be used in JSTL in the following way to access
- * a DynaBean's {@code fooProperty}:
- *
{@code ${myDynaBean.map.fooProperty}}
- *
- *
Usage
- *
- *
To decorate a {@link DynaBean} simply instantiate this class with the
- * target {@link DynaBean}:
- *
- *
{@code Map<String, Object> fooMap = new DynaBeanPropertyMapDecorator(fooDynaBean);}
- *
- *
The above example creates a read only {@code Map}.
- * To create a {@code Map} which can be modified, construct a
- * {@code DynaBeanPropertyMapDecorator} with the read only
- * attribute set to {@code false}:
- *
- *
Map<String, Object> fooMap =
- * new DynaBeanPropertyMapDecorator(fooDynaBean, false);
- *
- *
Limitations
- *
In this implementation the {@code entrySet()
, keySet()}
- * and {@code values()} methods create an unmodifiable
- * {@code Set and it does not support the Map's clear()}
- * and {@code remove()} operations.
- *
- * @since BeanUtils 1.9.0
- */
-public class DynaBeanPropertyMapDecorator extends BaseDynaBeanMapDecorator {
- /**
- * Construct a Map for the specified {@link DynaBean}.
- *
- * @param dynaBean The dyna bean being decorated
- * @param readOnly {@code true} if the Map is read only
- * otherwise {@code false}
- * @throws IllegalArgumentException if the {@link DynaBean} is null.
- */
- public DynaBeanPropertyMapDecorator(final DynaBean dynaBean, final boolean readOnly) {
- super(dynaBean, readOnly);
- }
-
- /**
- * Constructs a read only Map for the specified
- * {@link DynaBean}.
- *
- * @param dynaBean The dyna bean being decorated
- * @throws IllegalArgumentException if the {@link DynaBean} is null.
- */
- public DynaBeanPropertyMapDecorator(final DynaBean dynaBean) {
- super(dynaBean);
- }
-
- @Override
- protected String convertKey(final String propertyName) {
- return propertyName;
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaClass.java
deleted file mode 100644
index 41336ccd9..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaClass.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-/**
- *
A DynaClass is a simulation of the functionality of
- * {@code java.lang.Class} for classes implementing the
- * {@code DynaBean} interface. DynaBean instances that share the same
- * DynaClass all have the same set of available properties, along with any
- * associated data types, read-only states, and write-only states.
- *
- */
-
-public interface DynaClass {
-
- /**
- * Returns the name of this DynaClass (analogous to the
- * {@code getName()} method of {@code java.lang.Class}, which
- * allows the same {@code DynaClass} implementation class to support
- * different dynamic classes, with different sets of properties.
- *
- * @return the name of the DynaClass
- */
- String getName();
-
- /**
- * Returns a property descriptor for the specified property, if it exists;
- * otherwise, return {@code null}.
- *
- * @param name Name of the dynamic property for which a descriptor
- * is requested
- * @return The descriptor for the specified property
- *
- * @throws IllegalArgumentException if no property name is specified
- */
- DynaProperty getDynaProperty(String name);
-
- /**
- *
Returns an array of {@code PropertyDescriptor} for the properties
- * currently defined in this DynaClass. If no properties are defined, a
- * zero-length array will be returned.
- *
- *
FIXME - Should we really be implementing
- * {@code getBeanInfo()} instead, which returns property descriptors
- * and a bunch of other stuff?
- *
- * @return the set of properties for this DynaClass
- */
- DynaProperty[] getDynaProperties();
-
- /**
- * Instantiates and return a new DynaBean instance, associated
- * with this DynaClass.
- *
- * @return A new {@code DynaBean} instance
- *
- * @throws IllegalAccessException if the Class or the appropriate
- * constructor is not accessible
- * @throws InstantiationException if this Class represents an abstract
- * class, an array class, a primitive type, or void; or if instantiation
- * fails for some other reason
- */
- DynaBean newInstance()
- throws IllegalAccessException, InstantiationException;
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaProperty.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaProperty.java
deleted file mode 100644
index 2519e00dd..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaProperty.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.io.StreamCorruptedException;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-/**
- *
The metadata describing an individual property of a DynaBean.
- *
- *
The meta contains an optional content type property ({@link #getContentType})
- * for use by mapped and iterated properties.
- * A mapped or iterated property may choose to indicate the type it expects.
- * The DynaBean implementation may choose to enforce this type on its entries.
- * Alternatively, an implementation may choose to ignore this property.
- * All keys for maps must be of type String so no meta data is needed for map keys.
- *
- */
-
-public class DynaProperty implements Serializable {
-
-
-
- private static final long serialVersionUID = -3084907613499830175L;
- /*
- * There are issues with serializing primitive class types on certain JVM versions
- * (including java 1.3).
- * This class uses a custom serialization implementation that writes an integer
- * for these primitive class.
- * This list of constants are the ones used in serialization.
- * If these values are changed, then older versions will no longer be read correctly
- */
- private static final int BOOLEAN_TYPE = 1;
- private static final int BYTE_TYPE = 2;
- private static final int CHAR_TYPE = 3;
- private static final int DOUBLE_TYPE = 4;
- private static final int FLOAT_TYPE = 5;
- private static final int INT_TYPE = 6;
- private static final int LONG_TYPE = 7;
- private static final int SHORT_TYPE = 8;
-
-
-
- /**
- * Construct a property that accepts any data type.
- *
- * @param name Name of the property being described
- */
- public DynaProperty(final String name) {
-
- this(name, Object.class);
-
- }
-
- /**
- * Construct a property of the specified data type.
- *
- * @param name Name of the property being described
- * @param type Java class representing the property data type
- */
- public DynaProperty(final String name, final Class> type) {
-
- super();
- this.name = name;
- this.type = type;
- if (type != null && type.isArray()) {
- this.contentType = type.getComponentType();
- }
-
- }
-
- /**
- * Construct an indexed or mapped {@code DynaProperty} that supports (pseudo)-introspection
- * of the content type.
- *
- * @param name Name of the property being described
- * @param type Java class representing the property data type
- * @param contentType Class that all indexed or mapped elements are instances of
- */
- public DynaProperty(final String name, final Class> type, final Class> contentType) {
-
- super();
- this.name = name;
- this.type = type;
- this.contentType = contentType;
-
- }
-
-
-
- /** Property name */
- protected String name = null;
- /**
- * Get the name of this property.
- * @return the name of the property
- */
- public String getName() {
- return this.name;
- }
-
- /** Property type */
- protected transient Class> type = null;
- /**
- *
Gets the Java class representing the data type of the underlying property
- * values.
- *
- *
There are issues with serializing primitive class types on certain JVM versions
- * (including java 1.3).
- * Therefore, this field must not be serialized using the standard methods.
- *
- *
Please leave this field as {@code transient}
- *
- * @return the property type
- */
- public Class> getType() {
- return this.type;
- }
-
- /** The (optional) type of content elements for indexed {@code DynaProperty} */
- protected transient Class> contentType;
- /**
- * Gets the (optional) type of the indexed content for {@code DynaProperty}'s
- * that support this feature.
- *
- *
There are issues with serializing primitive class types on certain JVM versions
- * (including java 1.3).
- * Therefore, this field must not be serialized using the standard methods.
- *
- * @return the Class for the content type if this is an indexed {@code DynaProperty}
- * and this feature is supported. Otherwise null.
- */
- public Class> getContentType() {
- return contentType;
- }
-
-
-
- /**
- * Does this property represent an indexed value (ie an array or List)?
- *
- * @return {@code true} if the property is indexed (i.e. is a List or
- * array), otherwise {@code false}
- */
- public boolean isIndexed() {
-
- if (type == null) {
- return false;
- } else if (type.isArray() || List.class.isAssignableFrom(type)) {
- return true;
- } else {
- return false;
- }
-
- }
-
- /**
- * Does this property represent a mapped value (ie a Map)?
- *
- * @return {@code true} if the property is a Map
- * otherwise {@code false}
- */
- public boolean isMapped() {
-
- if (type == null) {
- return false;
- }
- return Map.class.isAssignableFrom(type);
-
- }
-
- /**
- * Checks this instance against the specified Object for equality. Overrides the
- * default reference test for equality provided by {@link java.lang.Object#equals(Object)}
- * @param obj The object to compare to
- * @return {@code true} if object is a dyna property with the same name
- * type and content type, otherwise {@code false}
- * @since 1.8.0
- */
- @Override
- public boolean equals(final Object obj) {
-
- boolean result = false;
-
- result = obj == this;
-
- if (!result && obj instanceof DynaProperty) {
- final DynaProperty that = (DynaProperty) obj;
- result =
- (Objects.equals(this.name, that.name)) &&
- (Objects.equals(this.type, that.type)) &&
- (Objects.equals(this.contentType, that.contentType));
- }
-
- return result;
- }
-
- /**
- * @return the hashcode for this dyna property
- * @see java.lang.Object#hashCode
- * @since 1.8.0
- */
- @Override
- public int hashCode() {
-
- int result = 1;
-
- result = result * 31 + (name == null ? 0 : name.hashCode());
- result = result * 31 + (type == null ? 0 : type.hashCode());
- result = result * 31 + (contentType == null ? 0 : contentType.hashCode());
-
- return result;
- }
-
- /**
- * Return a String representation of this Object.
- * @return a String representation of the dyna property
- */
- @Override
- public String toString() {
-
- final StringBuilder sb = new StringBuilder("DynaProperty[name=");
- sb.append(this.name);
- sb.append(",type=");
- sb.append(this.type);
- if (isMapped() || isIndexed()) {
- sb.append(" <").append(this.contentType).append(">");
- }
- sb.append("]");
- return sb.toString();
-
- }
-
-
-
- /**
- * Writes this object safely.
- * There are issues with serializing primitive class types on certain JVM versions
- * (including java 1.3).
- * This method provides a workaround.
- *
- * @param out {@link ObjectOutputStream} to write object to
- * @throws IOException if the object can't be written
- */
- private void writeObject(final ObjectOutputStream out) throws IOException {
-
- writeAnyClass(this.type,out);
-
- if (isMapped() || isIndexed()) {
- writeAnyClass(this.contentType,out);
- }
-
- // write out other values
- out.defaultWriteObject();
- }
-
- /**
- * Write a class using safe encoding to workaround java 1.3 serialization bug.
- */
- private void writeAnyClass(final Class> clazz, final ObjectOutputStream out) throws IOException {
- // safely write out any class
- int primitiveType = 0;
- if (Boolean.TYPE.equals(clazz)) {
- primitiveType = BOOLEAN_TYPE;
- } else if (Byte.TYPE.equals(clazz)) {
- primitiveType = BYTE_TYPE;
- } else if (Character.TYPE.equals(clazz)) {
- primitiveType = CHAR_TYPE;
- } else if (Double.TYPE.equals(clazz)) {
- primitiveType = DOUBLE_TYPE;
- } else if (Float.TYPE.equals(clazz)) {
- primitiveType = FLOAT_TYPE;
- } else if (Integer.TYPE.equals(clazz)) {
- primitiveType = INT_TYPE;
- } else if (Long.TYPE.equals(clazz)) {
- primitiveType = LONG_TYPE;
- } else if (Short.TYPE.equals(clazz)) {
- primitiveType = SHORT_TYPE;
- }
-
- if (primitiveType == 0) {
- // then it's not a primitive type
- out.writeBoolean(false);
- out.writeObject(clazz);
- } else {
- // we'll write out a constant instead
- out.writeBoolean(true);
- out.writeInt(primitiveType);
- }
- }
-
- /**
- * Reads field values for this object safely.
- * There are issues with serializing primitive class types on certain JVM versions
- * (including java 1.3).
- * This method provides a workaround.
- *
- * @param in {@link ObjectInputStream} to read object from
- * @throws StreamCorruptedException when the stream data values are outside expected range
- * @throws IOException if the input stream can't be read
- * @throws ClassNotFoundException When trying to read an object of class that is not on the classpath
- */
- private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
-
- this.type = readAnyClass(in);
-
- if (isMapped() || isIndexed()) {
- this.contentType = readAnyClass(in);
- }
-
- // read other values
- in.defaultReadObject();
- }
-
- /**
- * Reads a class using safe encoding to workaround java 1.3 serialization bug.
- */
- private Class> readAnyClass(final ObjectInputStream in) throws IOException, ClassNotFoundException {
- // read back type class safely
- if (in.readBoolean()) {
- // it's a type constant
- switch (in.readInt()) {
-
- case BOOLEAN_TYPE: return Boolean.TYPE;
- case BYTE_TYPE: return Byte.TYPE;
- case CHAR_TYPE: return Character.TYPE;
- case DOUBLE_TYPE: return Double.TYPE;
- case FLOAT_TYPE: return Float.TYPE;
- case INT_TYPE: return Integer.TYPE;
- case LONG_TYPE: return Long.TYPE;
- case SHORT_TYPE: return Short.TYPE;
- default:
- // something's gone wrong
- throw new StreamCorruptedException(
- "Invalid primitive type. "
- + "Check version of beanutils used to serialize is compatible.");
-
- }
-
- }
- // it's another class
- return (Class>) in.readObject();
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/FluentPropertyBeanIntrospector.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/FluentPropertyBeanIntrospector.java
deleted file mode 100644
index 6bfa2bef5..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/FluentPropertyBeanIntrospector.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-import java.util.Locale;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
- * An implementation of the {@code BeanIntrospector} interface which can
- * detect write methods for properties used in fluent API scenario.
- *
- *
- * A fluent API allows setting multiple properties using a single
- * statement by supporting so-called method chaining: Methods for
- * setting a property value do not return void, but an object which can
- * be called for setting another property. An example of such a fluent API could
- * look as follows:
- *
Per default, {@code PropertyUtils} does not detect methods like this
- * because, having a non-void return type, they violate the Java Beans
- * specification.
- *
- *
- * This class is more tolerant with regards to the return type of a set method.
- * It basically iterates over all methods of a class and filters them for a
- * configurable prefix (the default prefix is {@code set}). It then
- * generates corresponding {@code PropertyDescriptor} objects for the
- * methods found which use these methods as write methods.
- *
- *
- * An instance of this class is intended to collaborate with a
- * {@link DefaultBeanIntrospector} object. So best results are achieved by
- * adding this instance as custom {@code BeanIntrospector} after the
- * {@code DefaultBeanIntrospector} object. Then default introspection finds
- * read-only properties because it does not detect the write methods with a
- * non-void return type. {@code FluentPropertyBeanIntrospector}
- * completes the descriptors for these properties by setting the correct write
- * method.
- *
- *
- * @since 1.9
- */
-public class FluentPropertyBeanIntrospector implements BeanIntrospector {
- /** The default prefix for write methods. */
- public static final String DEFAULT_WRITE_METHOD_PREFIX = "set";
-
- /** The logger. */
- private final Log log = LogFactory.getLog(getClass());
-
- /** The prefix of write methods to search for. */
- private final String writeMethodPrefix;
-
- /**
- *
- * Creates a new instance of {@code FluentPropertyBeanIntrospector} and
- * initializes it with the prefix for write methods used by the classes to
- * be inspected.
- *
- * @param writePrefix the prefix for write methods (must not be null)
- * @throws IllegalArgumentException if the prefix is null
- */
- public FluentPropertyBeanIntrospector(final String writePrefix) {
- if (writePrefix == null) {
- throw new IllegalArgumentException(
- "Prefix for write methods must not be null!");
- }
- writeMethodPrefix = writePrefix;
- }
-
- /**
- *
- * Creates a new instance of {@code FluentPropertyBeanIntrospector} and
- * sets the default prefix for write methods.
- */
- public FluentPropertyBeanIntrospector() {
- this(DEFAULT_WRITE_METHOD_PREFIX);
- }
-
- /**
- * Returns the prefix for write methods this instance scans for.
- *
- * @return the prefix for write methods
- */
- public String getWriteMethodPrefix() {
- return writeMethodPrefix;
- }
-
- /**
- * Performs introspection. This method scans the current class's methods for
- * property write methods which have not been discovered by default
- * introspection.
- *
- * @param icontext the introspection context
- * @throws IntrospectionException if an error occurs
- */
- @Override
- public void introspect(final IntrospectionContext icontext)
- throws IntrospectionException {
- for (final Method m : icontext.getTargetClass().getMethods()) {
- if (m.getName().startsWith(getWriteMethodPrefix())) {
- final String propertyName = propertyName(m);
- final PropertyDescriptor pd = icontext
- .getPropertyDescriptor(propertyName);
- try {
- if (pd == null) {
- icontext.addPropertyDescriptor(createFluentPropertyDescritor(
- m, propertyName));
- } else if (pd.getWriteMethod() == null) {
- pd.setWriteMethod(m);
- }
- } catch (final IntrospectionException e) {
- log.debug("Error when creating PropertyDescriptor for " + m
- + "! Ignoring this property.");
- log.debug("Exception is:", e);
- }
- }
- }
- }
-
- /**
- * Derives the name of a property from the given set method.
- *
- * @param m the method
- * @return the corresponding property name
- */
- private String propertyName(final Method m) {
- final String methodName = m.getName().substring(
- getWriteMethodPrefix().length());
- return methodName.length() > 1 ? Introspector.decapitalize(methodName) : methodName
- .toLowerCase(Locale.ENGLISH);
- }
-
- /**
- * Creates a property descriptor for a fluent API property.
- *
- * @param m the set method for the fluent API property
- * @param propertyName the name of the corresponding property
- * @return the descriptor
- * @throws IntrospectionException if an error occurs
- */
- private PropertyDescriptor createFluentPropertyDescritor(final Method m,
- final String propertyName) throws IntrospectionException {
- return new PropertyDescriptor(propertyName(m), null, m);
- }
-}
\ No newline at end of file
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/IntrospectionContext.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/IntrospectionContext.java
deleted file mode 100644
index 858dd52a3..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/IntrospectionContext.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.beans.PropertyDescriptor;
-import java.util.Set;
-
-/**
- *
- * A context interface used during introspection for querying and setting
- * property descriptors.
- *
- *
- * An implementation of this interface is passed to {@link BeanIntrospector}
- * objects during processing of a bean class. It allows the
- * {@code BeanIntrospector} to deliver descriptors for properties it has
- * detected. It is also possible to find out which properties have already been
- * found by another {@code BeanIntrospector}; this allows multiple
- * {@code BeanIntrospector} instances to collaborate.
- *
- *
- * @since 1.9
- */
-public interface IntrospectionContext {
- /**
- * Returns the class that is subject of introspection.
- *
- * @return the current class
- */
- Class> getTargetClass();
-
- /**
- * Adds the given property descriptor to this context. This method is called
- * by a {@code BeanIntrospector} during introspection for each detected
- * property. If this context already contains a descriptor for the affected
- * property, it is overridden.
- *
- * @param desc the property descriptor
- */
- void addPropertyDescriptor(PropertyDescriptor desc);
-
- /**
- * Adds an array of property descriptors to this context. Using this method
- * multiple descriptors can be added at once.
- *
- * @param descriptors the array of descriptors to be added
- */
- void addPropertyDescriptors(PropertyDescriptor[] descriptors);
-
- /**
- * Tests whether a descriptor for the property with the given name is
- * already contained in this context. This method can be used for instance
- * to prevent that an already existing property descriptor is overridden.
- *
- * @param name the name of the property in question
- * @return true if a descriptor for this property has already been
- * added, false otherwise
- */
- boolean hasProperty(String name);
-
- /**
- * Returns the descriptor for the property with the given name or
- * null if this property is unknown.
- *
- * @param name the name of the property in question
- * @return the descriptor for this property or null if this property
- * is unknown
- */
- PropertyDescriptor getPropertyDescriptor(String name);
-
- /**
- * Removes the descriptor for the property with the given name.
- *
- * @param name the name of the affected property
- */
- void removePropertyDescriptor(String name);
-
- /**
- * Returns a set with the names of all properties known to this context.
- *
- * @return a set with the known property names
- */
- Set propertyNames();
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/JDBCDynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/JDBCDynaClass.java
deleted file mode 100644
index b3583cfd3..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/JDBCDynaClass.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.io.Serializable;
-import java.sql.Date;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- *
Provides common logic for JDBC implementations of {@link DynaClass}.
- *
- */
-
-abstract class JDBCDynaClass implements DynaClass, Serializable {
-
- private static final long serialVersionUID = 1L;
-
-
-
- /**
- *
Flag defining whether column names should be lower cased when
- * converted to property names.
The set of dynamic properties that are part of this
- * {@link DynaClass}, keyed by the property name. Individual descriptor
- * instances will be the same instances as those in the
- * {@code properties} list.
- */
- protected Map propertiesMap = new HashMap<>();
-
- /**
- * Cross Reference for column name --> dyna property name
- * (needed when lowerCase option is true)
- */
- private Map columnNameXref;
-
-
-
- /**
- *
Return the name of this DynaClass (analogous to the
- * {@code getName()
method of java.lang.Class}, which
- * allows the same {@code DynaClass} implementation class to support
- * different dynamic classes, with different sets of properties.
- */
- @Override
- public String getName() {
-
- return this.getClass().getName();
-
- }
-
- /**
- *
Return a property descriptor for the specified property, if it
- * exists; otherwise, return {@code null}.
- *
- * @param name Name of the dynamic property for which a descriptor
- * is requested
- *
- * @throws IllegalArgumentException if no property name is specified
- */
- @Override
- public DynaProperty getDynaProperty(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("No property name specified");
- }
- return propertiesMap.get(name);
-
- }
-
- /**
- *
Return an array of {@code PropertyDescriptor} for the properties
- * currently defined in this DynaClass. If no properties are defined, a
- * zero-length array will be returned.
Instantiate and return a new DynaBean instance, associated
- * with this DynaClass. NOTE - This operation is not
- * supported, and throws an exception.
- *
- * @throws IllegalAccessException if the Class or the appropriate
- * constructor is not accessible
- * @throws InstantiationException if this Class represents an abstract
- * class, an array class, a primitive type, or void; or if instantiation
- * fails for some other reason
- */
- @Override
- public DynaBean newInstance()
- throws IllegalAccessException, InstantiationException {
-
- throw new UnsupportedOperationException("newInstance() not supported");
-
- }
-
- /**
- * Set whether the column label or name should be used for the property name.
- *
- * @param useColumnLabel true if the column label should be used, otherwise false
- */
- public void setUseColumnLabel(final boolean useColumnLabel) {
- this.useColumnLabel = useColumnLabel;
- }
-
- /**
- *
Loads and returns the {@code Class} of the given name.
- * By default, a load from the thread context class loader is attempted.
- * If there is no such class loader, the class loader used to load this
- * class will be utilized.
- *
- * @param className The name of the class to load
- * @return The loaded class
- * @throws SQLException if an exception was thrown trying to load
- * the specified class
- */
- protected Class> loadClass(final String className) throws SQLException {
-
- try {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- if (cl == null) {
- cl = this.getClass().getClassLoader();
- }
- // use Class.forName() - see BEANUTILS-327
- return Class.forName(className, false, cl);
- } catch (final Exception e) {
- throw new SQLException(
- "Cannot load column class '" + className + "': " + e);
- }
-
- }
-
- /**
- *
Factory method to create a new DynaProperty for the given index
- * into the result set metadata.
- *
- * @param metadata is the result set metadata
- * @param i is the column index in the metadata
- * @return the newly created DynaProperty instance
- * @throws SQLException If an error occurs accessing the SQL metadata
- */
- protected DynaProperty createDynaProperty(
- final ResultSetMetaData metadata,
- final int i)
- throws SQLException {
-
- String columnName = null;
- if (useColumnLabel) {
- columnName = metadata.getColumnLabel(i);
- }
- if (columnName == null || columnName.trim().length() == 0) {
- columnName = metadata.getColumnName(i);
- }
- final String name = lowerCase ? columnName.toLowerCase() : columnName;
- if (!name.equals(columnName)) {
- if (columnNameXref == null) {
- columnNameXref = new HashMap<>();
- }
- columnNameXref.put(name, columnName);
- }
- String className = null;
- try {
- final int sqlType = metadata.getColumnType(i);
- switch (sqlType) {
- case java.sql.Types.DATE:
- return new DynaProperty(name, java.sql.Date.class);
- case java.sql.Types.TIMESTAMP:
- return new DynaProperty(name, java.sql.Timestamp.class);
- case java.sql.Types.TIME:
- return new DynaProperty(name, java.sql.Time.class);
- default:
- className = metadata.getColumnClassName(i);
- }
- } catch (final SQLException e) {
- // this is a patch for HsqlDb to ignore exceptions
- // thrown by its metadata implementation
- }
-
- // Default to Object type if no class name could be retrieved
- // from the metadata
- Class> clazz = Object.class;
- if (className != null) {
- clazz = loadClass(className);
- }
- return new DynaProperty(name, clazz);
-
- }
-
- /**
- *
Introspect the metadata associated with our result set, and populate
- * the {@code properties
and propertiesMap} instance
- * variables.
- *
- * @param resultSet The {@code resultSet} whose metadata is to
- * be introspected
- *
- * @throws SQLException if an error is encountered processing the
- * result set metadata
- */
- protected void introspect(final ResultSet resultSet) throws SQLException {
-
- // Accumulate an ordered list of DynaProperties
- final List list = new ArrayList<>();
- final ResultSetMetaData metadata = resultSet.getMetaData();
- final int n = metadata.getColumnCount();
- for (int i = 1; i <= n; i++) { // JDBC is one-relative!
- final DynaProperty dynaProperty = createDynaProperty(metadata, i);
- if (dynaProperty != null) {
- list.add(dynaProperty);
- }
- }
-
- // Convert this list into the internal data structures we need
- properties =
- list.toArray(new DynaProperty[list.size()]);
- for (final DynaProperty property : properties) {
- propertiesMap.put(property.getName(), property);
- }
-
- }
-
- /**
- * Get a column value from a {@link ResultSet} for the specified name.
- *
- * @param resultSet The result set
- * @param name The property name
- * @return The value
- * @throws SQLException if an error occurs
- */
- protected Object getObject(final ResultSet resultSet, final String name) throws SQLException {
-
- final DynaProperty property = getDynaProperty(name);
- if (property == null) {
- throw new IllegalArgumentException("Invalid name '" + name + "'");
- }
- final String columnName = getColumnName(name);
- final Class> type = property.getType();
-
- // java.sql.Date
- if (type.equals(Date.class)) {
- return resultSet.getDate(columnName);
- }
-
- // java.sql.Timestamp
- if (type.equals(Timestamp.class)) {
- return resultSet.getTimestamp(columnName);
- }
-
- // java.sql.Time
- if (type.equals(Time.class)) {
- return resultSet.getTime(columnName);
- }
-
- return resultSet.getObject(columnName);
- }
-
- /**
- * Get the table column name for the specified property name.
- *
- * @param name The property name
- * @return The column name (which can be different if the lowerCase
- * option is used).
- */
- protected String getColumnName(final String name) {
- if (columnNameXref != null && columnNameXref.containsKey(name)) {
- return columnNameXref.get(name);
- }
- return name;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java
deleted file mode 100644
index 878968559..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java
+++ /dev/null
@@ -1,955 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.io.Serializable;
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
DynaBean which automatically adds properties to the {@code DynaClass}
- * and provides Lazy List and Lazy Map features.
- *
- *
DynaBeans deal with three types of properties - simple, indexed and mapped and
- * have the following {@code get()
and set()} methods for
- * each of these types:
- *
If the property doesn't exist, the {@code LazyDynaBean} will automatically add
- * a property with an {@code ArrayList
type to the DynaClass} when
- * the {@code set(name, index, value)} method is called.
- * It will also instantiate a new {@code ArrayList} and automatically grow
- * the {@code List} so that it is big enough to accommodate the index being set.
- * {@code ArrayList} is the default indexed property that LazyDynaBean uses but
- * this can be easily changed by overriding the {@code defaultIndexedProperty(name)}
- * method.
- *
- *
If the indexed property does exist in the {@code DynaClass} but is set to
- * {@code null
in the LazyDynaBean}, then it will instantiate a
- * new {@code List or Array} as specified by the property's type
- * in the {@code DynaClass and automatically grow the List}
- * or {@code Array} so that it is big enough to accommodate the index being set.
- *
- *
If the property doesn't exist, the {@code LazyDynaBean} will automatically add
- * a property with a {@code HashMap
type to the DynaClass} and
- * instantiate a new {@code HashMap} in the DynaBean when the
- * {@code set(name, key, value) method is called. HashMap} is the default
- * mapped property that LazyDynaBean uses but this can be easily changed by overriding
- * the {@code defaultMappedProperty(name)} method.
- *
- *
have a facility to restrict the DynaClass}
- * so that its properties cannot be modified. If the {@code MutableDynaClass} is
- * restricted then calling any of the {@code set()} methods for a property which
- * doesn't exist will result in a {@code IllegalArgumentException} being thrown.
- *
- * @see LazyDynaClass
- */
-public class LazyDynaBean implements DynaBean, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Commons Logging
- */
- private transient Log logger = LogFactory.getLog(LazyDynaBean.class);
-
- /** BigInteger Zero */
- protected static final BigInteger BigInteger_ZERO = new BigInteger("0");
- /** BigDecimal Zero */
- protected static final BigDecimal BigDecimal_ZERO = new BigDecimal("0");
- /** Character Space */
- protected static final Character Character_SPACE = Character.valueOf(' ');
- /** Byte Zero */
- protected static final Byte Byte_ZERO = Byte.valueOf((byte)0);
- /** Short Zero */
- protected static final Short Short_ZERO = Short.valueOf((short)0);
- /** Integer Zero */
- protected static final Integer Integer_ZERO = Integer.valueOf(0);
- /** Long Zero */
- protected static final Long Long_ZERO = Long.valueOf(0);
- /** Float Zero */
- protected static final Float Float_ZERO = Float.valueOf((byte)0);
- /** Double Zero */
- protected static final Double Double_ZERO = Double.valueOf((byte)0);
-
- /**
- * The {@code MutableDynaClass} "base class" that this DynaBean
- * is associated with.
- */
- protected Map values;
-
- /** Map decorator for this DynaBean */
- private transient Map mapDecorator;
-
- /**
- * The {@code MutableDynaClass} "base class" that this DynaBean
- * is associated with.
- */
- protected MutableDynaClass dynaClass;
-
-
-
- /**
- * Construct a new {@code LazyDynaBean with a LazyDynaClass} instance.
- */
- public LazyDynaBean() {
- this(new LazyDynaClass());
- }
-
- /**
- * Construct a new {@code LazyDynaBean with a LazyDynaClass} instance.
- *
- * @param name Name of this DynaBean class
- */
- public LazyDynaBean(final String name) {
- this(new LazyDynaClass(name));
- }
-
- /**
- * Construct a new {@code DynaBean} associated with the specified
- * {@code DynaClass instance - if its not a MutableDynaClass}
- * then a new {@code LazyDynaClass} is created and the properties copied.
- *
- * @param dynaClass The DynaClass we are associated with
- */
- public LazyDynaBean(final DynaClass dynaClass) {
-
- values = newMap();
-
- if (dynaClass instanceof MutableDynaClass) {
- this.dynaClass = (MutableDynaClass)dynaClass;
- } else {
- this.dynaClass = new LazyDynaClass(dynaClass.getName(), dynaClass.getDynaProperties());
- }
-
- }
-
-
-
- /**
- *
- * Return a Map representation of this DynaBean.
- *
- * This, for example, could be used in JSTL in the following way to access
- * a DynaBean's {@code fooProperty}:
- *
{@code ${myDynaBean.map.fooProperty}}
- *
- * @return a Map representation of this DynaBean
- */
- public Map getMap() {
- // cache the Map
- if (mapDecorator == null) {
- mapDecorator = new DynaBeanPropertyMapDecorator(this);
- }
- return mapDecorator;
- }
-
- /**
- *
Return the size of an indexed or mapped property.
- *
- * @param name Name of the property
- * @return The indexed or mapped property size
- * @throws IllegalArgumentException if no property name is specified
- */
- public int size(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("No property name specified");
- }
-
- final Object value = values.get(name);
- if (value == null) {
- return 0;
- }
-
- if (value instanceof Map) {
- return ((Map, ?>)value).size();
- }
-
- if (value instanceof List) {
- return ((List>)value).size();
- }
-
- if (value.getClass().isArray()) {
- return Array.getLength(value);
- }
-
- return 0;
-
- }
-
-
-
- /**
- * Does the specified mapped property contain a value for the specified
- * key value?
- *
- * @param name Name of the property to check
- * @param key Name of the key to check
- * @return {@code true} if the mapped property contains a value for
- * the specified key, otherwise {@code false}
- *
- * @throws IllegalArgumentException if no property name is specified
- */
- @Override
- public boolean contains(final String name, final String key) {
-
- if (name == null) {
- throw new IllegalArgumentException("No property name specified");
- }
-
- final Object value = values.get(name);
- if (value == null) {
- return false;
- }
-
- if (value instanceof Map) {
- return ((Map, ?>) value).containsKey(key);
- }
-
- return false;
-
- }
-
- /**
- *
Return the value of a simple property with the specified name.
- *
- *
N.B. Returns {@code null} if there is no property
- * of the specified name.
- *
- * @param name Name of the property whose value is to be retrieved.
- * @return The property's value
- * @throws IllegalArgumentException if no property name is specified
- */
- @Override
- public Object get(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("No property name specified");
- }
-
- // Value found
- Object value = values.get(name);
- if (value != null) {
- return value;
- }
-
- // Property doesn't exist
- if (!isDynaProperty(name)) {
- return null;
- }
-
- // Property doesn't exist
- value = createProperty(name, dynaClass.getDynaProperty(name).getType());
-
- if (value != null) {
- set(name, value);
- }
-
- return value;
-
- }
-
- /**
- *
Return the value of an indexed property with the specified name.
- *
- *
N.B. Returns {@code null} if there is no 'indexed'
- * property of the specified name.
- *
- * @param name Name of the property whose value is to be retrieved
- * @param index Index of the value to be retrieved
- * @return The indexed property's value
- *
- * @throws IllegalArgumentException if the specified property
- * exists, but is not indexed
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the range of the underlying property
- */
- @Override
- public Object get(final String name, final int index) {
-
- // If its not a property, then create default indexed property
- if (!isDynaProperty(name)) {
- set(name, defaultIndexedProperty(name));
- }
-
- // Get the indexed property
- Object indexedProperty = get(name);
-
- // Check that the property is indexed
- if (!dynaClass.getDynaProperty(name).isIndexed()) {
- throw new IllegalArgumentException
- ("Non-indexed property for '" + name + "[" + index + "]' "
- + dynaClass.getDynaProperty(name).getName());
- }
-
- // Grow indexed property to appropriate size
- indexedProperty = growIndexedProperty(name, indexedProperty, index);
-
- // Return the indexed value
- if (indexedProperty.getClass().isArray()) {
- return Array.get(indexedProperty, index);
- } else if (indexedProperty instanceof List) {
- return ((List>)indexedProperty).get(index);
- } else {
- throw new IllegalArgumentException
- ("Non-indexed property for '" + name + "[" + index + "]' "
- + indexedProperty.getClass().getName());
- }
-
- }
-
- /**
- *
Return the value of a mapped property with the specified name.
- *
- *
N.B. Returns {@code null} if there is no 'mapped'
- * property of the specified name.
- *
- * @param name Name of the property whose value is to be retrieved
- * @param key Key of the value to be retrieved
- * @return The mapped property's value
- *
- * @throws IllegalArgumentException if the specified property
- * exists, but is not mapped
- */
- @Override
- public Object get(final String name, final String key) {
-
- // If its not a property, then create default mapped property
- if (!isDynaProperty(name)) {
- set(name, defaultMappedProperty(name));
- }
-
- // Get the mapped property
- final Object mappedProperty = get(name);
-
- // Check that the property is mapped
- if (!dynaClass.getDynaProperty(name).isMapped()) {
- throw new IllegalArgumentException
- ("Non-mapped property for '" + name + "(" + key + ")' "
- + dynaClass.getDynaProperty(name).getType().getName());
- }
-
- // Get the value from the Map
- if (mappedProperty instanceof Map) {
- return ((Map, ?>) mappedProperty).get(key);
- }
- throw new IllegalArgumentException
- ("Non-mapped property for '" + name + "(" + key + ")'"
- + mappedProperty.getClass().getName());
-
- }
-
- /**
- * Return the {@code DynaClass} instance that describes the set of
- * properties available for this DynaBean.
- *
- * @return The associated DynaClass
- */
- @Override
- public DynaClass getDynaClass() {
- return dynaClass;
- }
-
- /**
- * Remove any existing value for the specified key on the
- * specified mapped property.
- *
- * @param name Name of the property for which a value is to
- * be removed
- * @param key Key of the value to be removed
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- @Override
- public void remove(final String name, final String key) {
-
- if (name == null) {
- throw new IllegalArgumentException("No property name specified");
- }
-
- final Object value = values.get(name);
- if (value == null) {
- return;
- }
-
- if (value instanceof Map) {
- ((Map, ?>) value).remove(key);
- } else {
- throw new IllegalArgumentException
- ("Non-mapped property for '" + name + "(" + key + ")'"
- + value.getClass().getName());
- }
-
- }
-
- /**
- * Set the value of a simple property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param value Value to which this property is to be set
- *
- * @throws IllegalArgumentException if this is not an existing property
- * name for our DynaClass and the MutableDynaClass is restricted
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws NullPointerException if an attempt is made to set a
- * primitive property to null
- */
- @Override
- public void set(final String name, final Object value) {
-
- // If the property doesn't exist, then add it
- if (!isDynaProperty(name)) {
-
- if (dynaClass.isRestricted()) {
- throw new IllegalArgumentException
- ("Invalid property name '" + name + "' (DynaClass is restricted)");
- }
- if (value == null) {
- dynaClass.add(name);
- } else {
- dynaClass.add(name, value.getClass());
- }
-
- }
-
- final DynaProperty descriptor = dynaClass.getDynaProperty(name);
-
- if (value == null) {
- if (descriptor.getType().isPrimitive()) {
- throw new NullPointerException
- ("Primitive value for '" + name + "'");
- }
- } else if (!isAssignable(descriptor.getType(), value.getClass())) {
- throw new ConversionException
- ("Cannot assign value of type '" +
- value.getClass().getName() +
- "' to property '" + name + "' of type '" +
- descriptor.getType().getName() + "'");
- }
-
- // Set the property's value
- values.put(name, value);
-
- }
-
- /**
- * Set the value of an indexed property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param index Index of the property to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not indexed
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the range of the underlying property
- */
- @Override
- public void set(final String name, final int index, final Object value) {
-
- // If its not a property, then create default indexed property
- if (!isDynaProperty(name)) {
- set(name, defaultIndexedProperty(name));
- }
-
- // Get the indexed property
- Object indexedProperty = get(name);
-
- // Check that the property is indexed
- if (!dynaClass.getDynaProperty(name).isIndexed()) {
- throw new IllegalArgumentException
- ("Non-indexed property for '" + name + "[" + index + "]'"
- + dynaClass.getDynaProperty(name).getType().getName());
- }
-
- // Grow indexed property to appropriate size
- indexedProperty = growIndexedProperty(name, indexedProperty, index);
-
- // Set the value in an array
- if (indexedProperty.getClass().isArray()) {
- Array.set(indexedProperty, index, value);
- } else if (indexedProperty instanceof List) {
- @SuppressWarnings("unchecked")
- final
- // Indexed properties are stored in a List
- List values = (List) indexedProperty;
- values.set(index, value);
- } else {
- throw new IllegalArgumentException
- ("Non-indexed property for '" + name + "[" + index + "]' "
- + indexedProperty.getClass().getName());
- }
-
- }
-
- /**
- * Set the value of a mapped property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param key Key of the property to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not mapped
- */
- @Override
- public void set(final String name, final String key, final Object value) {
-
- // If the 'mapped' property doesn't exist, then add it
- if (!isDynaProperty(name)) {
- set(name, defaultMappedProperty(name));
- }
-
- // Get the mapped property
- final Object mappedProperty = get(name);
-
- // Check that the property is mapped
- if (!dynaClass.getDynaProperty(name).isMapped()) {
- throw new IllegalArgumentException
- ("Non-mapped property for '" + name + "(" + key + ")'"
- + dynaClass.getDynaProperty(name).getType().getName());
- }
-
- // Set the value in the Map
- @SuppressWarnings("unchecked")
- final
- // mapped properties are stored in a Map
- Map valuesMap = (Map) mappedProperty;
- valuesMap.put(key, value);
-
- }
-
-
-
- /**
- * Grow the size of an indexed property
- * @param name The name of the property
- * @param indexedProperty The current property value
- * @param index The indexed value to grow the property to (i.e. one less than
- * the required size)
- * @return The new property value (grown to the appropriate size)
- */
- protected Object growIndexedProperty(final String name, Object indexedProperty, final int index) {
-
- // Grow a List to the appropriate size
- if (indexedProperty instanceof List) {
-
- @SuppressWarnings("unchecked")
- final
- // Indexed properties are stored as List
- List list = (List)indexedProperty;
- while (index >= list.size()) {
- final Class> contentType = getDynaClass().getDynaProperty(name).getContentType();
- Object value = null;
- if (contentType != null) {
- value = createProperty(name+"["+list.size()+"]", contentType);
- }
- list.add(value);
- }
-
- }
-
- // Grow an Array to the appropriate size
- if (indexedProperty.getClass().isArray()) {
-
- final int length = Array.getLength(indexedProperty);
- if (index >= length) {
- final Class> componentType = indexedProperty.getClass().getComponentType();
- final Object newArray = Array.newInstance(componentType, index + 1);
- System.arraycopy(indexedProperty, 0, newArray, 0, length);
- indexedProperty = newArray;
- set(name, indexedProperty);
- final int newLength = Array.getLength(indexedProperty);
- for (int i = length; i < newLength; i++) {
- Array.set(indexedProperty, i, createProperty(name+"["+i+"]", componentType));
- }
- }
- }
-
- return indexedProperty;
-
- }
-
- /**
- * Create a new Instance of a Property
- * @param name The name of the property
- * @param type The class of the property
- * @return The new value
- */
- protected Object createProperty(final String name, final Class> type) {
- if (type == null) {
- return null;
- }
-
- // Create Lists, arrays or DynaBeans
- if (type.isArray() || List.class.isAssignableFrom(type)) {
- return createIndexedProperty(name, type);
- }
-
- if (Map.class.isAssignableFrom(type)) {
- return createMappedProperty(name, type);
- }
-
- if (DynaBean.class.isAssignableFrom(type)) {
- return createDynaBeanProperty(name, type);
- }
-
- if (type.isPrimitive()) {
- return createPrimitiveProperty(name, type);
- }
-
- if (Number.class.isAssignableFrom(type)) {
- return createNumberProperty(name, type);
- }
-
- return createOtherProperty(name, type);
-
- }
-
- /**
- * Create a new Instance of an 'Indexed' Property
- * @param name The name of the property
- * @param type The class of the property
- * @return The new value
- */
- protected Object createIndexedProperty(final String name, final Class> type) {
-
- // Create the indexed object
- Object indexedProperty = null;
-
- if (type == null) {
-
- indexedProperty = defaultIndexedProperty(name);
-
- } else if (type.isArray()) {
-
- indexedProperty = Array.newInstance(type.getComponentType(), 0);
-
- } else if (List.class.isAssignableFrom(type)) {
- if (type.isInterface()) {
- indexedProperty = defaultIndexedProperty(name);
- } else {
- try {
- indexedProperty = type.newInstance();
- }
- catch (final Exception ex) {
- throw new IllegalArgumentException
- ("Error instantiating indexed property of type '" +
- type.getName() + "' for '" + name + "' " + ex);
- }
- }
- } else {
-
- throw new IllegalArgumentException
- ("Non-indexed property of type '" + type.getName() + "' for '" + name + "'");
- }
-
- return indexedProperty;
-
- }
-
- /**
- * Create a new Instance of a 'Mapped' Property
- * @param name The name of the property
- * @param type The class of the property
- * @return The new value
- */
- protected Object createMappedProperty(final String name, final Class> type) {
-
- // Create the mapped object
- Object mappedProperty = null;
-
- if ((type == null) || type.isInterface()) {
-
- mappedProperty = defaultMappedProperty(name);
-
- } else if (Map.class.isAssignableFrom(type)) {
- try {
- mappedProperty = type.newInstance();
- }
- catch (final Exception ex) {
- throw new IllegalArgumentException
- ("Error instantiating mapped property of type '" +
- type.getName() + "' for '" + name + "' " + ex);
- }
- } else {
-
- throw new IllegalArgumentException
- ("Non-mapped property of type '" + type.getName() + "' for '" + name + "'");
- }
-
- return mappedProperty;
-
- }
-
- /**
- * Create a new Instance of a 'DynaBean' Property.
- * @param name The name of the property
- * @param type The class of the property
- * @return The new value
- */
- protected Object createDynaBeanProperty(final String name, final Class> type) {
- try {
- return type.newInstance();
- }
- catch (final Exception ex) {
- if (logger().isWarnEnabled()) {
- logger().warn("Error instantiating DynaBean property of type '" +
- type.getName() + "' for '" + name + "' " + ex);
- }
- return null;
- }
- }
-
- /**
- * Create a new Instance of a 'Primitive' Property.
- * @param name The name of the property
- * @param type The class of the property
- * @return The new value
- */
- protected Object createPrimitiveProperty(final String name, final Class> type) {
-
- if (type == Boolean.TYPE) {
- return Boolean.FALSE;
- } else if (type == Integer.TYPE) {
- return Integer_ZERO;
- } else if (type == Long.TYPE) {
- return Long_ZERO;
- } else if (type == Double.TYPE) {
- return Double_ZERO;
- } else if (type == Float.TYPE) {
- return Float_ZERO;
- } else if (type == Byte.TYPE) {
- return Byte_ZERO;
- } else if (type == Short.TYPE) {
- return Short_ZERO;
- } else if (type == Character.TYPE) {
- return Character_SPACE;
- } else {
- return null;
- }
-
- }
-
- /**
- * Create a new Instance of a {@code java.lang.Number} Property.
- * @param name The name of the property
- * @param type The class of the property
- * @return The new value
- */
- protected Object createNumberProperty(final String name, final Class> type) {
-
- return null;
-
- }
-
- /**
- * Create a new Instance of other Property types
- * @param name The name of the property
- * @param type The class of the property
- * @return The new value
- */
- protected Object createOtherProperty(final String name, final Class> type) {
-
- if (type == Object.class ||
- type == String.class ||
- type == Boolean.class ||
- type == Character.class ||
- Date.class.isAssignableFrom(type)) {
-
- return null;
-
- }
-
- try {
- return type.newInstance();
- }
- catch (final Exception ex) {
- if (logger().isWarnEnabled()) {
- logger().warn("Error instantiating property of type '" + type.getName() + "' for '" + name + "' " + ex);
- }
- return null;
- }
- }
-
- /**
- *
Creates a new {@code ArrayList} for an 'indexed' property
- * which doesn't exist.
- *
- *
This method should be overridden if an alternative {@code List}
- * or {@code Array} implementation is required for 'indexed' properties.
- *
- * @param name Name of the 'indexed property.
- * @return The default value for an indexed property (java.util.ArrayList)
- */
- protected Object defaultIndexedProperty(final String name) {
- return new ArrayList<>();
- }
-
- /**
- *
Creates a new {@code HashMap} for a 'mapped' property
- * which doesn't exist.
- *
- *
This method can be overridden if an alternative {@code Map}
- * implementation is required for 'mapped' properties.
- *
- * @param name Name of the 'mapped property.
- * @return The default value for a mapped property (java.util.HashMap)
- */
- protected Map defaultMappedProperty(final String name) {
- return new HashMap<>();
- }
-
- /**
- * Indicates if there is a property with the specified name.
- * @param name The name of the property to check
- * @return {@code true} if there is a property of the
- * specified name, otherwise {@code false}
- */
- protected boolean isDynaProperty(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("No property name specified");
- }
-
- // Handle LazyDynaClasses
- if (dynaClass instanceof LazyDynaClass) {
- return ((LazyDynaClass)dynaClass).isDynaProperty(name);
- }
-
- // Handle other MutableDynaClass
- return dynaClass.getDynaProperty(name) != null;
-
- }
-
- /**
- * Is an object of the source class assignable to the destination class?
- *
- * @param dest Destination class
- * @param source Source class
- * @return {@code true} if the source class is assignable to the
- * destination class, otherwise {@code false}
- */
- protected boolean isAssignable(final Class> dest, final Class> source) {
-
- if (dest.isAssignableFrom(source) ||
- dest == Boolean.TYPE && source == Boolean.class ||
- dest == Byte.TYPE && source == Byte.class ||
- dest == Character.TYPE && source == Character.class ||
- dest == Double.TYPE && source == Double.class ||
- dest == Float.TYPE && source == Float.class ||
- dest == Integer.TYPE && source == Integer.class ||
- dest == Long.TYPE && source == Long.class ||
- dest == Short.TYPE && source == Short.class) {
- return true;
- }
- return false;
-
- }
-
- /**
- *
Creates a new instance of the {@code Map}.
- * @return a new Map instance
- */
- protected Map newMap() {
- return new HashMap<>();
- }
-
- /**
- *
Returns the {@code Log}.
- */
- private Log logger() {
- if (logger == null) {
- logger = LogFactory.getLog(LazyDynaBean.class);
- }
- return logger;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaClass.java
deleted file mode 100644
index 9c29af5e7..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaClass.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-/**
- *
DynaClass which implements the {@code MutableDynaClass} interface.
- *
- *
A {@code MutableDynaClass
is a specialized extension to DynaClass}
- * that allows properties to be added or removed dynamically.
- *
- *
This implementation has one slightly unusual default behavior - calling
- * the {@code getDynaProperty(name)} method for a property which doesn't
- * exist returns a {@code DynaProperty
rather than null}. The
- * reason for this is that {@code BeanUtils} calls this method to check if
- * a property exists before trying to set the value. This would defeat the object
- * of the {@code LazyDynaBean} which automatically adds missing properties
- * when any of its {@code set()} methods are called. For this reason the
- * {@code isDynaProperty(name)} method has been added to this implementation
- * in order to determine if a property actually exists. If the more normal
- * behavior of returning {@code null} is required, then this can be achieved
- * by calling the {@code setReturnNull(true)}.
- *
- *
The {@code add(name, type, readable, writable)} method is not implemented
- * and always throws an {@code UnsupportedOperationException}. I believe
- * this attributes need to be added to the {@code DynaProperty} class
- * in order to control read/write facilities.
- *
- * @see LazyDynaBean
- */
-public class LazyDynaClass extends BasicDynaClass implements MutableDynaClass {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Controls whether changes to this DynaClass's properties are allowed.
- */
- protected boolean restricted;
-
- /**
- *
Controls whether the {@code getDynaProperty()} method returns
- * null if a property doesn't exist - or creates a new one.
- *
- *
Default is {@code false}.
- */
- protected boolean returnNull = false;
-
- /**
- * Construct a new LazyDynaClass with default parameters.
- */
- public LazyDynaClass() {
- this(null, (DynaProperty[])null);
- }
-
- /**
- * Construct a new LazyDynaClass with the specified name.
- *
- * @param name Name of this DynaBean class
- */
- public LazyDynaClass(final String name) {
- this(name, (DynaProperty[])null);
- }
-
- /**
- * Construct a new LazyDynaClass with the specified name and DynaBean class.
- *
- * @param name Name of this DynaBean class
- * @param dynaBeanClass The implementation class for new instances
- */
- public LazyDynaClass(final String name, final Class> dynaBeanClass) {
- this(name, dynaBeanClass, null);
- }
-
- /**
- * Construct a new LazyDynaClass with the specified name and properties.
- *
- * @param name Name of this DynaBean class
- * @param properties Property descriptors for the supported properties
- */
- public LazyDynaClass(final String name, final DynaProperty[] properties) {
- this(name, LazyDynaBean.class, properties);
- }
-
- /**
- * Construct a new LazyDynaClass with the specified name, DynaBean class and properties.
- *
- * @param name Name of this DynaBean class
- * @param dynaBeanClass The implementation class for new instances
- * @param properties Property descriptors for the supported properties
- */
- public LazyDynaClass(final String name, final Class> dynaBeanClass, final DynaProperty[] properties) {
- super(name, dynaBeanClass, properties);
- }
-
- /**
- *
Is this DynaClass currently restricted.
- *
If restricted, no changes to the existing registration of
- * property names, data types, readability, or writeability are allowed.
- * @return {@code true} if this {@link MutableDynaClass} cannot be changed
- * otherwise {@code false}
- */
- @Override
- public boolean isRestricted() {
- return restricted;
- }
-
- /**
- *
Set whether this DynaClass is currently restricted.
- *
If restricted, no changes to the existing registration of
- * property names, data types, readability, or writeability are allowed.
- * @param restricted {@code true} if this {@link MutableDynaClass} cannot
- * be changed otherwise {@code false}
- */
- @Override
- public void setRestricted(final boolean restricted) {
- this.restricted = restricted;
- }
-
- /**
- * Should this DynaClass return a {@code null} from
- * the {@code getDynaProperty(name)} method if the property
- * doesn't exist.
- *
- * @return {@code true if a null} {@link DynaProperty}
- * should be returned if the property doesn't exist, otherwise
- * {@code false} if a new {@link DynaProperty} should be created.
- */
- public boolean isReturnNull() {
- return returnNull;
- }
-
- /**
- * Set whether this DynaClass should return a {@code null} from
- * the {@code getDynaProperty(name)} method if the property
- * doesn't exist.
- * @param returnNull {@code true if a null} {@link DynaProperty}
- * should be returned if the property doesn't exist, otherwise
- * {@code false} if a new {@link DynaProperty} should be created.
- */
- public void setReturnNull(final boolean returnNull) {
- this.returnNull = returnNull;
- }
-
- /**
- * Add a new dynamic property with no restrictions on data type,
- * readability, or writeability.
- *
- * @param name Name of the new dynamic property
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no new properties can be added
- */
- @Override
- public void add(final String name) {
- add(new DynaProperty(name));
- }
-
- /**
- * Add a new dynamic property with the specified data type, but with
- * no restrictions on readability or writeability.
- *
- * @param name Name of the new dynamic property
- * @param type Data type of the new dynamic property (null for no
- * restrictions)
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no new properties can be added
- */
- @Override
- public void add(final String name, final Class> type) {
- if (type == null) {
- add(name);
- } else {
- add(new DynaProperty(name, type));
- }
- }
-
- /**
- *
Add a new dynamic property with the specified data type, readability,
- * and writeability.
- *
- *
N.B.Support for readable/writeable properties has not been implemented
- * and this method always throws a {@code UnsupportedOperationException}.
- *
- *
I'm not sure the intention of the original authors for this method, but it seems to
- * me that readable/writable should be attributes of the {@code DynaProperty} class
- * (which they are not) and is the reason this method has not been implemented.
- *
- * @param name Name of the new dynamic property
- * @param type Data type of the new dynamic property (null for no
- * restrictions)
- * @param readable Set to {@code true} if this property value
- * should be readable
- * @param writeable Set to {@code true} if this property value
- * should be writeable
- *
- * @throws UnsupportedOperationException anytime this method is called
- */
- @Override
- public void add(final String name, final Class> type, final boolean readable, final boolean writeable) {
- throw new java.lang.UnsupportedOperationException("readable/writable properties not supported");
- }
-
- /**
- * Add a new dynamic property.
- *
- * @param property Property the new dynamic property to add.
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no new properties can be added
- */
- protected void add(final DynaProperty property) {
-
- if (property.getName() == null) {
- throw new IllegalArgumentException("Property name is missing.");
- }
-
- if (isRestricted()) {
- throw new IllegalStateException("DynaClass is currently restricted. No new properties can be added.");
- }
-
- // Check if property already exists
- if (propertiesMap.get(property.getName()) != null) {
- return;
- }
-
- // Create a new property array with the specified property
- final DynaProperty[] oldProperties = getDynaProperties();
- final DynaProperty[] newProperties = new DynaProperty[oldProperties.length+1];
- System.arraycopy(oldProperties, 0, newProperties, 0, oldProperties.length);
- newProperties[oldProperties.length] = property;
-
- // Update the properties
- setProperties(newProperties);
-
- }
-
- /**
- * Remove the specified dynamic property, and any associated data type,
- * readability, and writeability, from this dynamic class.
- * NOTE - This does NOT cause any
- * corresponding property values to be removed from DynaBean instances
- * associated with this DynaClass.
- *
- * @param name Name of the dynamic property to remove
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no properties can be removed
- */
- @Override
- public void remove(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("Property name is missing.");
- }
-
- if (isRestricted()) {
- throw new IllegalStateException("DynaClass is currently restricted. No properties can be removed.");
- }
-
- // Ignore if property doesn't exist
- if (propertiesMap.get(name) == null) {
- return;
- }
-
- // Create a new property array of without the specified property
- final DynaProperty[] oldProperties = getDynaProperties();
- final DynaProperty[] newProperties = new DynaProperty[oldProperties.length-1];
- int j = 0;
- for (DynaProperty oldProperty : oldProperties) {
- if (!name.equals(oldProperty.getName())) {
- newProperties[j] = oldProperty;
- j++;
- }
- }
-
- // Update the properties
- setProperties(newProperties);
-
- }
-
- /**
- *
Return a property descriptor for the specified property.
- *
- *
If the property is not found and the {@code returnNull} indicator is
- * {@code true
, this method always returns null}.
- *
- *
If the property is not found and the {@code returnNull} indicator is
- * {@code false} a new property descriptor is created and returned (although
- * its not actually added to the DynaClass's properties). This is the default
- * behavior.
- *
- *
The reason for not returning a {@code null} property descriptor is that
- * {@code BeanUtils} uses this method to check if a property exists
- * before trying to set it - since these Lazy implementations automatically
- * add any new properties when they are set, returning {@code null} from
- * this method would defeat their purpose.
- *
- * @param name Name of the dynamic property for which a descriptor
- * is requested
- * @return The dyna property for the specified name
- *
- * @throws IllegalArgumentException if no property name is specified
- */
- @Override
- public DynaProperty getDynaProperty(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("Property name is missing.");
- }
-
- DynaProperty dynaProperty = propertiesMap.get(name);
-
- // If it doesn't exist and returnNull is false
- // create a new DynaProperty
- if (dynaProperty == null && !isReturnNull() && !isRestricted()) {
- dynaProperty = new DynaProperty(name);
- }
-
- return dynaProperty;
-
- }
-
- /**
- *
Indicate whether a property actually exists.
- *
- *
N.B. Using {@code getDynaProperty(name) == null}
- * doesn't work in this implementation because that method might
- * return a DynaProperty if it doesn't exist (depending on the
- * {@code returnNull} indicator).
- *
- * @param name The name of the property to check
- * @return {@code true} if there is a property of the
- * specified name, otherwise {@code false}
- * @throws IllegalArgumentException if no property name is specified
- */
- public boolean isDynaProperty(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("Property name is missing.");
- }
-
- return propertiesMap.get(name) != null;
-
- }
-
-}
\ No newline at end of file
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java
deleted file mode 100644
index 7409ce4b4..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java
+++ /dev/null
@@ -1,714 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Map;
-
-/**
- *
Lazy DynaBean List.
- *
- *
There are two main purposes for this class:
- *
- *
To provide Lazy List behavior - automatically
- * growing and populating the {@code List}
- * with either {@code DynaBean
, java.util.Map}
- * or POJO Beans.
- *
To provide a straight forward way of putting a Collection
- * or Array into the lazy list and a straight forward
- * way to get it out again at the end.
- *
- *
- *
All elements added to the List are stored as {@code DynaBean}'s:
- *
- *
{@code java.util.Map
elements are "wrapped" in a LazyDynaMap}.
- *
POJO Bean elements are "wrapped" in a {@code WrapDynaBean}.
- *
{@code DynaBean}'s are stored un-changed.
- *
- *
- *
{@code toArray()}
- *
The {@code toArray()} method returns an array of the
- * elements of the appropriate type. If the {@code LazyDynaList}
- * is populated with {@code java.util.Map} objects a
- * {@code Map[]} array is returned.
- * If the list is populated with POJO Beans an appropriate
- * array of the POJO Beans is returned. Otherwise a {@code DynaBean[]}
- * array is returned.
- *
- *
- *
{@code toDynaBeanArray()}
- *
The {@code toDynaBeanArray()} method returns a
- * {@code DynaBean[]} array of the elements in the List.
- *
- *
- *
N.B.All the elements in the List must be the
- * same type. If the {@code DynaClass
or Class}
- * of the {@code LazyDynaList}'s elements is
- * not specified, then it will be automatically set to the type
- * of the first element populated.
- *
- *
- *
Example 1
- *
If you have an array of {@code java.util.Map[]} - you can put that into
- * a {@code LazyDynaList}.
- *
- *
- * TreeMap[] myArray = .... // your Map[]
- * List lazyList = new LazyDynaList(myArray);
- *
- *
- *
New elements of the appropriate Map type are
- * automatically populated:
- *
- *
- * // get(index) automatically grows the list
- * DynaBean newElement = (DynaBean)lazyList.get(lazyList.size());
- * newElement.put("someProperty", "someValue");
- *
- *
- *
Once you've finished you can get back an Array of the
- * elements of the appropriate type:
- *
- *
- * // Retrieve the array from the list
- * TreeMap[] myArray = (TreeMap[])lazyList.toArray());
- *
- *
- *
- *
Example 2
- *
Alternatively you can create an empty List and
- * specify the Class for List's elements. The LazyDynaList
- * uses the Class to automatically populate elements:
- *
- *
- * // e.g. For Maps
- * List lazyList = new LazyDynaList(TreeMap.class);
- *
- * // e.g. For POJO Beans
- * List lazyList = new LazyDynaList(MyPojo.class);
- *
- * // e.g. For DynaBeans
- * List lazyList = new LazyDynaList(MyDynaBean.class);
- *
- *
- *
Example 3
- *
Alternatively you can create an empty List and specify the
- * DynaClass for List's elements. The LazyDynaList uses
- * the DynaClass to automatically populate elements:
- *
- *
- * // e.g. For Maps
- * DynaClass dynaClass = new LazyDynaMap(new HashMap());
- * List lazyList = new LazyDynaList(dynaClass);
- *
- * // e.g. For POJO Beans
- * DynaClass dynaClass = (new WrapDynaBean(myPojo)).getDynaClass();
- * List lazyList = new LazyDynaList(dynaClass);
- *
- * // e.g. For DynaBeans
- * DynaClass dynaClass = new BasicDynaClass(properties);
- * List lazyList = new LazyDynaList(dynaClass);
- *
- *
- *
N.B. You may wonder why control the type
- * using a {@code DynaClass
rather than the Class}
- * as in the previous example - the reason is that some {@code DynaBean}
- * implementations don't have a default empty constructor and
- * therefore need to be instantiated using the {@code DynaClass.newInstance()}
- * method.
- *
- *
Example 4
- *
A slight variation - set the element type using either
- * the {@code setElementType(Class)} method or the
- * {@code setElementDynaClass(DynaClass)} method - then populate
- * with the normal {@code java.util.List} methods(i.e.
- * {@code add()
, addAll() or set()}).
- *
- *
- * // Create a new LazyDynaList (100 element capacity)
- * LazyDynaList lazyList = new LazyDynaList(100);
- *
- * // Either Set the element type...
- * lazyList.setElementType(TreeMap.class);
- *
- * // ...or the element DynaClass...
- * lazyList.setElementDynaClass(new MyCustomDynaClass());
- *
- * // Populate from a collection
- * lazyList.addAll(myCollection);
- *
- *
- *
- * @since 1.8.0
- */
-public class LazyDynaList extends ArrayList {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * The DynaClass of the List's elements.
- */
- private DynaClass elementDynaClass;
-
- /**
- * The WrapDynaClass if the List's contains
- * POJO Bean elements.
- *
- * N.B. WrapDynaClass isn't serializable, which
- * is why its stored separately in a
- * transient instance variable.
- */
- private transient WrapDynaClass wrapDynaClass;
-
- /**
- * The type of the List's elements.
- */
- private Class> elementType;
-
- /**
- * The DynaBean type of the List's elements.
- */
- private Class> elementDynaBeanType;
-
-
-
- /**
- * Default Constructor.
- */
- public LazyDynaList() {
- super();
- }
-
- /**
- * Construct a LazyDynaList with the
- * specified capacity.
- *
- * @param capacity The initial capacity of the list.
- */
- public LazyDynaList(final int capacity) {
- super(capacity);
-
- }
-
- /**
- * Construct a LazyDynaList with a
- * specified DynaClass for its elements.
- *
- * @param elementDynaClass The DynaClass of the List's elements.
- */
- public LazyDynaList(final DynaClass elementDynaClass) {
- super();
- setElementDynaClass(elementDynaClass);
- }
-
- /**
- * Construct a LazyDynaList with a
- * specified type for its elements.
- *
- * @param elementType The Type of the List's elements.
- */
- public LazyDynaList(final Class> elementType) {
- super();
- setElementType(elementType);
- }
-
- /**
- * Construct a LazyDynaList populated with the
- * elements of a Collection.
- *
- * @param collection The Collection to populate the List from.
- */
- public LazyDynaList(final Collection> collection) {
- super(collection.size());
- addAll(collection);
- }
-
- /**
- * Construct a LazyDynaList populated with the
- * elements of an Array.
- *
- * @param array The Array to populate the List from.
- */
- public LazyDynaList(final Object[] array) {
- super(array.length);
- this.addAll(Arrays.asList(array));
- }
-
-
-
- /**
- *
Insert an element at the specified index position.
- *
- *
If the index position is greater than the current
- * size of the List, then the List is automatically
- * grown to the appropriate size.
- *
- * @param index The index position to insert the new element.
- * @param element The new element to add.
- */
- @Override
- public void add(final int index, final Object element) {
-
- final DynaBean dynaBean = transform(element);
-
- growList(index);
-
- super.add(index, dynaBean);
-
- }
-
- /**
- *
Add an element to the List.
- *
- * @param element The new element to add.
- * @return true.
- */
- @Override
- public boolean add(final Object element) {
-
- final DynaBean dynaBean = transform(element);
-
- return super.add(dynaBean);
-
- }
-
- /**
- *
Add all the elements from a Collection to the list.
- *
- * @param collection The Collection of new elements.
- * @return true if elements were added.
- */
- @Override
- public boolean addAll(final Collection> collection) {
-
- if (collection == null || collection.size() == 0) {
- return false;
- }
-
- ensureCapacity(size() + collection.size());
-
- for (final Object e : collection) {
- add(e);
- }
-
- return true;
-
- }
-
- /**
- *
Insert all the elements from a Collection into the
- * list at a specified position.
- *
- *
If the index position is greater than the current
- * size of the List, then the List is automatically
- * grown to the appropriate size.
- *
- * @param collection The Collection of new elements.
- * @param index The index position to insert the new elements at.
- * @return true if elements were added.
- */
- @Override
- public boolean addAll(final int index, final Collection> collection) {
-
- if (collection == null || collection.size() == 0) {
- return false;
- }
-
- ensureCapacity((Math.max(index, size())) + collection.size());
-
- // Call "transform" with first element, before
- // List is "grown" to ensure the correct DynaClass
- // is set.
- if (size() == 0) {
- transform(collection.iterator().next());
- }
-
- growList(index);
-
- int currentIndex = index;
- for (final Object e : collection) {
- add(currentIndex++, e);
- }
-
- return true;
-
- }
-
- /**
- *
Return the element at the specified position.
- *
- *
If the position requested is greater than the current
- * size of the List, then the List is automatically
- * grown (and populated) to the appropriate size.
- *
- * @param index The index position to insert the new elements at.
- * @return The element at the specified position.
- */
- @Override
- public Object get(final int index) {
-
- growList(index + 1);
-
- return super.get(index);
-
- }
-
- /**
- *
Set the element at the specified position.
- *
- *
If the position requested is greater than the current
- * size of the List, then the List is automatically
- * grown (and populated) to the appropriate size.
- *
- * @param index The index position to insert the new element at.
- * @param element The new element.
- * @return The new element.
- */
- @Override
- public Object set(final int index, final Object element) {
-
- final DynaBean dynaBean = transform(element);
-
- growList(index + 1);
-
- return super.set(index, dynaBean);
-
- }
-
- /**
- *
Converts the List to an Array.
- *
- *
The type of Array created depends on the contents
- * of the List:
- *
- *
If the List contains only LazyDynaMap type elements
- * then a java.util.Map[] array will be created.
- *
If the List contains only elements which are
- * "wrapped" DynaBeans then an Object[] of the most
- * suitable type will be created.
- *
...otherwise a DynaBean[] will be created.
- *
- *
- * @return An Array of the elements in this List.
- */
- @Override
- public Object[] toArray() {
-
- if (size() == 0 && elementType == null) {
- return new LazyDynaBean[0];
- }
-
- final Object[] array = (Object[])Array.newInstance(elementType, size());
- for (int i = 0; i < size(); i++) {
- if (Map.class.isAssignableFrom(elementType)) {
- array[i] = ((LazyDynaMap)get(i)).getMap();
- } else if (DynaBean.class.isAssignableFrom(elementType)) {
- array[i] = get(i);
- } else {
- array[i] = ((WrapDynaBean)get(i)).getInstance();
- }
- }
- return array;
-
- }
-
- /**
- *
Converts the List to an Array of the specified type.
- *
- * @param The type of the array elements
- * @param model The model for the type of array to return
- * @return An Array of the elements in this List.
- */
- @Override
- public T[] toArray(final T[] model) {
-
- final Class> arrayType = model.getClass().getComponentType();
- if (DynaBean.class.isAssignableFrom(arrayType)
- || size() == 0 && elementType == null) {
- return super.toArray(model);
- }
-
- if (arrayType.isAssignableFrom(elementType)) {
- T[] array;
- if (model.length >= size()) {
- array = model;
- } else {
- @SuppressWarnings("unchecked")
- final
- // This is safe because we know the element type
- T[] tempArray = (T[]) Array.newInstance(arrayType, size());
- array = tempArray;
- }
-
- for (int i = 0; i < size(); i++) {
- Object elem;
- if (Map.class.isAssignableFrom(elementType)) {
- elem = ((LazyDynaMap) get(i)).getMap();
- } else if (DynaBean.class.isAssignableFrom(elementType)) {
- elem = get(i);
- } else {
- elem = ((WrapDynaBean) get(i)).getInstance();
- }
- Array.set(array, i, elem);
- }
- return array;
- }
-
- throw new IllegalArgumentException("Invalid array type: "
- + arrayType.getName() + " - not compatible with '"
- + elementType.getName());
-
- }
-
-
-
- /**
- *
Converts the List to an DynaBean Array.
- *
- * @return A DynaBean[] of the elements in this List.
- */
- public DynaBean[] toDynaBeanArray() {
-
- if (size() == 0 && elementDynaBeanType == null) {
- return new LazyDynaBean[0];
- }
-
- final DynaBean[] array = (DynaBean[])Array.newInstance(elementDynaBeanType, size());
- for (int i = 0; i < size(); i++) {
- array[i] = (DynaBean)get(i);
- }
- return array;
-
- }
-
- /**
- *
Set the element Type and DynaClass.
- *
- * @param elementType The type of the elements.
- * @throws IllegalArgumentException if the List already
- * contains elements or the DynaClass is null.
- */
- public void setElementType(final Class> elementType) {
-
- if (elementType == null) {
- throw new IllegalArgumentException("Element Type is missing");
- }
-
- final boolean changeType = this.elementType != null && !this.elementType.equals(elementType);
- if (changeType && size() > 0) {
- throw new IllegalStateException("Element Type cannot be reset");
- }
-
- this.elementType = elementType;
-
- // Create a new object of the specified type
- Object object = null;
- try {
- object = elementType.newInstance();
- } catch (final Exception e) {
- throw new IllegalArgumentException("Error creating type: "
- + elementType.getName() + " - " + e);
- }
-
- // Create a DynaBean
- DynaBean dynaBean = null;
- if (Map.class.isAssignableFrom(elementType)) {
- dynaBean = createDynaBeanForMapProperty(object);
- this.elementDynaClass = dynaBean.getDynaClass();
- } else if (DynaBean.class.isAssignableFrom(elementType)) {
- dynaBean = (DynaBean)object;
- this.elementDynaClass = dynaBean.getDynaClass();
- } else {
- dynaBean = new WrapDynaBean(object);
- this.wrapDynaClass = (WrapDynaClass)dynaBean.getDynaClass();
- }
-
- 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();
- }
-
- }
-
- /**
- *
Set the element Type and DynaClass.
- *
- * @param elementDynaClass The DynaClass of the elements.
- * @throws IllegalArgumentException if the List already
- * contains elements or the DynaClass is null.
- */
- public void setElementDynaClass(final DynaClass elementDynaClass) {
-
- if (elementDynaClass == null) {
- throw new IllegalArgumentException("Element DynaClass is missing");
- }
-
- if (size() > 0) {
- throw new IllegalStateException("Element DynaClass cannot be reset");
- }
-
- // Try to create a new instance of the DynaBean
- try {
- final DynaBean dynaBean = elementDynaClass.newInstance();
- this.elementDynaBeanType = dynaBean.getClass();
- if (WrapDynaBean.class.isAssignableFrom(elementDynaBeanType)) {
- this.elementType = ((WrapDynaBean)dynaBean).getInstance().getClass();
- this.wrapDynaClass = (WrapDynaClass)elementDynaClass;
- } else if (LazyDynaMap.class.isAssignableFrom(elementDynaBeanType)) {
- this.elementType = ((LazyDynaMap)dynaBean).getMap().getClass();
- this.elementDynaClass = elementDynaClass;
- } else {
- this.elementType = dynaBean.getClass();
- this.elementDynaClass = elementDynaClass;
- }
- } catch (final Exception e) {
- throw new IllegalArgumentException(
- "Error creating DynaBean from " +
- elementDynaClass.getClass().getName() + " - " + e);
- }
-
- }
-
-
-
- /**
- *
Automatically grown the List
- * to the appropriate size, populating with
- * DynaBeans.
- *
- * @param requiredSize the required size of the List.
- */
- private void growList(final int requiredSize) {
-
- if (requiredSize < size()) {
- return;
- }
-
- ensureCapacity(requiredSize + 1);
-
- for (int i = size(); i < requiredSize; i++) {
- final DynaBean dynaBean = transform(null);
- super.add(dynaBean);
- }
-
- }
-
- /**
- *
Transform the element into a DynaBean:
- *
- *
- *
Map elements are turned into LazyDynaMap's.
- *
POJO Beans are "wrapped" in a WrapDynaBean.
- *
DynaBeans are unchanged.
- *
- *
- * @param element The element to transformed.
- * @return The DynaBean to store in the List.
- */
- private DynaBean transform(final Object element) {
-
- DynaBean dynaBean = null;
- Class> newDynaBeanType = null;
- Class> newElementType = null;
-
- // Create a new element
- if (element == null) {
-
- // Default Types to LazyDynaBean
- // if not specified
- if (elementType == null) {
- setElementDynaClass(new LazyDynaClass());
- }
-
- // Get DynaClass (restore WrapDynaClass lost in serialization)
- if (getDynaClass() == null) {
- setElementType(elementType);
- }
-
- // Create a new DynaBean
- try {
- dynaBean = getDynaClass().newInstance();
- newDynaBeanType = dynaBean.getClass();
- } catch (final Exception e) {
- throw new IllegalArgumentException("Error creating DynaBean: "
- + getDynaClass().getClass().getName()
- + " - " + e);
- }
-
- } else {
-
- // Transform Object to a DynaBean
- newElementType = element.getClass();
- if (Map.class.isAssignableFrom(element.getClass())) {
- dynaBean = createDynaBeanForMapProperty(element);
- } else if (DynaBean.class.isAssignableFrom(element.getClass())) {
- dynaBean = (DynaBean)element;
- } else {
- dynaBean = new WrapDynaBean(element);
- }
-
- newDynaBeanType = dynaBean.getClass();
-
- }
-
- // Re-calculate the element type
- newElementType = dynaBean.getClass();
- if (WrapDynaBean.class.isAssignableFrom(newDynaBeanType)) {
- newElementType = ((WrapDynaBean)dynaBean).getInstance().getClass();
- } else if (LazyDynaMap.class.isAssignableFrom(newDynaBeanType)) {
- newElementType = ((LazyDynaMap)dynaBean).getMap().getClass();
- }
-
- // Check the new element type, matches all the
- // other elements in the List
- if (elementType != null && !newElementType.equals(elementType)) {
- throw new IllegalArgumentException("Element Type " + newElementType
- + " doesn't match other elements " + elementType);
- }
-
- return dynaBean;
-
- }
-
- /**
- * Creates a new {@code LazyDynaMap} object for the given property value.
- *
- * @param value the property value
- * @return the newly created {@code LazyDynaMap}
- */
- private LazyDynaMap createDynaBeanForMapProperty(final Object value) {
- @SuppressWarnings("unchecked")
- final
- // map properties are always stored as Map
- Map valueMap = (Map) value;
- return new LazyDynaMap(valueMap);
- }
-
- /**
- * Return the DynaClass.
- */
- private DynaClass getDynaClass() {
- return elementDynaClass == null ? wrapDynaClass : elementDynaClass;
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaMap.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaMap.java
deleted file mode 100644
index c710a737d..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaMap.java
+++ /dev/null
@@ -1,487 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.util.Map;
-
-/**
- *
Provides a light weight {@code DynaBean
facade to a Map}
- * with lazy map/list processing.
- *
- *
Its a light weight {@code DynaBean} implementation because there is no
- * actual {@code DynaClass
associated with this DynaBean} - in fact
- * it implements the {@code DynaClass} interface itself providing pseudo DynaClass
- * behavior from the actual values stored in the {@code Map}.
- *
- *
As well providing rhe standard {@code DynaBean
access to the Map}'s properties
- * this class also provides the usual Lazy behavior:
- *
- *
Properties don't need to be pre-defined in a {@code DynaClass}
- *
Indexed properties ({@code Lists
or Arrays}) are automatically instantiated
- * and grown so that they are large enough to cater for the index being set.
- *
Mapped properties are automatically instantiated.
- *
- *
- *
Restricted DynaClass
- *
This class implements the {@code MutableDynaClass} interface.
- * {@code MutableDynaClass
have a facility to restrict the DynaClass}
- * so that its properties cannot be modified. If the {@code MutableDynaClass} is
- * restricted then calling any of the {@code set()} methods for a property which
- * doesn't exist will result in a {@code IllegalArgumentException} being thrown.
- *
- */
-public class LazyDynaMap extends LazyDynaBean implements MutableDynaClass {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * The name of this DynaClass (analogous to the
- * {@code getName() method of java.lang.Class}).
- */
- protected String name;
-
- /**
- * Controls whether changes to this DynaClass's properties are allowed.
- */
- protected boolean restricted;
-
- /**
- *
Controls whether the {@code getDynaProperty()} method returns
- * null if a property doesn't exist - or creates a new one.
- *
- *
Default is {@code false}.
- */
- protected boolean returnNull = false;
-
-
-
- /**
- * Default Constructor.
- */
- public LazyDynaMap() {
- this(null, (Map)null);
- }
-
- /**
- * Construct a new {@code LazyDynaMap} with the specified name.
- *
- * @param name Name of this DynaBean class
- */
- public LazyDynaMap(final String name) {
- this(name, (Map)null);
- }
-
- /**
- * Construct a new {@code LazyDynaMap
with the specified Map}.
- *
- * @param values The Map backing this {@code LazyDynaMap}
- */
- public LazyDynaMap(final Map values) {
- this(null, values);
- }
-
- /**
- * Construct a new {@code LazyDynaMap with the specified name and Map}.
- *
- * @param name Name of this DynaBean class
- * @param values The Map backing this {@code LazyDynaMap}
- */
- public LazyDynaMap(final String name, final Map values) {
- this.name = name == null ? "LazyDynaMap" : name;
- this.values = values == null ? newMap() : values;
- this.dynaClass = this;
- }
-
- /**
- * Construct a new {@code LazyDynaMap} with the specified properties.
- *
- * @param properties Property descriptors for the supported properties
- */
- public LazyDynaMap(final DynaProperty[] properties) {
- this(null, properties);
- }
-
- /**
- * Construct a new {@code LazyDynaMap} with the specified name and properties.
- *
- * @param name Name of this DynaBean class
- * @param properties Property descriptors for the supported properties
- */
- public LazyDynaMap(final String name, final DynaProperty[] properties) {
- this(name, (Map)null);
- if (properties != null) {
- for (final DynaProperty property : properties) {
- add(property);
- }
- }
- }
-
- /**
- * Construct a new {@code LazyDynaMap} based on an exisiting DynaClass
- *
- * @param dynaClass DynaClass to copy the name and properties from
- */
- public LazyDynaMap(final DynaClass dynaClass) {
- this(dynaClass.getName(), dynaClass.getDynaProperties());
- }
-
-
-
- /**
- * Set the Map backing this {@code DynaBean}
- *
- * @param values The new Map of values
- */
- public void setMap(final Map values) {
- this.values = values;
- }
-
- /**
- * Return the underlying Map backing this {@code DynaBean}
- * @return the underlying Map
- * @since 1.8.0
- */
- @Override
- public Map getMap() {
- return values;
- }
-
-
-
- /**
- * Set the value of a simple property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param value Value to which this property is to be set
- */
- @Override
- public void set(final String name, final Object value) {
-
- if (isRestricted() && !values.containsKey(name)) {
- throw new IllegalArgumentException
- ("Invalid property name '" + name + "' (DynaClass is restricted)");
- }
-
- values.put(name, value);
-
- }
-
-
-
- /**
- * Return the name of this DynaClass (analogous to the
- * {@code getName() method of java.lang.Class})
- *
- * @return the name of the DynaClass
- */
- @Override
- public String getName() {
- return this.name;
- }
-
- /**
- *
Return a property descriptor for the specified property.
- *
- *
If the property is not found and the {@code returnNull} indicator is
- * {@code true
, this method always returns null}.
- *
- *
If the property is not found and the {@code returnNull} indicator is
- * {@code false} a new property descriptor is created and returned (although
- * its not actually added to the DynaClass's properties). This is the default
- * behavior.
- *
- *
The reason for not returning a {@code null} property descriptor is that
- * {@code BeanUtils} uses this method to check if a property exists
- * before trying to set it - since these Map implementations automatically
- * add any new properties when they are set, returning {@code null} from
- * this method would defeat their purpose.
- *
- * @param name Name of the dynamic property for which a descriptor
- * is requested
- * @return The descriptor for the specified property
- *
- * @throws IllegalArgumentException if no property name is specified
- */
- @Override
- public DynaProperty getDynaProperty(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("Property name is missing.");
- }
-
- // If it doesn't exist and returnNull is false
- // create a new DynaProperty
- if (!values.containsKey(name) && isReturnNull()) {
- return null;
- }
-
- final Object value = values.get(name);
-
- if (value == null) {
- return new DynaProperty(name);
- }
- return new DynaProperty(name, value.getClass());
-
- }
-
- /**
- *
Return an array of {@code PropertyDescriptor} for the properties
- * currently defined in this DynaClass. If no properties are defined, a
- * zero-length array will be returned.
- *
- *
FIXME - Should we really be implementing
- * {@code getBeanInfo()} instead, which returns property descriptors
- * and a bunch of other stuff?
- * @return the set of properties for this DynaClass
- */
- @Override
- public DynaProperty[] getDynaProperties() {
-
- int i = 0;
- final DynaProperty[] properties = new DynaProperty[values.size()];
- for (final Map.Entry e : values.entrySet()) {
- final String name = e.getKey();
- final Object value = values.get(name);
- properties[i++] = new DynaProperty(name, value == null ? null
- : value.getClass());
- }
-
- return properties;
-
- }
-
- /**
- * Instantiate and return a new DynaBean instance, associated
- * with this DynaClass.
- * @return A new {@code DynaBean} instance
- */
- @Override
- public DynaBean newInstance() {
-
- // Create a new instance of the Map
- Map newMap = null;
- try {
- final
- // The new map is used as properties map
- Map temp = getMap().getClass().newInstance();
- newMap = temp;
- } catch(final Exception ex) {
- newMap = newMap();
- }
-
- // Crate new LazyDynaMap and initialize properties
- final LazyDynaMap lazyMap = new LazyDynaMap(newMap);
- final DynaProperty[] properties = this.getDynaProperties();
- if (properties != null) {
- for (final DynaProperty property : properties) {
- lazyMap.add(property);
- }
- }
- return lazyMap;
- }
-
-
-
- /**
- *
Is this DynaClass currently restricted.
- *
If restricted, no changes to the existing registration of
- * property names, data types, readability, or writeability are allowed.
- *
- * @return {@code true} if this Mutable {@link DynaClass} is restricted,
- * otherwise {@code false}
- */
- @Override
- public boolean isRestricted() {
- return restricted;
- }
-
- /**
- *
Set whether this DynaClass is currently restricted.
- *
If restricted, no changes to the existing registration of
- * property names, data types, readability, or writeability are allowed.
- *
- * @param restricted The new restricted state
- */
- @Override
- public void setRestricted(final boolean restricted) {
- this.restricted = restricted;
- }
-
- /**
- * Add a new dynamic property with no restrictions on data type,
- * readability, or writeability.
- *
- * @param name Name of the new dynamic property
- *
- * @throws IllegalArgumentException if name is null
- */
- @Override
- public void add(final String name) {
- add(name, null);
- }
-
- /**
- * Add a new dynamic property with the specified data type, but with
- * no restrictions on readability or writeability.
- *
- * @param name Name of the new dynamic property
- * @param type Data type of the new dynamic property (null for no
- * restrictions)
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no new properties can be added
- */
- @Override
- public void add(final String name, final Class> type) {
-
- if (name == null) {
- throw new IllegalArgumentException("Property name is missing.");
- }
-
- if (isRestricted()) {
- throw new IllegalStateException("DynaClass is currently restricted. No new properties can be added.");
- }
-
- final Object value = values.get(name);
-
- // Check if the property already exists
- if (value == null) {
- values.put(name, type == null ? null : createProperty(name, type));
- }
-
- }
-
- /**
- *
Add a new dynamic property with the specified data type, readability,
- * and writeability.
- *
- *
N.B.Support for readable/writeable properties has not been implemented
- * and this method always throws a {@code UnsupportedOperationException}.
- *
- *
I'm not sure the intention of the original authors for this method, but it seems to
- * me that readable/writable should be attributes of the {@code DynaProperty} class
- * (which they are not) and is the reason this method has not been implemented.
- *
- * @param name Name of the new dynamic property
- * @param type Data type of the new dynamic property (null for no
- * restrictions)
- * @param readable Set to {@code true} if this property value
- * should be readable
- * @param writeable Set to {@code true} if this property value
- * should be writeable
- *
- * @throws UnsupportedOperationException anytime this method is called
- */
- @Override
- public void add(final String name, final Class> type, final boolean readable, final boolean writeable) {
- throw new java.lang.UnsupportedOperationException("readable/writable properties not supported");
- }
-
- /**
- * Add a new dynamic property.
- *
- * @param property Property the new dynamic property to add.
- *
- * @throws IllegalArgumentException if name is null
- */
- protected void add(final DynaProperty property) {
- add(property.getName(), property.getType());
- }
-
- /**
- * Remove the specified dynamic property, and any associated data type,
- * readability, and writeability, from this dynamic class.
- * NOTE - This does NOT cause any
- * corresponding property values to be removed from DynaBean instances
- * associated with this DynaClass.
- *
- * @param name Name of the dynamic property to remove
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no properties can be removed
- */
- @Override
- public void remove(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("Property name is missing.");
- }
-
- if (isRestricted()) {
- throw new IllegalStateException("DynaClass is currently restricted. No properties can be removed.");
- }
-
- values.remove(name);
- }
-
-
-
- /**
- * Should this DynaClass return a {@code null} from
- * the {@code getDynaProperty(name)} method if the property
- * doesn't exist.
- *
- * @return {@code true if a null} {@link DynaProperty}
- * should be returned if the property doesn't exist, otherwise
- * {@code false} if a new {@link DynaProperty} should be created.
- */
- public boolean isReturnNull() {
- return returnNull;
- }
-
- /**
- * Set whether this DynaClass should return a {@code null} from
- * the {@code getDynaProperty(name)} method if the property
- * doesn't exist.
- *
- * @param returnNull {@code true if a null} {@link DynaProperty}
- * should be returned if the property doesn't exist, otherwise
- * {@code false} if a new {@link DynaProperty} should be created.
- */
- public void setReturnNull(final boolean returnNull) {
- this.returnNull = returnNull;
- }
-
-
-
- /**
- *
Indicate whether a property actually exists.
- *
- *
N.B. Using {@code getDynaProperty(name) == null}
- * doesn't work in this implementation because that method might
- * return a DynaProperty if it doesn't exist (depending on the
- * {@code returnNull} indicator).
- *
- * @param name Name of the dynamic property
- * @return {@code true} if the property exists,
- * otherwise {@code false}
- * @throws IllegalArgumentException if no property name is specified
- */
- @Override
- protected boolean isDynaProperty(final String name) {
-
- if (name == null) {
- throw new IllegalArgumentException("Property name is missing.");
- }
-
- return values.containsKey(name);
-
- }
-
-}
\ No newline at end of file
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/MappedPropertyDescriptor.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/MappedPropertyDescriptor.java
deleted file mode 100644
index c204be0b9..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/MappedPropertyDescriptor.java
+++ /dev/null
@@ -1,525 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.lang.ref.Reference;
-import java.lang.ref.SoftReference;
-import java.lang.ref.WeakReference;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-
-
-/**
- * A MappedPropertyDescriptor describes one mapped property.
- * Mapped properties are multivalued properties like indexed properties
- * but that are accessed with a String key instead of an index.
- * Such property values are typically stored in a Map collection.
- * For this class to work properly, a mapped value must have
- * getter and setter methods of the form
- *
where {@code Property} must be replaced
- * by the name of the property.
- * @see java.beans.PropertyDescriptor
- *
- */
-public class MappedPropertyDescriptor extends PropertyDescriptor {
-
-
- /**
- * The underlying data type of the property we are describing.
- */
- private Reference> mappedPropertyTypeRef;
-
- /**
- * The reader method for this property (if any).
- */
- private MappedMethodReference mappedReadMethodRef;
-
- /**
- * The writer method for this property (if any).
- */
- private MappedMethodReference mappedWriteMethodRef;
-
- /**
- * The parameter types array for the reader method signature.
- */
- private static final Class>[] STRING_CLASS_PARAMETER = new Class[]{String.class};
-
-
-
- /**
- * Constructs a MappedPropertyDescriptor for a property that follows
- * the standard Java convention by having getFoo and setFoo
- * accessor methods, with the addition of a String parameter (the key).
- * Thus if the argument name is "fred", it will
- * assume that the writer method is "setFred" and the reader method
- * is "getFred". Note that the property name should start with a lower
- * case character, which will be capitalized in the method names.
- *
- * @param propertyName The programmatic name of the property.
- * @param beanClass The Class object for the target bean. For
- * example sun.beans.OurButton.class.
- *
- * @throws IntrospectionException if an exception occurs during
- * introspection.
- */
- public MappedPropertyDescriptor(final String propertyName, final Class> beanClass)
- throws IntrospectionException {
-
- super(propertyName, null, null);
-
- if (propertyName == null || propertyName.length() == 0) {
- throw new IntrospectionException("bad property name: " +
- propertyName + " on class: " + beanClass.getClass().getName());
- }
-
- setName(propertyName);
- final String base = capitalizePropertyName(propertyName);
-
- // Look for mapped read method and matching write method
- Method mappedReadMethod = null;
- Method mappedWriteMethod = null;
- try {
- try {
- mappedReadMethod = getMethod(beanClass, "get" + base,
- STRING_CLASS_PARAMETER);
- } catch (final IntrospectionException e) {
- mappedReadMethod = getMethod(beanClass, "is" + base,
- STRING_CLASS_PARAMETER);
- }
- final Class>[] params = { String.class, mappedReadMethod.getReturnType() };
- mappedWriteMethod = getMethod(beanClass, "set" + base, params);
- } catch (final IntrospectionException e) {
- /* Swallow IntrospectionException
- * TODO: Why?
- */
- }
-
- // If there's no read method, then look for just a write method
- if (mappedReadMethod == null) {
- mappedWriteMethod = getMethod(beanClass, "set" + base, 2);
- }
-
- if (mappedReadMethod == null && mappedWriteMethod == null) {
- throw new IntrospectionException("Property '" + propertyName +
- "' not found on " +
- beanClass.getName());
- }
- mappedReadMethodRef = new MappedMethodReference(mappedReadMethod);
- mappedWriteMethodRef = new MappedMethodReference(mappedWriteMethod);
-
- findMappedPropertyType();
- }
-
-
- /**
- * This constructor takes the name of a mapped property, and method
- * names for reading and writing the property.
- *
- * @param propertyName The programmatic name of the property.
- * @param beanClass The Class object for the target bean. For
- * example sun.beans.OurButton.class.
- * @param mappedGetterName The name of the method used for
- * reading one of the property values. May be null if the
- * property is write-only.
- * @param mappedSetterName The name of the method used for writing
- * one of the property values. May be null if the property is
- * read-only.
- *
- * @throws IntrospectionException if an exception occurs during
- * introspection.
- */
- public MappedPropertyDescriptor(final String propertyName, final Class> beanClass,
- final String mappedGetterName, final String mappedSetterName)
- throws IntrospectionException {
-
- super(propertyName, null, null);
-
- if (propertyName == null || propertyName.length() == 0) {
- throw new IntrospectionException("bad property name: " +
- propertyName);
- }
- setName(propertyName);
-
- // search the mapped get and set methods
- Method mappedReadMethod = null;
- Method mappedWriteMethod = null;
- mappedReadMethod =
- getMethod(beanClass, mappedGetterName, STRING_CLASS_PARAMETER);
-
- if (mappedReadMethod != null) {
- final Class>[] params = { String.class, mappedReadMethod.getReturnType() };
- mappedWriteMethod =
- getMethod(beanClass, mappedSetterName, params);
- } else {
- mappedWriteMethod =
- getMethod(beanClass, mappedSetterName, 2);
- }
- mappedReadMethodRef = new MappedMethodReference(mappedReadMethod);
- mappedWriteMethodRef = new MappedMethodReference(mappedWriteMethod);
-
- findMappedPropertyType();
- }
-
- /**
- * This constructor takes the name of a mapped property, and Method
- * objects for reading and writing the property.
- *
- * @param propertyName The programmatic name of the property.
- * @param mappedGetter The method used for reading one of
- * the property values. May be be null if the property
- * is write-only.
- * @param mappedSetter The method used for writing one the
- * property values. May be null if the property is read-only.
- *
- * @throws IntrospectionException if an exception occurs during
- * introspection.
- */
- public MappedPropertyDescriptor(final String propertyName,
- final Method mappedGetter, final Method mappedSetter)
- throws IntrospectionException {
-
- super(propertyName, mappedGetter, mappedSetter);
-
- if (propertyName == null || propertyName.length() == 0) {
- throw new IntrospectionException("bad property name: " +
- propertyName);
- }
-
- setName(propertyName);
- mappedReadMethodRef = new MappedMethodReference(mappedGetter);
- mappedWriteMethodRef = new MappedMethodReference(mappedSetter);
- findMappedPropertyType();
- }
-
-
-
- /**
- * Gets the Class object for the property values.
- *
- * @return The Java type info for the property values. Note that
- * the "Class" object may describe a built-in Java type such as "int".
- * The result may be "null" if this is a mapped property that
- * does not support non-keyed access.
- *
- * This is the type that will be returned by the mappedReadMethod.
- */
- public Class> getMappedPropertyType() {
- return mappedPropertyTypeRef.get();
- }
-
- /**
- * Gets the method that should be used to read one of the property value.
- *
- * @return The method that should be used to read the property value.
- * May return null if the property can't be read.
- */
- public Method getMappedReadMethod() {
- return mappedReadMethodRef.get();
- }
-
- /**
- * Sets the method that should be used to read one of the property value.
- *
- * @param mappedGetter The mapped getter method.
- * @throws IntrospectionException If an error occurs finding the
- * mapped property
- */
- public void setMappedReadMethod(final Method mappedGetter)
- throws IntrospectionException {
- mappedReadMethodRef = new MappedMethodReference(mappedGetter);
- findMappedPropertyType();
- }
-
- /**
- * Gets the method that should be used to write one of the property value.
- *
- * @return The method that should be used to write one of the property value.
- * May return null if the property can't be written.
- */
- public Method getMappedWriteMethod() {
- return mappedWriteMethodRef.get();
- }
-
- /**
- * Sets the method that should be used to write the property value.
- *
- * @param mappedSetter The mapped setter method.
- * @throws IntrospectionException If an error occurs finding the
- * mapped property
- */
- public void setMappedWriteMethod(final Method mappedSetter)
- throws IntrospectionException {
- mappedWriteMethodRef = new MappedMethodReference(mappedSetter);
- findMappedPropertyType();
- }
-
-
-
- /**
- * Introspect our bean class to identify the corresponding getter
- * and setter methods.
- */
- private void findMappedPropertyType() throws IntrospectionException {
- final Method mappedReadMethod = getMappedReadMethod();
- final Method mappedWriteMethod = getMappedWriteMethod();
- Class> mappedPropertyType = null;
- if (mappedReadMethod != null) {
- if (mappedReadMethod.getParameterTypes().length != 1) {
- throw new IntrospectionException
- ("bad mapped read method arg count");
- }
- mappedPropertyType = mappedReadMethod.getReturnType();
- if (mappedPropertyType == Void.TYPE) {
- throw new IntrospectionException
- ("mapped read method " +
- mappedReadMethod.getName() + " returns void");
- }
- }
-
- if (mappedWriteMethod != null) {
- final Class>[] params = mappedWriteMethod.getParameterTypes();
- if (params.length != 2) {
- throw new IntrospectionException
- ("bad mapped write method arg count");
- }
- if (mappedPropertyType != null &&
- mappedPropertyType != params[1]) {
- throw new IntrospectionException
- ("type mismatch between mapped read and write methods");
- }
- mappedPropertyType = params[1];
- }
- mappedPropertyTypeRef = new SoftReference<>(mappedPropertyType);
- }
-
-
- /**
- * Return a capitalized version of the specified property name.
- *
- * @param s The property name
- */
- private static String capitalizePropertyName(final String s) {
- if (s.length() == 0) {
- return s;
- }
-
- final char[] chars = s.toCharArray();
- chars[0] = Character.toUpperCase(chars[0]);
- return new String(chars);
- }
-
- /**
- * Find a method on a class with a specified number of parameters.
- */
- private static Method internalGetMethod(final Class> initial, final String methodName,
- final int parameterCount) {
- // For overridden methods we need to find the most derived version.
- // So we start with the given class and walk up the superclass chain.
- for (Class> clazz = initial; clazz != null; clazz = clazz.getSuperclass()) {
- final Method[] methods = clazz.getDeclaredMethods();
- for (final Method method : methods) {
- if (method == null) {
- continue;
- }
- // skip static methods.
- final int mods = method.getModifiers();
- if (!Modifier.isPublic(mods) ||
- Modifier.isStatic(mods)) {
- continue;
- }
- if (method.getName().equals(methodName) &&
- method.getParameterTypes().length == parameterCount) {
- return method;
- }
- }
- }
-
- // Now check any inherited interfaces. This is necessary both when
- // the argument class is itself an interface, and when the argument
- // class is an abstract class.
- final Class>[] interfaces = initial.getInterfaces();
- for (final Class> interface1 : interfaces) {
- final Method method = internalGetMethod(interface1, methodName, parameterCount);
- if (method != null) {
- return method;
- }
- }
-
- return null;
- }
-
- /**
- * Find a method on a class with a specified number of parameters.
- */
- private static Method getMethod(final Class> clazz, final String methodName, final int parameterCount)
- throws IntrospectionException {
- if (methodName == null) {
- return null;
- }
-
- final Method method = internalGetMethod(clazz, methodName, parameterCount);
- if (method != null) {
- return method;
- }
-
- // No Method found
- throw new IntrospectionException("No method \"" + methodName +
- "\" with " + parameterCount + " parameter(s)");
- }
-
- /**
- * Find a method on a class with a specified parameter list.
- */
- private static Method getMethod(final Class> clazz, final String methodName, final Class>[] parameterTypes)
- throws IntrospectionException {
- if (methodName == null) {
- return null;
- }
-
- final Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, parameterTypes);
- if (method != null) {
- return method;
- }
-
- final int parameterCount = parameterTypes == null ? 0 : parameterTypes.length;
-
- // No Method found
- throw new IntrospectionException("No method \"" + methodName +
- "\" with " + parameterCount + " parameter(s) of matching types.");
- }
-
- /**
- * Holds a {@link Method} in a {@link SoftReference} so that it
- * it doesn't prevent any ClassLoader being garbage collected, but
- * tries to re-create the method if the method reference has been
- * released.
- *
- * See https://issues.apache.org/jira/browse/BEANUTILS-291
- */
- private static class MappedMethodReference {
- private String className;
- private String methodName;
- private Reference methodRef;
- private Reference> classRef;
- private Reference> writeParamTypeRef0;
- private Reference> writeParamTypeRef1;
- private String[] writeParamClassNames;
- MappedMethodReference(final Method m) {
- if (m != null) {
- className = m.getDeclaringClass().getName();
- methodName = m.getName();
- methodRef = new SoftReference<>(m);
- classRef = new WeakReference<>(m.getDeclaringClass());
- final Class>[] types = m.getParameterTypes();
- if (types.length == 2) {
- writeParamTypeRef0 = new WeakReference<>(types[0]);
- writeParamTypeRef1 = new WeakReference<>(types[1]);
- writeParamClassNames = new String[2];
- writeParamClassNames[0] = types[0].getName();
- writeParamClassNames[1] = types[1].getName();
- }
- }
- }
- private Method get() {
- if (methodRef == null) {
- return null;
- }
- Method m = methodRef.get();
- if (m == null) {
- Class> clazz = classRef.get();
- if (clazz == null) {
- clazz = reLoadClass();
- if (clazz != null) {
- classRef = new WeakReference<>(clazz);
- }
- }
- if (clazz == null) {
- throw new RuntimeException("Method " + methodName + " for " +
- className + " could not be reconstructed - class reference has gone");
- }
- Class>[] paramTypes = null;
- if (writeParamClassNames != null) {
- paramTypes = new Class[2];
- paramTypes[0] = writeParamTypeRef0.get();
- if (paramTypes[0] == null) {
- paramTypes[0] = reLoadClass(writeParamClassNames[0]);
- if (paramTypes[0] != null) {
- writeParamTypeRef0 = new WeakReference<>(paramTypes[0]);
- }
- }
- paramTypes[1] = writeParamTypeRef1.get();
- if (paramTypes[1] == null) {
- paramTypes[1] = reLoadClass(writeParamClassNames[1]);
- if (paramTypes[1] != null) {
- writeParamTypeRef1 = new WeakReference<>(paramTypes[1]);
- }
- }
- } else {
- paramTypes = STRING_CLASS_PARAMETER;
- }
- try {
- m = clazz.getMethod(methodName, paramTypes);
- // Un-comment following line for testing
- // System.out.println("Recreated Method " + methodName + " for " + className);
- } catch (final NoSuchMethodException e) {
- throw new RuntimeException("Method " + methodName + " for " +
- className + " could not be reconstructed - method not found");
- }
- methodRef = new SoftReference<>(m);
- }
- return m;
- }
-
- /**
- * Try to re-load the class
- */
- private Class> reLoadClass() {
- return reLoadClass(className);
- }
-
- /**
- * Try to re-load the class
- */
- private Class> reLoadClass(final String name) {
-
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-
- // Try the context class loader
- if (classLoader != null) {
- try {
- return classLoader.loadClass(name);
- } catch (final ClassNotFoundException e) {
- // ignore
- }
- }
-
- // Try this class's class loader
- classLoader = MappedPropertyDescriptor.class.getClassLoader();
- try {
- return classLoader.loadClass(name);
- } catch (final ClassNotFoundException e) {
- return null;
- }
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/MethodUtils.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/MethodUtils.java
deleted file mode 100644
index 64b485d03..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/MethodUtils.java
+++ /dev/null
@@ -1,1349 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.lang.ref.Reference;
-import java.lang.ref.WeakReference;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collections;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
Utility reflection methods focused on methods in general rather than properties in particular.
- *
- *
Known Limitations
- *
Accessing Public Methods In A Default Access Superclass
- *
There is an issue when invoking public methods contained in a default access superclass.
- * Reflection locates these methods fine and correctly assigns them as public.
- * However, an {@code IllegalAccessException} is thrown if the method is invoked.
- *
- *
{@code MethodUtils} contains a workaround for this situation.
- * It will attempt to call {@code setAccessible} on this method.
- * If this call succeeds, then the method can be invoked as normal.
- * This call will only succeed when the application has sufficient security privileges.
- * If this call fails then a warning will be logged and the method may fail.
- *
- */
-
-public class MethodUtils {
-
-
-
- /**
- * Only log warning about accessibility work around once.
- *
- * Note that this is broken when this class is deployed via a shared
- * classloader in a container, as the warning message will be emitted
- * only once, not once per webapp. However making the warning appear
- * once per webapp means having a map keyed by context classloader
- * which introduces nasty memory-leak problems. As this warning is
- * really optional we can ignore this problem; only one of the webapps
- * will get the warning in its logs but that should be good enough.
- */
- private static boolean loggedAccessibleWarning = false;
-
- /**
- * Indicates whether methods should be cached for improved performance.
- *
- * Note that when this class is deployed via a shared classloader in
- * a container, this will affect all webapps. However making this
- * configurable per webapp would mean having a map keyed by context classloader
- * which may introduce memory-leak problems.
- */
- private static boolean CACHE_METHODS = true;
-
- /** An empty class array */
- private static final Class>[] EMPTY_CLASS_PARAMETERS = new Class[0];
- /** An empty object array */
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
-
- /**
- * Stores a cache of MethodDescriptor -> Method in a WeakHashMap.
- *
- * The keys into this map only ever exist as temporary variables within
- * methods of this class, and are never exposed to users of this class.
- * This means that the WeakHashMap is used only as a mechanism for
- * limiting the size of the cache, ie a way to tell the garbage collector
- * that the contents of the cache can be completely garbage-collected
- * whenever it needs the memory. Whether this is a good approach to
- * this problem is doubtful; something like the commons-collections
- * LRUMap may be more appropriate (though of course selecting an
- * appropriate size is an issue).
- *
- * This static variable is safe even when this code is deployed via a
- * shared classloader because it is keyed via a MethodDescriptor object
- * which has a Class as one of its members and that member is used in
- * the MethodDescriptor.equals method. So two components that load the same
- * class via different classloaders will generate non-equal MethodDescriptor
- * objects and hence end up with different entries in the map.
- */
- private static final Map> cache = Collections
- .synchronizedMap(new WeakHashMap>());
-
-
-
- /**
- * Set whether methods should be cached for greater performance or not,
- * default is {@code true}.
- *
- * @param cacheMethods {@code true} if methods should be
- * cached for greater performance, otherwise {@code false}
- * @since 1.8.0
- */
- public static synchronized void setCacheMethods(final boolean cacheMethods) {
- CACHE_METHODS = cacheMethods;
- if (!CACHE_METHODS) {
- clearCache();
- }
- }
-
- /**
- * Clear the method cache.
- * @return the number of cached methods cleared
- * @since 1.8.0
- */
- public static synchronized int clearCache() {
- final int size = cache.size();
- cache.clear();
- return size;
- }
-
- /**
- *
Invoke a named method whose parameter type matches the object type.
- *
- *
The behavior of this method is less deterministic
- * than {@code invokeExactMethod()}.
- * It loops through all methods with names that match
- * and then executes the first it finds with compatible parameters.
- *
- *
This method supports calls to methods taking primitive parameters
- * via passing in wrapping classes. So, for example, a {@code Boolean} class
- * would match a {@code boolean} primitive.
- *
- *
This is a convenient wrapper for
- * {@link #invokeMethod(Object object,String methodName,Object [] args)}.
- *
- *
- * @param object invoke method on this object
- * @param methodName get method with this name
- * @param arg use this argument. May be null (this will result in calling the
- * parameterless method with name {@code methodName}).
- * @return The value returned by the invoked method
- *
- * @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
- */
- public static Object invokeMethod(
- final Object object,
- final String methodName,
- final Object arg)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- final Object[] args = toArray(arg);
- return invokeMethod(object, methodName, args);
- }
-
- /**
- *
Invoke a named method whose parameter type matches the object type.
- *
- *
The behavior of this method is less deterministic
- * than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}.
- * It loops through all methods with names that match
- * and then executes the first it finds with compatible parameters.
- *
- *
This method supports calls to methods taking primitive parameters
- * via passing in wrapping classes. So, for example, a {@code Boolean} class
- * would match a {@code boolean} primitive.
- *
- *
This is a convenient wrapper for
- * {@link #invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)}.
- *
- *
- * @param object invoke method on this object
- * @param methodName get method with this name
- * @param args use these arguments - treat null as empty array (passing null will
- * result in calling the parameterless method with name {@code methodName}).
- * @return The value returned by the invoked method
- *
- * @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
- */
- public static Object invokeMethod(
- final Object object,
- final String methodName,
- Object[] args)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
- final int arguments = args.length;
- final Class>[] parameterTypes = new Class[arguments];
- for (int i = 0; i < arguments; i++) {
- parameterTypes[i] = args[i].getClass();
- }
- return invokeMethod(object, methodName, args, parameterTypes);
- }
-
- /**
- *
Invoke a named method whose parameter type matches the object type.
- *
- *
The behavior of this method is less deterministic
- * than {@link
- * #invokeExactMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)}.
- * It loops through all methods with names that match
- * and then executes the first it finds with compatible parameters.
- *
- *
This method supports calls to methods taking primitive parameters
- * via passing in wrapping classes. So, for example, a {@code Boolean} class
- * would match a {@code boolean} primitive.
- *
- *
- * @param object invoke method on this object
- * @param methodName get method with this name
- * @param args use these arguments - treat null as empty array (passing null will
- * result in calling the parameterless method with name {@code methodName}).
- * @param parameterTypes match these parameters - treat null as empty array
- * @return The value returned by the invoked method
- *
- * @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
- */
- public static Object invokeMethod(
- final Object object,
- final String methodName,
- Object[] args,
- Class>[] parameterTypes)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- if (parameterTypes == null) {
- parameterTypes = EMPTY_CLASS_PARAMETERS;
- }
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
-
- final Method method = getMatchingAccessibleMethod(
- object.getClass(),
- methodName,
- parameterTypes);
- if (method == null) {
- throw new NoSuchMethodException("No such accessible method: " +
- methodName + "() on object: " + object.getClass().getName());
- }
- return method.invoke(object, args);
- }
-
- /**
- *
Invoke a method whose parameter type matches exactly the object
- * type.
- *
- *
This is a convenient wrapper for
- * {@link #invokeExactMethod(Object object,String methodName,Object [] args)}.
- *
- *
- * @param object invoke method on this object
- * @param methodName get method with this name
- * @param arg use this argument. May be null (this will result in calling the
- * parameterless method with name {@code methodName}).
- * @return The value returned by the invoked method
- *
- * @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
- */
- public static Object invokeExactMethod(
- final Object object,
- final String methodName,
- final Object arg)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- final Object[] args = toArray(arg);
- return invokeExactMethod(object, methodName, args);
- }
-
- /**
- *
Invoke a method whose parameter types match exactly the object
- * types.
- *
- *
This uses reflection to invoke the method obtained from a call to
- * {@code getAccessibleMethod()}.
- *
- * @param object invoke method on this object
- * @param methodName get method with this name
- * @param args use these arguments - treat null as empty array (passing null will
- * result in calling the parameterless method with name {@code methodName}).
- * @return The value returned by the invoked method
- *
- * @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
- */
- public static Object invokeExactMethod(
- final Object object,
- final String methodName,
- Object[] args)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
- final int arguments = args.length;
- final Class>[] parameterTypes = new Class[arguments];
- for (int i = 0; i < arguments; i++) {
- parameterTypes[i] = args[i].getClass();
- }
- return invokeExactMethod(object, methodName, args, parameterTypes);
- }
-
- /**
- *
Invoke a method whose parameter types match exactly the parameter
- * types given.
- *
- *
This uses reflection to invoke the method obtained from a call to
- * {@code getAccessibleMethod()}.
- *
- * @param object invoke method on this object
- * @param methodName get method with this name
- * @param args use these arguments - treat null as empty array (passing null will
- * result in calling the parameterless method with name {@code methodName}).
- * @param parameterTypes match these parameters - treat null as empty array
- * @return The value returned by the invoked method
- *
- * @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
- */
- public static Object invokeExactMethod(
- final Object object,
- final String methodName,
- Object[] args,
- Class>[] parameterTypes)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
-
- if (parameterTypes == null) {
- parameterTypes = EMPTY_CLASS_PARAMETERS;
- }
-
- final Method method = getAccessibleMethod(
- object.getClass(),
- methodName,
- parameterTypes);
- if (method == null) {
- throw new NoSuchMethodException("No such accessible method: " +
- methodName + "() on object: " + object.getClass().getName());
- }
- return method.invoke(object, args);
- }
-
- /**
- *
Invoke a static method whose parameter types match exactly the parameter
- * types given.
- *
- *
This uses reflection to invoke the method obtained from a call to
- * {@link #getAccessibleMethod(Class, String, Class[])}.
- *
- * @param objectClass invoke static method on this class
- * @param methodName get method with this name
- * @param args use these arguments - treat null as empty array (passing null will
- * result in calling the parameterless method with name {@code methodName}).
- * @param parameterTypes match these parameters - treat null as empty array
- * @return The value returned by the invoked method
- *
- * @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
- * @since 1.8.0
- */
- public static Object invokeExactStaticMethod(
- final Class> objectClass,
- final String methodName,
- Object[] args,
- Class>[] parameterTypes)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
-
- if (parameterTypes == null) {
- parameterTypes = EMPTY_CLASS_PARAMETERS;
- }
-
- final Method method = getAccessibleMethod(
- objectClass,
- methodName,
- parameterTypes);
- if (method == null) {
- throw new NoSuchMethodException("No such accessible method: " +
- methodName + "() on class: " + objectClass.getName());
- }
- return method.invoke(null, args);
- }
-
- /**
- *
Invoke a named static method whose parameter type matches the object type.
- *
- *
The behavior of this method is less deterministic
- * than {@link #invokeExactMethod(Object, String, Object[], Class[])}.
- * It loops through all methods with names that match
- * and then executes the first it finds with compatible parameters.
- *
- *
This method supports calls to methods taking primitive parameters
- * via passing in wrapping classes. So, for example, a {@code Boolean} class
- * would match a {@code boolean} primitive.
- *
- *
This is a convenient wrapper for
- * {@link #invokeStaticMethod(Class objectClass,String methodName,Object [] args)}.
- *
- *
- * @param objectClass invoke static method on this class
- * @param methodName get method with this name
- * @param arg use this argument. May be null (this will result in calling the
- * parameterless method with name {@code methodName}).
- * @return The value returned by the invoked method
- *
- * @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
- * @since 1.8.0
- */
- public static Object invokeStaticMethod(
- final Class> objectClass,
- final String methodName,
- final Object arg)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- final Object[] args = toArray(arg);
- return invokeStaticMethod (objectClass, methodName, args);
- }
-
- /**
- *
Invoke a named static method whose parameter type matches the object type.
- *
- *
The behavior of this method is less deterministic
- * than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}.
- * It loops through all methods with names that match
- * and then executes the first it finds with compatible parameters.
- *
- *
This method supports calls to methods taking primitive parameters
- * via passing in wrapping classes. So, for example, a {@code Boolean} class
- * would match a {@code boolean} primitive.
- *
- *
This is a convenient wrapper for
- * {@link #invokeStaticMethod(Class objectClass, String methodName, Object[] args, Class[] parameterTypes)}.
- *
- *
- * @param objectClass invoke static method on this class
- * @param methodName get method with this name
- * @param args use these arguments - treat null as empty array (passing null will
- * result in calling the parameterless method with name {@code methodName}).
- * @return The value returned by the invoked method
- *
- * @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
- * @since 1.8.0
- */
- public static Object invokeStaticMethod(
- final Class> objectClass,
- final String methodName,
- Object[] args)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
- final int arguments = args.length;
- final Class>[] parameterTypes = new Class[arguments];
- for (int i = 0; i < arguments; i++) {
- parameterTypes[i] = args[i].getClass();
- }
- return invokeStaticMethod (objectClass, methodName, args, parameterTypes);
- }
-
- /**
- *
Invoke a named static method whose parameter type matches the object type.
- *
- *
The behavior of this method is less deterministic
- * than {@link
- * #invokeExactStaticMethod(Class objectClass, String methodName, Object[] args, Class[] parameterTypes)}.
- * It loops through all methods with names that match
- * and then executes the first it finds with compatible parameters.
- *
- *
This method supports calls to methods taking primitive parameters
- * via passing in wrapping classes. So, for example, a {@code Boolean} class
- * would match a {@code boolean} primitive.
- *
- *
- * @param objectClass invoke static method on this class
- * @param methodName get method with this name
- * @param args use these arguments - treat null as empty array (passing null will
- * result in calling the parameterless method with name {@code methodName}).
- * @param parameterTypes match these parameters - treat null as empty array
- * @return The value returned by the invoked method
- *
- * @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
- * @since 1.8.0
- */
- public static Object invokeStaticMethod(
- final Class> objectClass,
- final String methodName,
- Object[] args,
- Class>[] parameterTypes)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- if (parameterTypes == null) {
- parameterTypes = EMPTY_CLASS_PARAMETERS;
- }
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
-
- final Method method = getMatchingAccessibleMethod(
- objectClass,
- methodName,
- parameterTypes);
- if (method == null) {
- throw new NoSuchMethodException("No such accessible method: " +
- methodName + "() on class: " + objectClass.getName());
- }
- return method.invoke(null, args);
- }
-
- /**
- *
Invoke a static method whose parameter type matches exactly the object
- * type.
- *
- *
This is a convenient wrapper for
- * {@link #invokeExactStaticMethod(Class objectClass,String methodName,Object [] args)}.
- *
- *
- * @param objectClass invoke static method on this class
- * @param methodName get method with this name
- * @param arg use this argument. May be null (this will result in calling the
- * parameterless method with name {@code methodName}).
- * @return The value returned by the invoked method
- *
- * @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
- * @since 1.8.0
- */
- public static Object invokeExactStaticMethod(
- final Class> objectClass,
- final String methodName,
- final Object arg)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- final Object[] args = toArray(arg);
- return invokeExactStaticMethod (objectClass, methodName, args);
- }
-
- /**
- *
Invoke a static method whose parameter types match exactly the object
- * types.
- *
- *
This uses reflection to invoke the method obtained from a call to
- * {@link #getAccessibleMethod(Class, String, Class[])}.
- *
- * @param objectClass invoke static method on this class
- * @param methodName get method with this name
- * @param args use these arguments - treat null as empty array (passing null will
- * result in calling the parameterless method with name {@code methodName}).
- * @return The value returned by the invoked method
- *
- * @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
- * @since 1.8.0
- */
- public static Object invokeExactStaticMethod(
- final Class> objectClass,
- final String methodName,
- Object[] args)
- throws
- NoSuchMethodException,
- IllegalAccessException,
- InvocationTargetException {
-
- if (args == null) {
- args = EMPTY_OBJECT_ARRAY;
- }
- final int arguments = args.length;
- final Class>[] parameterTypes = new Class[arguments];
- for (int i = 0; i < arguments; i++) {
- parameterTypes[i] = args[i].getClass();
- }
- return invokeExactStaticMethod(objectClass, methodName, args, parameterTypes);
- }
-
- private static Object[] toArray(final Object arg) {
- Object[] args = null;
- if (arg != null) {
- args = new Object[] { arg };
- }
- return args;
- }
-
- /**
- *
Return an accessible method (that is, one that can be invoked via
- * reflection) with given name and a single parameter. If no such method
- * can be found, return {@code null}.
- * Basically, a convenience wrapper that constructs a {@code Class}
- * array for you.
- *
- * @param clazz get method from this class
- * @param methodName get method with this name
- * @param parameterType taking this type of parameter
- * @return The accessible method
- */
- public static Method getAccessibleMethod(
- final Class> clazz,
- final String methodName,
- final Class> parameterType) {
-
- final Class>[] parameterTypes = {parameterType};
- return getAccessibleMethod(clazz, methodName, parameterTypes);
- }
-
- /**
- *
Return an accessible method (that is, one that can be invoked via
- * reflection) with given name and parameters. If no such method
- * can be found, return {@code null}.
- * This is just a convenient wrapper for
- * {@link #getAccessibleMethod(Method method)}.
- *
- * @param clazz get method from this class
- * @param methodName get method with this name
- * @param parameterTypes with these parameters types
- * @return The accessible method
- */
- public static Method getAccessibleMethod(
- final Class> clazz,
- final String methodName,
- final Class>[] parameterTypes) {
-
- try {
- final MethodDescriptor md = new MethodDescriptor(clazz, methodName, parameterTypes, true);
- // Check the cache first
- Method method = getCachedMethod(md);
- if (method != null) {
- return method;
- }
-
- method = getAccessibleMethod
- (clazz, clazz.getMethod(methodName, parameterTypes));
- cacheMethod(md, method);
- return method;
- } catch (final NoSuchMethodException e) {
- return null;
- }
- }
-
- /**
- *
Return an accessible method (that is, one that can be invoked via
- * reflection) that implements the specified Method. If no such method
- * can be found, return {@code null}.
- *
- * @param method The method that we wish to call
- * @return The accessible method
- */
- public static Method getAccessibleMethod(final Method method) {
-
- // Make sure we have a method to check
- if (method == null) {
- return null;
- }
-
- return getAccessibleMethod(method.getDeclaringClass(), method);
- }
-
- /**
- *
Return an accessible method (that is, one that can be invoked via
- * reflection) that implements the specified Method. If no such method
- * can be found, return {@code null}.
- *
- * @param clazz The class of the object
- * @param method The method that we wish to call
- * @return The accessible method
- * @since 1.8.0
- */
- 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())) {
- return null;
- }
-
- boolean sameClass = true;
- if (clazz == null) {
- clazz = method.getDeclaringClass();
- } else {
- if (!method.getDeclaringClass().isAssignableFrom(clazz)) {
- throw new IllegalArgumentException(clazz.getName() +
- " is not assignable from " + method.getDeclaringClass().getName());
- }
- sameClass = clazz.equals(method.getDeclaringClass());
- }
-
- // If the class is public, we are done
- if (Modifier.isPublic(clazz.getModifiers())) {
- if (!sameClass && !Modifier.isPublic(method.getDeclaringClass().getModifiers())) {
- setMethodAccessible(method); // Default access superclass workaround
- }
- return method;
- }
-
- final String methodName = method.getName();
- final Class>[] parameterTypes = method.getParameterTypes();
-
- // Check the implemented interfaces and subinterfaces
- method =
- getAccessibleMethodFromInterfaceNest(clazz,
- methodName,
- parameterTypes);
-
- // Check the superclass chain
- if (method == null) {
- method = getAccessibleMethodFromSuperclass(clazz,
- methodName,
- parameterTypes);
- }
-
- return method;
- }
-
-
-
- /**
- *
Return an accessible method (that is, one that can be invoked via
- * reflection) by scanning through the superclasses. If no such method
- * can be found, return {@code null}.
- *
- * @param clazz Class to be checked
- * @param methodName Method name of the method we wish to call
- * @param parameterTypes The parameter type signatures
- */
- private static Method getAccessibleMethodFromSuperclass
- (final Class> clazz, final String methodName, final Class>[] parameterTypes) {
-
- Class> parentClazz = clazz.getSuperclass();
- while (parentClazz != null) {
- if (Modifier.isPublic(parentClazz.getModifiers())) {
- try {
- return parentClazz.getMethod(methodName, parameterTypes);
- } catch (final NoSuchMethodException e) {
- return null;
- }
- }
- parentClazz = parentClazz.getSuperclass();
- }
- return null;
- }
-
- /**
- *
Return an accessible method (that is, one that can be invoked via
- * reflection) that implements the specified method, by scanning through
- * all implemented interfaces and subinterfaces. If no such method
- * can be found, return {@code null}.
- *
- *
There isn't any good reason why this method must be private.
- * It is because there doesn't seem any reason why other classes should
- * call this rather than the higher level methods.
- *
- * @param clazz Parent class for the interfaces to be checked
- * @param methodName Method name of the method we wish to call
- * @param parameterTypes The parameter type signatures
- */
- private static Method getAccessibleMethodFromInterfaceNest
- (Class> clazz, final String methodName, final Class>[] parameterTypes) {
-
- Method method = null;
-
- // Search up the superclass chain
- for (; clazz != null; clazz = clazz.getSuperclass()) {
-
- // Check the implemented interfaces of the parent class
- final Class>[] interfaces = clazz.getInterfaces();
- for (Class> anInterface : interfaces) {
-
- // Is this interface public?
- if (!Modifier.isPublic(anInterface.getModifiers())) {
- continue;
- }
-
- // Does the method exist on this interface?
- try {
- method = anInterface.getDeclaredMethod(methodName,
- parameterTypes);
- } catch (final NoSuchMethodException e) {
- /* Swallow, if no method is found after the loop then this
- * method returns null.
- */
- }
- if (method != null) {
- return method;
- }
-
- // Recursively check our parent interfaces
- method =
- getAccessibleMethodFromInterfaceNest(anInterface,
- methodName,
- parameterTypes);
- if (method != null) {
- return method;
- }
-
- }
-
- }
-
- // We did not find anything
- return null;
- }
-
- /**
- *
Find an accessible method that matches the given name and has compatible parameters.
- * Compatible parameters mean that every method parameter is assignable from
- * the given parameters.
- * In other words, it finds a method with the given name
- * that will take the parameters given.
- *
- *
This method is slightly indeterministic since it loops
- * through methods names and return the first matching method.
- *
- *
This method is used by
- * {@link
- * #invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)}.
- *
- *
This method can match primitive parameter by passing in wrapper classes.
- * For example, a {@code Boolean
will match a primitive boolean}
- * parameter.
- *
- * @param clazz find method in this class
- * @param methodName find method with this name
- * @param parameterTypes find method with compatible parameters
- * @return The accessible method
- */
- public static Method getMatchingAccessibleMethod(
- final Class> clazz,
- final String methodName,
- final Class>[] parameterTypes) {
- // trace logging
- final Log log = LogFactory.getLog(MethodUtils.class);
- if (log.isTraceEnabled()) {
- log.trace("Matching name=" + methodName + " on " + clazz);
- }
- final MethodDescriptor md = new MethodDescriptor(clazz, methodName, parameterTypes, false);
-
- // see if we can find the method directly
- // most of the time this works and it's much faster
- try {
- // Check the cache first
- Method method = getCachedMethod(md);
- if (method != null) {
- return method;
- }
-
- method = clazz.getMethod(methodName, parameterTypes);
- if (log.isTraceEnabled()) {
- log.trace("Found straight match: " + method);
- log.trace("isPublic:" + Modifier.isPublic(method.getModifiers()));
- }
-
- setMethodAccessible(method); // Default access superclass workaround
-
- cacheMethod(md, method);
- return method;
-
- } catch (final NoSuchMethodException e) { /* SWALLOW */ }
-
- // search through all methods
- final int paramSize = parameterTypes.length;
- Method bestMatch = null;
- final Method[] methods = clazz.getMethods();
- float bestMatchCost = Float.MAX_VALUE;
- float myCost = Float.MAX_VALUE;
- for (final Method method2 : methods) {
- if (method2.getName().equals(methodName)) {
- // log some trace information
- if (log.isTraceEnabled()) {
- log.trace("Found matching name:");
- log.trace(method2);
- }
-
- // compare parameters
- final Class>[] methodsParams = method2.getParameterTypes();
- final int methodParamSize = methodsParams.length;
- if (methodParamSize == paramSize) {
- boolean match = true;
- for (int n = 0 ; n < methodParamSize; n++) {
- if (log.isTraceEnabled()) {
- log.trace("Param=" + parameterTypes[n].getName());
- log.trace("Method=" + methodsParams[n].getName());
- }
- if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) {
- if (log.isTraceEnabled()) {
- log.trace(methodsParams[n] + " is not assignable from "
- + parameterTypes[n]);
- }
- match = false;
- break;
- }
- }
-
- if (match) {
- // get accessible version of method
- final Method method = getAccessibleMethod(clazz, method2);
- if (method != null) {
- if (log.isTraceEnabled()) {
- log.trace(method + " accessible version of "
- + method2);
- }
- setMethodAccessible(method); // Default access superclass workaround
- myCost = getTotalTransformationCost(parameterTypes,method.getParameterTypes());
- if ( myCost < bestMatchCost ) {
- bestMatch = method;
- bestMatchCost = myCost;
- }
- }
-
- log.trace("Couldn't find accessible method.");
- }
- }
- }
- }
- if ( bestMatch != null ){
- cacheMethod(md, bestMatch);
- } else {
- // didn't find a match
- log.trace("No match found.");
- }
-
- return bestMatch;
- }
-
- /**
- * Try to make the method accessible
- * @param method The source arguments
- */
- private static void setMethodAccessible(final Method method) {
- try {
- //
- // XXX Default access superclass workaround
- //
- // When a public class has a default access superclass
- // with public methods, these methods are accessible.
- // Calling them from compiled code works fine.
- //
- // Unfortunately, using reflection to invoke these methods
- // seems to (wrongly) to prevent access even when the method
- // modifier is public.
- //
- // The following workaround solves the problem but will only
- // work from sufficiently privileges code.
- //
- // Better workarounds would be gratefully accepted.
- //
- if (!method.isAccessible()) {
- method.setAccessible(true);
- }
-
- } catch (final SecurityException se) {
- // log but continue just in case the method.invoke works anyway
- final Log log = LogFactory.getLog(MethodUtils.class);
- if (!loggedAccessibleWarning) {
- boolean vulnerableJVM = false;
- try {
- final String specVersion = System.getProperty("java.specification.version");
- if (specVersion.charAt(0) == '1' &&
- (specVersion.charAt(2) == '0' ||
- specVersion.charAt(2) == '1' ||
- specVersion.charAt(2) == '2' ||
- specVersion.charAt(2) == '3')) {
-
- vulnerableJVM = true;
- }
- } catch (final SecurityException e) {
- // don't know - so display warning
- vulnerableJVM = true;
- }
- if (vulnerableJVM) {
- log.warn(
- "Current Security Manager restricts use of workarounds for reflection bugs "
- + " in pre-1.4 JVMs.");
- }
- loggedAccessibleWarning = true;
- }
- log.debug("Cannot setAccessible on method. Therefore cannot use jvm access bug workaround.", se);
- }
- }
-
- /**
- * Returns the sum of the object transformation cost for each class in the source
- * argument list.
- * @param srcArgs The source arguments
- * @param destArgs The destination arguments
- * @return The total transformation cost
- */
- private static float getTotalTransformationCost(final Class>[] srcArgs, final Class>[] destArgs) {
-
- float totalCost = 0.0f;
- for (int i = 0; i < srcArgs.length; i++) {
- Class> srcClass, destClass;
- srcClass = srcArgs[i];
- destClass = destArgs[i];
- totalCost += getObjectTransformationCost(srcClass, destClass);
- }
-
- return totalCost;
- }
-
- /**
- * Gets the number of steps required needed to turn the source class into the
- * destination class. This represents the number of steps in the object hierarchy
- * graph.
- * @param srcClass The source class
- * @param destClass The destination class
- * @return The cost of transforming an object
- */
- private static float getObjectTransformationCost(Class> srcClass, final Class> destClass) {
- float cost = 0.0f;
- while (srcClass != null && !destClass.equals(srcClass)) {
- if (destClass.isPrimitive()) {
- final Class> destClassWrapperClazz = getPrimitiveWrapper(destClass);
- if (destClassWrapperClazz != null && destClassWrapperClazz.equals(srcClass)) {
- cost += 0.25f;
- break;
- }
- }
- if (destClass.isInterface() && isAssignmentCompatible(destClass,srcClass)) {
- // slight penalty for interface match.
- // we still want an exact match to override an interface match, but
- // an interface match should override anything where we have to get a
- // superclass.
- cost += 0.25f;
- break;
- }
- cost++;
- srcClass = srcClass.getSuperclass();
- }
-
- /*
- * If the destination class is null, we've traveled all the way up to
- * an Object match. We'll penalize this by adding 1.5 to the cost.
- */
- if (srcClass == null) {
- cost += 1.5f;
- }
-
- return cost;
- }
-
- /**
- *
Determine whether a type can be used as a parameter in a method invocation.
- * This method handles primitive conversions correctly.
- *
- *
In order words, it will match a {@code Boolean
to a boolean},
- * a {@code Long to a long},
- * a {@code Float to a float},
- * a {@code Integer to a int},
- * and a {@code Double to a double}.
- * Now logic widening matches are allowed.
- * For example, a {@code Long will not match a int}.
- *
- * @param parameterType the type of parameter accepted by the method
- * @param parameterization the type of parameter being tested
- *
- * @return true if the assignment is compatible.
- */
- public static final boolean isAssignmentCompatible(final Class> parameterType, final Class> parameterization) {
- // try plain assignment
- if (parameterType.isAssignableFrom(parameterization)) {
- return true;
- }
-
- if (parameterType.isPrimitive()) {
- // this method does *not* do widening - you must specify exactly
- // is this the right behavior?
- final Class> parameterWrapperClazz = getPrimitiveWrapper(parameterType);
- if (parameterWrapperClazz != null) {
- return parameterWrapperClazz.equals(parameterization);
- }
- }
-
- return false;
- }
-
- /**
- * Gets the wrapper object class for the given primitive type class.
- * For example, passing {@code boolean.class returns Boolean.class}
- * @param primitiveType the primitive type class for which a match is to be found
- * @return the wrapper type associated with the given primitive
- * or null if no match is found
- */
- public static Class> getPrimitiveWrapper(final Class> primitiveType) {
- // does anyone know a better strategy than comparing names?
- if (boolean.class.equals(primitiveType)) {
- return Boolean.class;
- } else if (float.class.equals(primitiveType)) {
- return Float.class;
- } else if (long.class.equals(primitiveType)) {
- return Long.class;
- } else if (int.class.equals(primitiveType)) {
- return Integer.class;
- } else if (short.class.equals(primitiveType)) {
- return Short.class;
- } else if (byte.class.equals(primitiveType)) {
- return Byte.class;
- } else if (double.class.equals(primitiveType)) {
- return Double.class;
- } else if (char.class.equals(primitiveType)) {
- return Character.class;
- } else {
-
- return null;
- }
- }
-
- /**
- * Gets the class for the primitive type corresponding to the primitive wrapper class given.
- * For example, an instance of {@code Boolean.class returns a boolean.class}.
- * @param wrapperType the
- * @return the primitive type class corresponding to the given wrapper class,
- * null if no match is found
- */
- public static Class> getPrimitiveType(final Class> wrapperType) {
- // does anyone know a better strategy than comparing names?
- if (Boolean.class.equals(wrapperType)) {
- return boolean.class;
- } else if (Float.class.equals(wrapperType)) {
- return float.class;
- } else if (Long.class.equals(wrapperType)) {
- return long.class;
- } else if (Integer.class.equals(wrapperType)) {
- return int.class;
- } else if (Short.class.equals(wrapperType)) {
- return short.class;
- } else if (Byte.class.equals(wrapperType)) {
- return byte.class;
- } else if (Double.class.equals(wrapperType)) {
- return double.class;
- } else if (Character.class.equals(wrapperType)) {
- return char.class;
- } else {
- final Log log = LogFactory.getLog(MethodUtils.class);
- if (log.isDebugEnabled()) {
- log.debug("Not a known primitive wrapper class: " + wrapperType);
- }
- return null;
- }
- }
-
- /**
- * Find a non primitive representation for given primitive class.
- *
- * @param clazz the class to find a representation for, not null
- * @return the original class if it not a primitive. Otherwise the wrapper class. Not null
- */
- public static Class> toNonPrimitiveClass(final Class> clazz) {
- if (clazz.isPrimitive()) {
- final Class> primitiveClazz = MethodUtils.getPrimitiveWrapper(clazz);
- // the above method returns
- if (primitiveClazz != null) {
- return primitiveClazz;
- }
- return clazz;
- }
- return clazz;
- }
-
- /**
- * Return the method from the cache, if present.
- *
- * @param md The method descriptor
- * @return The cached method
- */
- private static Method getCachedMethod(final MethodDescriptor md) {
- if (CACHE_METHODS) {
- final Reference methodRef = cache.get(md);
- if (methodRef != null) {
- return methodRef.get();
- }
- }
- return null;
- }
-
- /**
- * Add a method to the cache.
- *
- * @param md The method descriptor
- * @param method The method to cache
- */
- private static void cacheMethod(final MethodDescriptor md, final Method method) {
- if (CACHE_METHODS) {
- if (method != null) {
- cache.put(md, new WeakReference<>(method));
- }
- }
- }
-
- /**
- * Represents the key to looking up a Method by reflection.
- */
- private static class MethodDescriptor {
- private final Class> cls;
- private final String methodName;
- private final Class>[] paramTypes;
- private final boolean exact;
- private final int hashCode;
-
- /**
- * The sole constructor.
- *
- * @param cls the class to reflect, must not be null
- * @param methodName the method name to obtain
- * @param paramTypes the array of classes representing the parameter types
- * @param exact whether the match has to be exact.
- */
- public MethodDescriptor(final Class> cls, final String methodName, Class>[] paramTypes, final boolean exact) {
- if (cls == null) {
- throw new IllegalArgumentException("Class cannot be null");
- }
- if (methodName == null) {
- throw new IllegalArgumentException("Method Name cannot be null");
- }
- if (paramTypes == null) {
- paramTypes = EMPTY_CLASS_PARAMETERS;
- }
-
- this.cls = cls;
- this.methodName = methodName;
- this.paramTypes = paramTypes;
- this.exact= exact;
-
- this.hashCode = methodName.length();
- }
- /**
- * Checks for equality.
- * @param obj object to be tested for equality
- * @return true, if the object describes the same Method.
- */
- @Override
- public boolean equals(final Object obj) {
- if (!(obj instanceof MethodDescriptor)) {
- return false;
- }
- final MethodDescriptor md = (MethodDescriptor)obj;
-
- return exact == md.exact &&
- methodName.equals(md.methodName) &&
- cls.equals(md.cls) &&
- java.util.Arrays.equals(paramTypes, md.paramTypes);
- }
- /**
- * Returns the string length of method name. I.e. if the
- * hashcodes are different, the objects are different. If the
- * hashcodes are the same, need to use the equals method to
- * determine equality.
- * @return the string length of method name.
- */
- @Override
- public int hashCode() {
- return hashCode;
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/MutableDynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/MutableDynaClass.java
deleted file mode 100644
index 9380cac70..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/MutableDynaClass.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- *
A specialized extension to {@code DynaClass} that allows properties
- * to be added or removed dynamically.
- *
- *
WARNING - No guarantees that this will be in the final
- * APIs ... it's here primarily to preserve some concepts that were in the
- * original proposal for further discussion.
- *
- */
-
-public interface MutableDynaClass extends DynaClass {
-
- /**
- * Add a new dynamic property with no restrictions on data type,
- * readability, or writeability.
- *
- * @param name Name of the new dynamic property
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no new properties can be added
- */
- void add(String name);
-
- /**
- * Add a new dynamic property with the specified data type, but with
- * no restrictions on readability or writeability.
- *
- * @param name Name of the new dynamic property
- * @param type Data type of the new dynamic property (null for no
- * restrictions)
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no new properties can be added
- */
- void add(String name, Class> type);
-
- /**
- * Add a new dynamic property with the specified data type, readability,
- * and writeability.
- *
- * @param name Name of the new dynamic property
- * @param type Data type of the new dynamic property (null for no
- * restrictions)
- * @param readable Set to {@code true} if this property value
- * should be readable
- * @param writeable Set to {@code true} if this property value
- * should be writeable
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no new properties can be added
- */
- void add(String name, Class> type, boolean readable,
- boolean writeable);
-
- /**
- * Is this DynaClass currently restricted, if so, no changes to the
- * existing registration of property names, data types, readability, or
- * writeability are allowed.
- *
- * @return {@code true} if this Mutable {@link DynaClass} is restricted,
- * otherwise {@code false}
- */
- boolean isRestricted();
-
- /**
- * Remove the specified dynamic property, and any associated data type,
- * readability, and writeability, from this dynamic class.
- * NOTE - This does NOT cause any
- * corresponding property values to be removed from DynaBean instances
- * associated with this DynaClass.
- *
- * @param name Name of the dynamic property to remove
- *
- * @throws IllegalArgumentException if name is null
- * @throws IllegalStateException if this DynaClass is currently
- * restricted, so no properties can be removed
- */
- void remove(String name);
-
- /**
- * Set the restricted state of this DynaClass to the specified value.
- *
- * @param restricted The new restricted state
- */
- void setRestricted(boolean restricted);
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/NestedNullException.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/NestedNullException.java
deleted file mode 100644
index 61c71aed9..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/NestedNullException.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- * Thrown to indicate that the Bean Access Language cannot execute query
- * against given bean since a nested bean referenced is null.
- *
- * @since 1.7
- */
-
-public class NestedNullException extends BeanAccessLanguageException {
-
- private static final long serialVersionUID = 1L;
-
-
-
- /**
- * Constructs a {@code NestedNullException} without a detail message.
- */
- public NestedNullException() {
- super();
- }
-
- /**
- * Constructs a {@code NestedNullException} without a detail message.
- *
- * @param message the detail message explaining this exception
- */
- public NestedNullException(final String message) {
- super(message);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/PropertyUtils.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/PropertyUtils.java
deleted file mode 100644
index 20b800fa1..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/PropertyUtils.java
+++ /dev/null
@@ -1,824 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.commons.beanutils2;
-
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Map;
-
-
-/**
- *
Utility methods for using Java Reflection APIs to facilitate generic
- * property getter and setter operations on Java objects.
- *
- *
The implementations for these methods are provided by {@code PropertyUtilsBean}.
- * For more details see {@link PropertyUtilsBean}.
- *
- * @see PropertyUtilsBean
- * @see org.apache.commons.beanutils2.expression.Resolver
- */
-
-public class PropertyUtils {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /**
- * Clear any cached property descriptors information for all classes
- * loaded by any class loaders. This is useful in cases where class
- * loaders are thrown away to implement class reloading.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @see PropertyUtilsBean#clearDescriptors
- */
- public static void clearDescriptors() {
-
- PropertyUtilsBean.getInstance().clearDescriptors();
-
- }
-
- /**
- * Resets the registered {@link BeanIntrospector} objects to the initial default
- * state.
- *
- * @since 1.9
- */
- public static void resetBeanIntrospectors() {
- PropertyUtilsBean.getInstance().resetBeanIntrospectors();
- }
-
- /**
- * Adds a {@code BeanIntrospector}. This object is invoked when the
- * property descriptors of a class need to be obtained.
- *
- * @param introspector the {@code BeanIntrospector} to be added (must
- * not be null
- * @throws IllegalArgumentException if the argument is null
- * @since 1.9
- */
- public static void addBeanIntrospector(final BeanIntrospector introspector) {
- PropertyUtilsBean.getInstance().addBeanIntrospector(introspector);
- }
-
- /**
- * Removes the specified {@code BeanIntrospector}.
- *
- * @param introspector the {@code BeanIntrospector} to be removed
- * @return true if the {@code BeanIntrospector} existed and
- * could be removed, false otherwise
- * @since 1.9
- */
- public static boolean removeBeanIntrospector(final BeanIntrospector introspector) {
- return PropertyUtilsBean.getInstance().removeBeanIntrospector(
- introspector);
- }
-
- /**
- *
Copy property values from the "origin" bean to the "destination" bean
- * for all cases where the property names are the same (even though the
- * actual getter and setter methods might have been customized via
- * {@code BeanInfo} classes).
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param dest Destination bean whose properties are modified
- * @param orig Origin bean whose properties are retrieved
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if the {@code dest} or
- * {@code orig} argument is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#copyProperties
- */
- public static void copyProperties(final Object dest, final Object orig)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().copyProperties(dest, orig);
- }
-
-
- /**
- *
Return the entire set of properties for which the specified bean
- * provides a read method.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose properties are to be extracted
- * @return The set of properties for the bean
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#describe
- */
- public static Map describe(final Object bean)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().describe(bean);
-
- }
-
-
- /**
- *
Return the value of the specified indexed property of the specified
- * bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname[index]} of the property value
- * to be extracted
- * @return the indexed property value
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getIndexedProperty(Object,String)
- */
- public static Object getIndexedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getIndexedProperty(bean, name);
-
- }
-
-
- /**
- *
Return the value of the specified indexed property of the specified
- * bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param index Index of the property value to be extracted
- * @return the indexed property value
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getIndexedProperty(Object,String, int)
- */
- public static Object getIndexedProperty(final Object bean,
- final String name, final int index)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getIndexedProperty(bean, name, index);
- }
-
-
- /**
- *
Return the value of the specified mapped property of the
- * specified bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname(key)} of the property value
- * to be extracted
- * @return the mapped property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getMappedProperty(Object,String)
- */
- public static Object getMappedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getMappedProperty(bean, name);
-
- }
-
-
- /**
- *
Return the value of the specified mapped property of the specified
- * bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Mapped property name of the property value to be extracted
- * @param key Key of the property value to be extracted
- * @return the mapped property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getMappedProperty(Object,String, String)
- */
- public static Object getMappedProperty(final Object bean,
- final String name, final String key)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getMappedProperty(bean, name, key);
-
- }
-
-
- /**
- *
Return the mapped property descriptors for this bean class.
Return the value of the (possibly nested) property of the specified
- * name, for the specified bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly nested name of the property to be extracted
- * @return the nested property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws NestedNullException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException
- * if the property accessor method throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getNestedProperty
- */
- public static Object getNestedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getNestedProperty(bean, name);
-
- }
-
-
- /**
- *
Return the value of the specified property of the specified bean,
- * no matter which property reference format is used, with no
- * type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly indexed and/or nested name of the property
- * to be extracted
- * @return the property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getProperty
- */
- public static Object getProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getProperty(bean, name);
-
- }
-
-
- /**
- *
Retrieve the property descriptor for the specified property of the
- * specified bean, or return {@code null} if there is no such
- * descriptor.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean for which a property descriptor is requested
- * @param name Possibly indexed and/or nested name of the property for
- * which a property descriptor is requested
- * @return the property descriptor
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getPropertyDescriptor
- */
- public static PropertyDescriptor getPropertyDescriptor(final Object bean,
- final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getPropertyDescriptor(bean, name);
-
- }
-
-
- /**
- *
Retrieve the property descriptors for the specified class,
- * introspecting and caching them the first time a particular bean class
- * is encountered.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param beanClass Bean class for which property descriptors are requested
- * @return the property descriptors
- * @throws IllegalArgumentException if {@code beanClass} is null
- * @see PropertyUtilsBean#getPropertyDescriptors(Class)
- */
- public static PropertyDescriptor[]
- getPropertyDescriptors(final Class> beanClass) {
-
- return PropertyUtilsBean.getInstance().getPropertyDescriptors(beanClass);
-
- }
-
-
- /**
- *
Retrieve the property descriptors for the specified bean,
- * introspecting and caching them the first time a particular bean class
- * is encountered.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean for which property descriptors are requested
- * @return the property descriptors
- * @throws IllegalArgumentException if {@code bean} is null
- * @see PropertyUtilsBean#getPropertyDescriptors(Object)
- */
- public static PropertyDescriptor[] getPropertyDescriptors(final Object bean) {
-
- return PropertyUtilsBean.getInstance().getPropertyDescriptors(bean);
-
- }
-
-
- /**
- *
Return the Java Class representing the property editor class that has
- * been registered for this property (if any).
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean for which a property descriptor is requested
- * @param name Possibly indexed and/or nested name of the property for
- * which a property descriptor is requested
- * @return the property editor class
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getPropertyEditorClass(Object,String)
- */
- public static Class> getPropertyEditorClass(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getPropertyEditorClass(bean, name);
-
- }
-
-
- /**
- *
Return the Java Class representing the property type of the specified
- * property, or {@code null} if there is no such property for the
- * specified bean.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean for which a property descriptor is requested
- * @param name Possibly indexed and/or nested name of the property for
- * which a property descriptor is requested
- * @return The property type
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getPropertyType(Object, String)
- */
- public static Class> getPropertyType(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getPropertyType(bean, name);
- }
-
-
- /**
- *
Return an accessible property getter method for this property,
- * if there is one; otherwise return {@code null}.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param descriptor Property descriptor to return a getter for
- * @return The read method
- * @see PropertyUtilsBean#getReadMethod(PropertyDescriptor)
- */
- public static Method getReadMethod(final PropertyDescriptor descriptor) {
-
- return PropertyUtilsBean.getInstance().getReadMethod(descriptor);
-
- }
-
-
- /**
- *
Return the value of the specified simple property of the specified
- * bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Name of the property to be extracted
- * @return The property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if the property name
- * is nested or indexed
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#getSimpleProperty
- */
- public static Object getSimpleProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return PropertyUtilsBean.getInstance().getSimpleProperty(bean, name);
-
- }
-
-
- /**
- *
Return an accessible property setter method for this property,
- * if there is one; otherwise return {@code null}.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param descriptor Property descriptor to return a setter for
- * @return The write method
- * @see PropertyUtilsBean#getWriteMethod(PropertyDescriptor)
- */
- public static Method getWriteMethod(final PropertyDescriptor descriptor) {
-
- return PropertyUtilsBean.getInstance().getWriteMethod(descriptor);
-
- }
-
-
- /**
- *
Return {@code true} if the specified property name identifies
- * a readable property on the specified bean; otherwise, return
- * {@code false}.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean to be examined (may be a {@link DynaBean}
- * @param name Property name to be evaluated
- * @return {@code true} if the property is readable,
- * otherwise {@code false}
- *
- * @throws IllegalArgumentException if {@code bean}
- * or {@code name is null}
- * @see PropertyUtilsBean#isReadable
- * @since BeanUtils 1.6
- */
- public static boolean isReadable(final Object bean, final String name) {
-
- return PropertyUtilsBean.getInstance().isReadable(bean, name);
- }
-
-
- /**
- *
Return {@code true} if the specified property name identifies
- * a writeable property on the specified bean; otherwise, return
- * {@code false}.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean to be examined (may be a {@link DynaBean}
- * @param name Property name to be evaluated
- * @return {@code true} if the property is writeable,
- * otherwise {@code false}
- *
- * @throws IllegalArgumentException if {@code bean}
- * or {@code name is null}
- * @see PropertyUtilsBean#isWriteable
- * @since BeanUtils 1.6
- */
- public static boolean isWriteable(final Object bean, final String name) {
-
- return PropertyUtilsBean.getInstance().isWriteable(bean, name);
- }
-
-
- /**
- *
Sets the value of the specified indexed property of the specified
- * bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be modified
- * @param name {@code propertyname[index]} of the property value
- * to be modified
- * @param value Value to which the specified property element
- * should be set
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#setIndexedProperty(Object, String, Object)
- */
- public static void setIndexedProperty(final Object bean, final String name,
- final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setIndexedProperty(bean, name, value);
-
- }
-
-
- /**
- *
Sets the value of the specified indexed property of the specified
- * bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be set
- * @param name Simple property name of the property value to be set
- * @param index Index of the property value to be set
- * @param value Value to which the indexed property element is to be set
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#setIndexedProperty(Object, String, Object)
- */
- public static void setIndexedProperty(final Object bean, final String name,
- final int index, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setIndexedProperty(bean, name, index, value);
- }
-
-
- /**
- *
Sets the value of the specified mapped property of the
- * specified bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be set
- * @param name {@code propertyname(key)} of the property value
- * to be set
- * @param value The property value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#setMappedProperty(Object, String, Object)
- */
- public static void setMappedProperty(final Object bean, final String name,
- final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setMappedProperty(bean, name, value);
- }
-
-
- /**
- *
Sets the value of the specified mapped property of the specified
- * bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be set
- * @param name Mapped property name of the property value to be set
- * @param key Key of the property value to be set
- * @param value The property value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#setMappedProperty(Object, String, String, Object)
- */
- public static void setMappedProperty(final Object bean, final String name,
- final String key, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setMappedProperty(bean, name, key, value);
- }
-
-
- /**
- *
Sets the value of the (possibly nested) property of the specified
- * name, for the specified bean, with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be modified
- * @param name Possibly nested name of the property to be modified
- * @param value Value to which the property is to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#setNestedProperty
- */
- public static void setNestedProperty(final Object bean,
- final String name, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setNestedProperty(bean, name, value);
- }
-
-
- /**
- *
Set the value of the specified property of the specified bean,
- * no matter which property reference format is used, with no
- * type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be modified
- * @param name Possibly indexed and/or nested name of the property
- * to be modified
- * @param value Value to which this property is to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#setProperty
- */
- public static void setProperty(final Object bean, final String name, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setProperty(bean, name, value);
-
- }
-
-
- /**
- *
Set the value of the specified simple property of the specified bean,
- * with no type conversions.
- *
- *
For more details see {@code PropertyUtilsBean}.
- *
- * @param bean Bean whose property is to be modified
- * @param name Name of the property to be modified
- * @param value Value to which the property should be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if the property name is
- * nested or indexed
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- * @see PropertyUtilsBean#setSimpleProperty
- */
- public static void setSimpleProperty(final Object bean,
- final String name, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- PropertyUtilsBean.getInstance().setSimpleProperty(bean, name, value);
- }
-
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java
deleted file mode 100644
index fb12188cb..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/PropertyUtilsBean.java
+++ /dev/null
@@ -1,2179 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.beans.IndexedPropertyDescriptor;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.apache.commons.beanutils2.expression.DefaultResolver;
-import org.apache.commons.beanutils2.expression.Resolver;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Utility methods for using Java Reflection APIs to facilitate generic
- * property getter and setter operations on Java objects. Much of this
- * code was originally included in {@code BeanUtils}, but has been
- * separated because of the volume of code involved.
- *
- * In general, the objects that are examined and modified using these
- * methods are expected to conform to the property getter and setter method
- * naming conventions described in the JavaBeans Specification (Version 1.0.1).
- * No data type conversions are performed, and there are no usage of any
- * {@code PropertyEditor} classes that have been registered, although
- * a convenient way to access the registered classes themselves is included.
- *
- * For the purposes of this class, five formats for referencing a particular
- * property value of a bean are defined, with the default layout of an
- * identifying String in parentheses. However the notation for these formats
- * and how they are resolved is now (since BeanUtils 1.8.0) controlled by
- * the configured {@link Resolver} implementation:
- *
- *
Simple ({@code name}) - The specified
- * {@code name} identifies an individual property of a particular
- * JavaBean. The name of the actual getter or setter method to be used
- * is determined using standard JavaBeans introspection, so that (unless
- * overridden by a {@code BeanInfo} class, a property named "xyz"
- * will have a getter method named {@code getXyz()} or (for boolean
- * properties only) {@code isXyz()}, and a setter method named
- * {@code setXyz()}.
- *
Nested ({@code name1.name2.name3}) The first
- * name element is used to select a property getter, as for simple
- * references above. The object returned for this property is then
- * consulted, using the same approach, for a property getter for a
- * property named {@code name2}, and so on. The property value that
- * is ultimately retrieved or modified is the one identified by the
- * last name element.
- *
Indexed ({@code name[index]}) - The underlying
- * property value is assumed to be an array, or this JavaBean is assumed
- * to have indexed property getter and setter methods. The appropriate
- * (zero-relative) entry in the array is selected. {@code List}
- * objects are now also supported for read/write. You simply need to define
- * a getter that returns the {@code List}
- *
Mapped ({@code name(key)}) - The JavaBean
- * is assumed to have an property getter and setter methods with an
- * additional attribute of type {@code java.lang.String}.
- *
Combined ({@code name1.name2[index].name3(key)}) -
- * Combining mapped, nested, and indexed references is also
- * supported.
- *
- *
- * @see Resolver
- * @see PropertyUtils
- * @since 1.7
- */
-
-public class PropertyUtilsBean {
-
- private Resolver resolver = new DefaultResolver();
-
-
-
- /**
- * Return the PropertyUtils bean instance.
- * @return The PropertyUtils bean instance
- */
- protected static PropertyUtilsBean getInstance() {
- return BeanUtilsBean.getInstance().getPropertyUtils();
- }
-
-
-
- /**
- * The cache of PropertyDescriptor arrays for beans we have already
- * introspected, keyed by the java.lang.Class of this object.
- */
- private WeakFastHashMap, BeanIntrospectionData> descriptorsCache = null;
- private WeakFastHashMap, Map> mappedDescriptorsCache = null;
-
- /** An empty object array */
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
-
- /** Log instance */
- private final Log log = LogFactory.getLog(PropertyUtilsBean.class);
-
- /** The list with BeanIntrospector objects. */
- private final List introspectors;
-
-
-
- /** Base constructor */
- public PropertyUtilsBean() {
- descriptorsCache = new WeakFastHashMap<>();
- descriptorsCache.setFast(true);
- mappedDescriptorsCache = new WeakFastHashMap<>();
- mappedDescriptorsCache.setFast(true);
- introspectors = new CopyOnWriteArrayList<>();
- resetBeanIntrospectors();
- }
-
-
-
- /**
- * Return the configured {@link Resolver} implementation used by BeanUtils.
- *
- * The {@link Resolver} handles the property name
- * expressions and the implementation in use effectively
- * controls the dialect of the expression language
- * that BeanUtils recognizes.
- *
- * {@link DefaultResolver} is the default implementation used.
- *
- * @return resolver The property expression resolver.
- * @since 1.8.0
- */
- public Resolver getResolver() {
- return resolver;
- }
-
- /**
- * Configure the {@link Resolver} implementation used by BeanUtils.
- *
- * The {@link Resolver} handles the property name
- * expressions and the implementation in use effectively
- * controls the dialect of the expression language
- * that BeanUtils recognizes.
- *
- * {@link DefaultResolver} is the default implementation used.
- *
- * @param resolver The property expression resolver.
- * @since 1.8.0
- */
- public void setResolver(final Resolver resolver) {
- if (resolver == null) {
- this.resolver = new DefaultResolver();
- } else {
- this.resolver = resolver;
- }
- }
-
- /**
- * Resets the {@link BeanIntrospector} objects registered at this instance. After this
- * method was called, only the default {@code BeanIntrospector} is registered.
- *
- * @since 1.9
- */
- public final void resetBeanIntrospectors() {
- introspectors.clear();
- introspectors.add(DefaultBeanIntrospector.INSTANCE);
- introspectors.add(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
- }
-
- /**
- * Adds a {@code BeanIntrospector}. This object is invoked when the
- * property descriptors of a class need to be obtained.
- *
- * @param introspector the {@code BeanIntrospector} to be added (must
- * not be null
- * @throws IllegalArgumentException if the argument is null
- * @since 1.9
- */
- public void addBeanIntrospector(final BeanIntrospector introspector) {
- if (introspector == null) {
- throw new IllegalArgumentException(
- "BeanIntrospector must not be null!");
- }
- introspectors.add(introspector);
- }
-
- /**
- * Removes the specified {@code BeanIntrospector}.
- *
- * @param introspector the {@code BeanIntrospector} to be removed
- * @return true if the {@code BeanIntrospector} existed and
- * could be removed, false otherwise
- * @since 1.9
- */
- public boolean removeBeanIntrospector(final BeanIntrospector introspector) {
- return introspectors.remove(introspector);
- }
-
- /**
- * Clear any cached property descriptors information for all classes
- * loaded by any class loaders. This is useful in cases where class
- * loaders are thrown away to implement class reloading.
- */
- public void clearDescriptors() {
-
- descriptorsCache.clear();
- mappedDescriptorsCache.clear();
- Introspector.flushCaches();
-
- }
-
- /**
- *
Copy property values from the "origin" bean to the "destination" bean
- * for all cases where the property names are the same (even though the
- * actual getter and setter methods might have been customized via
- * {@code BeanInfo} classes). No conversions are performed on the
- * actual property values -- it is assumed that the values retrieved from
- * the origin bean are assignment-compatible with the types expected by
- * the destination bean.
- *
- *
If the origin "bean" is actually a {@code Map}, it is assumed
- * to contain String-valued simple property names as the keys, pointing
- * at the corresponding property values that will be set in the destination
- * bean.Note that this method is intended to perform
- * a "shallow copy" of the properties and so complex properties
- * (for example, nested ones) will not be copied.
- *
- *
Note, that this method will not copy a List to a List, or an Object[]
- * to an Object[]. It's specifically for copying JavaBean properties.
- *
- * @param dest Destination bean whose properties are modified
- * @param orig Origin bean whose properties are retrieved
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if the {@code dest} or
- * {@code orig} argument is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public void copyProperties(final Object dest, final Object orig)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- if (dest == null) {
- throw new IllegalArgumentException
- ("No destination bean specified");
- }
- if (orig == null) {
- throw new IllegalArgumentException("No origin bean specified");
- }
-
- if (orig instanceof DynaBean) {
- final DynaProperty[] origDescriptors =
- ((DynaBean) orig).getDynaClass().getDynaProperties();
- for (final DynaProperty origDescriptor : origDescriptors) {
- final String name = origDescriptor.getName();
- if (isReadable(orig, name) && isWriteable(dest, name)) {
- try {
- final Object value = ((DynaBean) orig).get(name);
- if (dest instanceof DynaBean) {
- ((DynaBean) dest).set(name, value);
- } else {
- setSimpleProperty(dest, name, value);
- }
- } catch (final NoSuchMethodException e) {
- if (log.isDebugEnabled()) {
- log.debug("Error writing to '" + name + "' on class '" + dest.getClass() + "'", e);
- }
- }
- }
- }
- } else if (orig instanceof Map) {
- for (final Map.Entry, ?> entry : ((Map, ?>) orig).entrySet()) {
- final String name = (String)entry.getKey();
- if (isWriteable(dest, name)) {
- try {
- if (dest instanceof DynaBean) {
- ((DynaBean) dest).set(name, entry.getValue());
- } else {
- setSimpleProperty(dest, name, entry.getValue());
- }
- } catch (final NoSuchMethodException e) {
- if (log.isDebugEnabled()) {
- log.debug("Error writing to '" + name + "' on class '" + dest.getClass() + "'", e);
- }
- }
- }
- }
- } else /* if (orig is a standard JavaBean) */ {
- final PropertyDescriptor[] origDescriptors =
- getPropertyDescriptors(orig);
- for (final PropertyDescriptor origDescriptor : origDescriptors) {
- final String name = origDescriptor.getName();
- if (isReadable(orig, name) && isWriteable(dest, name)) {
- try {
- final Object value = getSimpleProperty(orig, name);
- if (dest instanceof DynaBean) {
- ((DynaBean) dest).set(name, value);
- } else {
- setSimpleProperty(dest, name, value);
- }
- } catch (final NoSuchMethodException e) {
- if (log.isDebugEnabled()) {
- log.debug("Error writing to '" + name + "' on class '" + dest.getClass() + "'", e);
- }
- }
- }
- }
- }
-
- }
-
- /**
- *
Return the entire set of properties for which the specified bean
- * provides a read method. This map contains the unconverted property
- * values for all properties for which a read method is provided
- * (i.e. where the {@code getReadMethod()} returns non-null).
- *
- *
FIXME - Does not account for mapped properties.
- *
- * @param bean Bean whose properties are to be extracted
- * @return The set of properties for the bean
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public Map describe(final Object bean)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- if (bean == null) {
- throw new IllegalArgumentException("No bean specified");
- }
- final Map description = new HashMap<>();
- if (bean instanceof DynaBean) {
- final DynaProperty[] descriptors =
- ((DynaBean) bean).getDynaClass().getDynaProperties();
- for (final DynaProperty descriptor : descriptors) {
- final String name = descriptor.getName();
- description.put(name, getProperty(bean, name));
- }
- } else {
- final PropertyDescriptor[] descriptors =
- getPropertyDescriptors(bean);
- for (final PropertyDescriptor descriptor : descriptors) {
- final String name = descriptor.getName();
- if (descriptor.getReadMethod() != null) {
- description.put(name, getProperty(bean, name));
- }
- }
- }
- return description;
-
- }
-
- /**
- * Return the value of the specified indexed property of the specified
- * bean, with no type conversions. The zero-relative index of the
- * required value must be included (in square brackets) as a suffix to
- * the property name, or {@code IllegalArgumentException} will be
- * thrown. In addition to supporting the JavaBeans specification, this
- * method has been extended to support {@code List} objects as well.
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname[index]} of the property value
- * to be extracted
- * @return the indexed property value
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying array or List
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public Object getIndexedProperty(final Object bean, 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() + "'");
- }
-
- // Identify the index of the requested individual property
- int index = -1;
- try {
- index = resolver.getIndex(name);
- } catch (final IllegalArgumentException e) {
- throw new IllegalArgumentException("Invalid indexed property '" +
- name + "' on bean class '" + bean.getClass() + "' " +
- e.getMessage());
- }
- if (index < 0) {
- throw new IllegalArgumentException("Invalid indexed property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
-
- // Isolate the name
- name = resolver.getProperty(name);
-
- // Request the specified indexed property value
- return getIndexedProperty(bean, name, index);
-
- }
-
- /**
- * Return the value of the specified indexed property of the specified
- * bean, with no type conversions. In addition to supporting the JavaBeans
- * specification, this method has been extended to support
- * {@code List} objects as well.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param index Index of the property value to be extracted
- * @return the indexed property value
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public Object getIndexedProperty(final Object bean,
- final String name, final int index)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- if (bean == null) {
- throw new IllegalArgumentException("No bean specified");
- }
- if (name == null || name.length() == 0) {
- if (bean.getClass().isArray()) {
- return Array.get(bean, index);
- } else if (bean instanceof List) {
- return ((List>)bean).get(index);
- }
- }
- if (name == null) {
- throw new IllegalArgumentException("No name specified for bean class '" +
- bean.getClass() + "'");
- }
-
- // Handle DynaBean instances specially
- if (bean instanceof DynaBean) {
- final DynaProperty descriptor =
- ((DynaBean) bean).getDynaClass().getDynaProperty(name);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
- return ((DynaBean) bean).get(name, index);
- }
-
- // Retrieve the property descriptor for the specified property
- final PropertyDescriptor descriptor =
- getPropertyDescriptor(bean, name);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
-
- // Call the indexed getter method if there is one
- if (descriptor instanceof IndexedPropertyDescriptor) {
- Method readMethod = ((IndexedPropertyDescriptor) descriptor).
- getIndexedReadMethod();
- readMethod = MethodUtils.getAccessibleMethod(bean.getClass(), readMethod);
- if (readMethod != null) {
- final Object[] subscript = new Object[1];
- subscript[0] = Integer.valueOf(index);
- try {
- return invokeMethod(readMethod,bean, subscript);
- } catch (final InvocationTargetException e) {
- if (e.getTargetException() instanceof
- IndexOutOfBoundsException) {
- throw (IndexOutOfBoundsException)
- e.getTargetException();
- }
- throw e;
- }
- }
- }
-
- // Otherwise, the underlying property must be an array
- final Method readMethod = getReadMethod(bean.getClass(), descriptor);
- if (readMethod == null) {
- throw new NoSuchMethodException("Property '" + name + "' has no " +
- "getter method on bean class '" + bean.getClass() + "'");
- }
-
- // Call the property getter and return the value
- final Object value = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
- if (!value.getClass().isArray()) {
- if (!(value instanceof java.util.List)) {
- throw new IllegalArgumentException("Property '" + name +
- "' is not indexed on bean class '" + bean.getClass() + "'");
- }
- //get the List's value
- return ((java.util.List>) value).get(index);
- }
- //get the array's value
- try {
- return Array.get(value, index);
- } catch (final ArrayIndexOutOfBoundsException e) {
- throw new ArrayIndexOutOfBoundsException("Index: " +
- index + ", Size: " + Array.getLength(value) +
- " for property '" + name + "'");
- }
-
- }
-
- /**
- * Return the value of the specified mapped property of the
- * specified bean, with no type conversions. The key of the
- * required value must be included (in brackets) as a suffix to
- * the property name, or {@code IllegalArgumentException} will be
- * thrown.
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname(key)} of the property value
- * to be extracted
- * @return the mapped property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public Object getMappedProperty(final Object bean, 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() + "'");
- }
-
- // Identify the key of the requested individual property
- String key = null;
- try {
- key = resolver.getKey(name);
- } catch (final IllegalArgumentException e) {
- throw new IllegalArgumentException
- ("Invalid mapped property '" + name +
- "' on bean class '" + bean.getClass() + "' " + e.getMessage());
- }
- if (key == null) {
- throw new IllegalArgumentException("Invalid mapped property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
-
- // Isolate the name
- name = resolver.getProperty(name);
-
- // Request the specified indexed property value
- return getMappedProperty(bean, name, key);
-
- }
-
- /**
- * Return the value of the specified mapped property of the specified
- * bean, with no type conversions.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Mapped property name of the property value to be extracted
- * @param key Key of the property value to be extracted
- * @return the mapped property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public Object getMappedProperty(final Object bean,
- final String name, final String key)
- 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() + "'");
- }
- if (key == null) {
- throw new IllegalArgumentException("No key specified for property '" +
- name + "' on bean class " + bean.getClass() + "'");
- }
-
- // Handle DynaBean instances specially
- if (bean instanceof DynaBean) {
- final DynaProperty descriptor =
- ((DynaBean) bean).getDynaClass().getDynaProperty(name);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "'+ on bean class '" + bean.getClass() + "'");
- }
- return ((DynaBean) bean).get(name, key);
- }
-
- Object result = null;
-
- // Retrieve the property descriptor for the specified property
- final PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "'+ on bean class '" + bean.getClass() + "'");
- }
-
- if (descriptor instanceof MappedPropertyDescriptor) {
- // Call the keyed getter method if there is one
- Method readMethod = ((MappedPropertyDescriptor) descriptor).
- getMappedReadMethod();
- readMethod = MethodUtils.getAccessibleMethod(bean.getClass(), readMethod);
- if (readMethod != null) {
- final Object[] keyArray = new Object[1];
- keyArray[0] = key;
- result = invokeMethod(readMethod, bean, keyArray);
- } else {
- throw new NoSuchMethodException("Property '" + name +
- "' has no mapped getter method on bean class '" +
- bean.getClass() + "'");
- }
- } else {
- /* means that the result has to be retrieved from a map */
- final Method readMethod = getReadMethod(bean.getClass(), descriptor);
- if (readMethod != null) {
- final Object invokeResult = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
- /* test and fetch from the map */
- if (invokeResult instanceof java.util.Map) {
- result = ((java.util.Map, ?>)invokeResult).get(key);
- }
- } else {
- throw new NoSuchMethodException("Property '" + name +
- "' has no mapped getter method on bean class '" +
- bean.getClass() + "'");
- }
- }
- return result;
-
- }
-
- /**
- *
Return the mapped property descriptors for this bean class.
- *
- *
FIXME - Does not work with DynaBeans.
- *
- * @param beanClass Bean class to be introspected
- * @return the mapped property descriptors
- */
- Map, Map> getMappedPropertyDescriptors(final Class> beanClass) {
-
- if (beanClass == null) {
- return null;
- }
-
- // Look up any cached descriptors for this bean class
- return mappedDescriptorsCache.get(beanClass);
-
- }
-
- /**
- *
Return the mapped property descriptors for this bean.
- *
- *
FIXME - Does not work with DynaBeans.
- *
- * @param bean Bean to be introspected
- * @return the mapped property descriptors
- */
- Map getMappedPropertyDescriptors(final Object bean) {
-
- if (bean == null) {
- return null;
- }
- return getMappedPropertyDescriptors(bean.getClass());
-
- }
-
- /**
- * Return the value of the (possibly nested) property of the specified
- * name, for the specified bean, with no type conversions.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly nested name of the property to be extracted
- * @return the nested property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws NestedNullException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException
- * if the property accessor method throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public Object getNestedProperty(Object bean, 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() + "'");
- }
-
- // Resolve nested references
- while (resolver.hasNested(name)) {
- final String next = resolver.next(name);
- Object nestedBean = null;
- if (bean instanceof Map) {
- nestedBean = getPropertyOfMapBean((Map, ?>) bean, next);
- } else if (resolver.isMapped(next)) {
- nestedBean = getMappedProperty(bean, next);
- } else if (resolver.isIndexed(next)) {
- nestedBean = getIndexedProperty(bean, next);
- } else {
- nestedBean = getSimpleProperty(bean, next);
- }
- if (nestedBean == null) {
- throw new NestedNullException
- ("Null property value for '" + name +
- "' on bean class '" + bean.getClass() + "'");
- }
- bean = nestedBean;
- name = resolver.remove(name);
- }
-
- if (bean instanceof Map) {
- bean = getPropertyOfMapBean((Map, ?>) bean, name);
- } else if (resolver.isMapped(name)) {
- bean = getMappedProperty(bean, name);
- } else if (resolver.isIndexed(name)) {
- bean = getIndexedProperty(bean, name);
- } else {
- bean = getSimpleProperty(bean, name);
- }
- return bean;
-
- }
-
- /**
- * This method is called by getNestedProperty and setNestedProperty to
- * define what it means to get a property from an object which implements
- * Map. See setPropertyOfMapBean for more information.
- *
- * @param bean Map bean
- * @param propertyName The property name
- * @return the property value
- *
- * @throws IllegalArgumentException when the propertyName is regarded as
- * being invalid.
- *
- * @throws IllegalAccessException just in case subclasses override this
- * method to try to access real getter methods and find permission is denied.
- *
- * @throws InvocationTargetException just in case subclasses override this
- * method to try to access real getter methods, and find it throws an
- * exception when invoked.
- *
- * @throws NoSuchMethodException just in case subclasses override this
- * method to try to access real getter methods, and want to fail if
- * no simple method is available.
- * @since 1.8.0
- */
- protected Object getPropertyOfMapBean(final Map, ?> bean, String propertyName)
- throws IllegalArgumentException, IllegalAccessException,
- InvocationTargetException, NoSuchMethodException {
-
- if (resolver.isMapped(propertyName)) {
- final String name = resolver.getProperty(propertyName);
- if (name == null || name.length() == 0) {
- propertyName = resolver.getKey(propertyName);
- }
- }
-
- if (resolver.isIndexed(propertyName) ||
- resolver.isMapped(propertyName)) {
- throw new IllegalArgumentException(
- "Indexed or mapped properties are not supported on"
- + " objects of type Map: " + propertyName);
- }
-
- return bean.get(propertyName);
- }
-
- /**
- * Return the value of the specified property of the specified bean,
- * no matter which property reference format is used, with no
- * type conversions.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly indexed and/or nested name of the property
- * to be extracted
- * @return the property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public Object getProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return getNestedProperty(bean, name);
-
- }
-
- /**
- *
Retrieve the property descriptor for the specified property of the
- * specified bean, or return {@code null} if there is no such
- * descriptor. This method resolves indexed and nested property
- * references in the same manner as other methods in this class, except
- * that if the last (or only) name element is indexed, the descriptor
- * for the last resolved property itself is returned.
- *
- *
FIXME - Does not work with DynaBeans.
- *
- *
Note that for Java 8 and above, this method no longer return
- * IndexedPropertyDescriptor for {@link List}-typed properties, only for
- * properties typed as native array. (BEANUTILS-492).
- *
- * @param bean Bean for which a property descriptor is requested
- * @param name Possibly indexed and/or nested name of the property for
- * which a property descriptor is requested
- * @return the property descriptor
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public PropertyDescriptor getPropertyDescriptor(Object bean,
- 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() + "'");
- }
-
- // Resolve nested references
- while (resolver.hasNested(name)) {
- final String next = resolver.next(name);
- final Object nestedBean = getProperty(bean, next);
- if (nestedBean == null) {
- throw new NestedNullException
- ("Null property value for '" + next +
- "' on bean class '" + bean.getClass() + "'");
- }
- bean = nestedBean;
- name = resolver.remove(name);
- }
-
- // Remove any subscript from the final name value
- name = resolver.getProperty(name);
-
- // Look up and return this property from our cache
- // creating and adding it to the cache if not found.
- if (name == null) {
- return null;
- }
-
- final BeanIntrospectionData data = getIntrospectionData(bean.getClass());
- PropertyDescriptor result = data.getDescriptor(name);
- if (result != null) {
- return result;
- }
-
- Map mappedDescriptors =
- getMappedPropertyDescriptors(bean);
- if (mappedDescriptors == null) {
- mappedDescriptors = new ConcurrentHashMap, Map>();
- mappedDescriptorsCache.put(bean.getClass(), mappedDescriptors);
- }
- result = (PropertyDescriptor) mappedDescriptors.get(name);
- if (result == null) {
- // not found, try to create it
- try {
- result = new MappedPropertyDescriptor(name, bean.getClass());
- } catch (final IntrospectionException ie) {
- /* Swallow IntrospectionException
- * TODO: Why?
- */
- }
- if (result != null) {
- mappedDescriptors.put(name, result);
- }
- }
-
- return result;
-
- }
-
- /**
- *
Retrieve the property descriptors for the specified class,
- * introspecting and caching them the first time a particular bean class
- * is encountered.
- *
- *
FIXME - Does not work with DynaBeans.
- *
- * @param beanClass Bean class for which property descriptors are requested
- * @return the property descriptors
- *
- * @throws IllegalArgumentException if {@code beanClass} is null
- */
- public PropertyDescriptor[]
- getPropertyDescriptors(final Class> beanClass) {
-
- return getIntrospectionData(beanClass).getDescriptors();
-
- }
-
- /**
- *
Retrieve the property descriptors for the specified bean,
- * introspecting and caching them the first time a particular bean class
- * is encountered.
- *
- *
FIXME - Does not work with DynaBeans.
- *
- * @param bean Bean for which property descriptors are requested
- * @return the property descriptors
- *
- * @throws IllegalArgumentException if {@code bean} is null
- */
- public PropertyDescriptor[] getPropertyDescriptors(final Object bean) {
-
- if (bean == null) {
- throw new IllegalArgumentException("No bean specified");
- }
- return getPropertyDescriptors(bean.getClass());
-
- }
-
- /**
- *
Return the Java Class repesenting the property editor class that has
- * been registered for this property (if any). This method follows the
- * same name resolution rules used by {@code getPropertyDescriptor()},
- * so if the last element of a name reference is indexed, the property
- * editor for the underlying property's class is returned.
- *
- *
Note that {@code null} will be returned if there is no property,
- * or if there is no registered property editor class. Because this
- * return value is ambiguous, you should determine the existence of the
- * property itself by other means.
- *
- *
FIXME - Does not work with DynaBeans.
- *
- * @param bean Bean for which a property descriptor is requested
- * @param name Possibly indexed and/or nested name of the property for
- * which a property descriptor is requested
- * @return the property editor class
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public Class> getPropertyEditorClass(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() + "'");
- }
-
- final PropertyDescriptor descriptor =
- getPropertyDescriptor(bean, name);
- if (descriptor != null) {
- return descriptor.getPropertyEditorClass();
- }
- return null;
-
- }
-
- /**
- * Return the Java Class representing the property type of the specified
- * property, or {@code null} if there is no such property for the
- * specified bean. This method follows the same name resolution rules
- * used by {@code getPropertyDescriptor()}, so if the last element
- * of a name reference is indexed, the type of the property itself will
- * be returned. If the last (or only) element has no property with the
- * specified name, {@code null} is returned.
- *
- * If the property is an indexed property (e.g. {@code String[]}),
- * this method will return the type of the items within that array.
- * Note that from Java 8 and newer, this method do not support
- * such index types from items within an Collection, and will
- * instead return the collection type (e.g. java.util.List) from the
- * getter method.
- *
- * @param bean Bean for which a property descriptor is requested
- * @param name Possibly indexed and/or nested name of the property for
- * which a property descriptor is requested
- * @return The property type
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public Class> getPropertyType(Object bean, 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() + "'");
- }
-
- // Resolve nested references
- while (resolver.hasNested(name)) {
- final String next = resolver.next(name);
- final Object nestedBean = getProperty(bean, next);
- if (nestedBean == null) {
- throw new NestedNullException
- ("Null property value for '" + next +
- "' on bean class '" + bean.getClass() + "'");
- }
- bean = nestedBean;
- name = resolver.remove(name);
- }
-
- // Remove any subscript from the final name value
- name = resolver.getProperty(name);
-
- // Special handling for DynaBeans
- if (bean instanceof DynaBean) {
- final DynaProperty descriptor =
- ((DynaBean) bean).getDynaClass().getDynaProperty(name);
- if (descriptor == null) {
- return null;
- }
- final Class> type = descriptor.getType();
- if (type == null) {
- return null;
- } else if (type.isArray()) {
- return type.getComponentType();
- } else {
- return type;
- }
- }
-
- final PropertyDescriptor descriptor =
- getPropertyDescriptor(bean, name);
- if (descriptor == null) {
- return null;
- } else if (descriptor instanceof IndexedPropertyDescriptor) {
- return ((IndexedPropertyDescriptor) descriptor).
- getIndexedPropertyType();
- } else if (descriptor instanceof MappedPropertyDescriptor) {
- return ((MappedPropertyDescriptor) descriptor).
- getMappedPropertyType();
- } else {
- return descriptor.getPropertyType();
- }
-
- }
-
- /**
- *
Return an accessible property getter method for this property,
- * if there is one; otherwise return {@code null}.
- *
- *
FIXME - Does not work with DynaBeans.
- *
- * @param descriptor Property descriptor to return a getter for
- * @return The read method
- */
- public Method getReadMethod(final PropertyDescriptor descriptor) {
-
- return MethodUtils.getAccessibleMethod(descriptor.getReadMethod());
-
- }
-
- /**
- *
Return an accessible property getter method for this property,
- * if there is one; otherwise return {@code null}.
- *
- *
FIXME - Does not work with DynaBeans.
- *
- * @param clazz The class of the read method will be invoked on
- * @param descriptor Property descriptor to return a getter for
- * @return The read method
- */
- Method getReadMethod(final Class> clazz, final PropertyDescriptor descriptor) {
- return MethodUtils.getAccessibleMethod(clazz, descriptor.getReadMethod());
- }
-
- /**
- * Return the value of the specified simple property of the specified
- * bean, with no type conversions.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Name of the property to be extracted
- * @return The property value
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if the property name
- * is nested or indexed
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- 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() + "'");
- }
-
- // 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() + "'");
- } else if (resolver.isIndexed(name)) {
- throw new IllegalArgumentException
- ("Indexed property names are not allowed: Property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- } else if (resolver.isMapped(name)) {
- 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);
- if (descriptor == null) {
- 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);
- if (descriptor == null) {
- 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() + "'");
- }
-
- // Call the property getter and return the value
- final Object value = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
- return value;
-
- }
-
- /**
- *
Return an accessible property setter method for this property,
- * if there is one; otherwise return {@code null}.
- *
- *
Note: This method does not work correctly with custom bean
- * introspection under certain circumstances. It may return {@code null}
- * even if a write method is defined for the property in question. Use
- * {@link #getWriteMethod(Class, PropertyDescriptor)} to be sure that the
- * correct result is returned.
- *
FIXME - Does not work with DynaBeans.
- *
- * @param descriptor Property descriptor to return a setter for
- * @return The write method
- */
- public Method getWriteMethod(final PropertyDescriptor descriptor) {
-
- return MethodUtils.getAccessibleMethod(descriptor.getWriteMethod());
-
- }
-
- /**
- *
Return an accessible property setter method for this property,
- * if there is one; otherwise return {@code null}.
- *
- *
FIXME - Does not work with DynaBeans.
- *
- * @param clazz The class of the read method will be invoked on
- * @param descriptor Property descriptor to return a setter for
- * @return The write method
- * @since 1.9.1
- */
- public Method getWriteMethod(final Class> clazz, final PropertyDescriptor descriptor) {
- final BeanIntrospectionData data = getIntrospectionData(clazz);
- return MethodUtils.getAccessibleMethod(clazz,
- data.getWriteMethod(clazz, descriptor));
- }
-
- /**
- *
Return {@code true} if the specified property name identifies
- * a readable property on the specified bean; otherwise, return
- * {@code false}.
- *
- * @param bean Bean to be examined (may be a {@link DynaBean}
- * @param name Property name to be evaluated
- * @return {@code true} if the property is readable,
- * otherwise {@code false}
- *
- * @throws IllegalArgumentException if {@code bean}
- * or {@code name
is null}
- *
- * @since BeanUtils 1.6
- */
- public boolean isReadable(Object bean, String name) {
-
- // Validate method parameters
- if (bean == null) {
- throw new IllegalArgumentException("No bean specified");
- }
- if (name == null) {
- throw new IllegalArgumentException("No name specified for bean class '" +
- bean.getClass() + "'");
- }
-
- // Resolve nested references
- while (resolver.hasNested(name)) {
- final String next = resolver.next(name);
- Object nestedBean = null;
- try {
- nestedBean = getProperty(bean, next);
- } catch (final IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
- return false;
- }
- if (nestedBean == null) {
- throw new NestedNullException
- ("Null property value for '" + next +
- "' on bean class '" + bean.getClass() + "'");
- }
- bean = nestedBean;
- name = resolver.remove(name);
- }
-
- // Remove any subscript from the final name value
- name = resolver.getProperty(name);
-
- // Treat WrapDynaBean as special case - may be a write-only property
- // (see Jira issue# BEANUTILS-61)
- if (bean instanceof WrapDynaBean) {
- bean = ((WrapDynaBean)bean).getInstance();
- }
-
- // Return the requested result
- if (bean instanceof DynaBean) {
- // All DynaBean properties are readable
- return ((DynaBean) bean).getDynaClass().getDynaProperty(name) != null;
- }
- try {
- final PropertyDescriptor desc =
- getPropertyDescriptor(bean, name);
- if (desc != null) {
- Method readMethod = getReadMethod(bean.getClass(), desc);
- if (readMethod == null) {
- if (desc instanceof IndexedPropertyDescriptor) {
- readMethod = ((IndexedPropertyDescriptor) desc).getIndexedReadMethod();
- } else if (desc instanceof MappedPropertyDescriptor) {
- readMethod = ((MappedPropertyDescriptor) desc).getMappedReadMethod();
- }
- readMethod = MethodUtils.getAccessibleMethod(bean.getClass(), readMethod);
- }
- return readMethod != null;
- }
- return false;
- } catch (final IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
- return false;
- }
-
- }
-
- /**
- *
Return {@code true} if the specified property name identifies
- * a writeable property on the specified bean; otherwise, return
- * {@code false}.
- *
- * @param bean Bean to be examined (may be a {@link DynaBean}
- * @param name Property name to be evaluated
- * @return {@code true} if the property is writeable,
- * otherwise {@code false}
- *
- * @throws IllegalArgumentException if {@code bean}
- * or {@code name
is null}
- *
- * @since BeanUtils 1.6
- */
- public boolean isWriteable(Object bean, String name) {
-
- // Validate method parameters
- if (bean == null) {
- throw new IllegalArgumentException("No bean specified");
- }
- if (name == null) {
- throw new IllegalArgumentException("No name specified for bean class '" +
- bean.getClass() + "'");
- }
-
- // Resolve nested references
- while (resolver.hasNested(name)) {
- final String next = resolver.next(name);
- Object nestedBean = null;
- try {
- nestedBean = getProperty(bean, next);
- } catch (final IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
- return false;
- }
- if (nestedBean == null) {
- throw new NestedNullException
- ("Null property value for '" + next +
- "' on bean class '" + bean.getClass() + "'");
- }
- bean = nestedBean;
- name = resolver.remove(name);
- }
-
- // Remove any subscript from the final name value
- name = resolver.getProperty(name);
-
- // Treat WrapDynaBean as special case - may be a read-only property
- // (see Jira issue# BEANUTILS-61)
- if (bean instanceof WrapDynaBean) {
- bean = ((WrapDynaBean)bean).getInstance();
- }
-
- // Return the requested result
- if (bean instanceof DynaBean) {
- // All DynaBean properties are writeable
- return ((DynaBean) bean).getDynaClass().getDynaProperty(name) != null;
- }
- try {
- final PropertyDescriptor desc =
- getPropertyDescriptor(bean, name);
- if (desc != null) {
- Method writeMethod = getWriteMethod(bean.getClass(), desc);
- if (writeMethod == null) {
- if (desc instanceof IndexedPropertyDescriptor) {
- writeMethod = ((IndexedPropertyDescriptor) desc).getIndexedWriteMethod();
- } else if (desc instanceof MappedPropertyDescriptor) {
- writeMethod = ((MappedPropertyDescriptor) desc).getMappedWriteMethod();
- }
- writeMethod = MethodUtils.getAccessibleMethod(bean.getClass(), writeMethod);
- }
- return writeMethod != null;
- }
- return false;
- } catch (final IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
- return false;
- }
-
- }
-
- /**
- * Set the value of the specified indexed property of the specified
- * bean, with no type conversions. The zero-relative index of the
- * required value must be included (in square brackets) as a suffix to
- * the property name, or {@code IllegalArgumentException} will be
- * thrown. In addition to supporting the JavaBeans specification, this
- * method has been extended to support {@code List} objects as well.
- *
- * @param bean Bean whose property is to be modified
- * @param name {@code propertyname[index]} of the property value
- * to be modified
- * @param value Value to which the specified property element
- * should be set
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public void setIndexedProperty(final Object bean, String name,
- final Object value)
- 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() + "'");
- }
-
- // Identify the index of the requested individual property
- int index = -1;
- try {
- index = resolver.getIndex(name);
- } catch (final IllegalArgumentException e) {
- throw new IllegalArgumentException("Invalid indexed property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
- if (index < 0) {
- throw new IllegalArgumentException("Invalid indexed property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
-
- // Isolate the name
- name = resolver.getProperty(name);
-
- // Set the specified indexed property value
- setIndexedProperty(bean, name, index, value);
-
- }
-
- /**
- * Set the value of the specified indexed property of the specified
- * bean, with no type conversions. In addition to supporting the JavaBeans
- * specification, this method has been extended to support
- * {@code List} objects as well.
- *
- * @param bean Bean whose property is to be set
- * @param name Simple property name of the property value to be set
- * @param index Index of the property value to be set
- * @param value Value to which the indexed property element is to be set
- *
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the valid range for the underlying property
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public void setIndexedProperty(final Object bean, final String name,
- final int index, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- if (bean == null) {
- throw new IllegalArgumentException("No bean specified");
- }
- if (name == null || name.length() == 0) {
- if (bean.getClass().isArray()) {
- Array.set(bean, index, value);
- return;
- } else if (bean instanceof List) {
- final List list = toObjectList(bean);
- list.set(index, value);
- return;
- }
- }
- if (name == null) {
- throw new IllegalArgumentException("No name specified for bean class '" +
- bean.getClass() + "'");
- }
-
- // Handle DynaBean instances specially
- if (bean instanceof DynaBean) {
- final DynaProperty descriptor =
- ((DynaBean) bean).getDynaClass().getDynaProperty(name);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
- ((DynaBean) bean).set(name, index, value);
- return;
- }
-
- // Retrieve the property descriptor for the specified property
- final PropertyDescriptor descriptor =
- getPropertyDescriptor(bean, name);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
-
- // Call the indexed setter method if there is one
- if (descriptor instanceof IndexedPropertyDescriptor) {
- Method writeMethod = ((IndexedPropertyDescriptor) descriptor).
- getIndexedWriteMethod();
- writeMethod = MethodUtils.getAccessibleMethod(bean.getClass(), writeMethod);
- if (writeMethod != null) {
- final Object[] subscript = new Object[2];
- subscript[0] = Integer.valueOf(index);
- subscript[1] = value;
- try {
- if (log.isTraceEnabled()) {
- final String valueClassName =
- value == null ? ""
- : value.getClass().getName();
- log.trace("setSimpleProperty: Invoking method "
- + writeMethod +" with index=" + index
- + ", value=" + value
- + " (class " + valueClassName+ ")");
- }
- invokeMethod(writeMethod, bean, subscript);
- } catch (final InvocationTargetException e) {
- if (e.getTargetException() instanceof
- IndexOutOfBoundsException) {
- throw (IndexOutOfBoundsException)
- e.getTargetException();
- }
- throw e;
- }
- return;
- }
- }
-
- // Otherwise, the underlying property must be an array or a list
- final Method readMethod = getReadMethod(bean.getClass(), descriptor);
- if (readMethod == null) {
- throw new NoSuchMethodException("Property '" + name +
- "' has no getter method on bean class '" + bean.getClass() + "'");
- }
-
- // Call the property getter to get the array or list
- final Object array = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
- if (!array.getClass().isArray()) {
- if (array instanceof List) {
- // Modify the specified value in the List
- final List list = toObjectList(array);
- list.set(index, value);
- } else {
- throw new IllegalArgumentException("Property '" + name +
- "' is not indexed on bean class '" + bean.getClass() + "'");
- }
- } else {
- // Modify the specified value in the array
- Array.set(array, index, value);
- }
-
- }
-
- /**
- * Set the value of the specified mapped property of the
- * specified bean, with no type conversions. The key of the
- * value to set must be included (in brackets) as a suffix to
- * the property name, or {@code IllegalArgumentException} will be
- * thrown.
- *
- * @param bean Bean whose property is to be set
- * @param name {@code propertyname(key)} of the property value
- * to be set
- * @param value The property value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public void setMappedProperty(final Object bean, String name,
- final Object value)
- 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() + "'");
- }
-
- // Identify the key of the requested individual property
- String key = null;
- try {
- key = resolver.getKey(name);
- } catch (final IllegalArgumentException e) {
- throw new IllegalArgumentException
- ("Invalid mapped property '" + name +
- "' on bean class '" + bean.getClass() + "'");
- }
- if (key == null) {
- throw new IllegalArgumentException
- ("Invalid mapped property '" + name +
- "' on bean class '" + bean.getClass() + "'");
- }
-
- // Isolate the name
- name = resolver.getProperty(name);
-
- // Request the specified indexed property value
- setMappedProperty(bean, name, key, value);
-
- }
-
- /**
- * Set the value of the specified mapped property of the specified
- * bean, with no type conversions.
- *
- * @param bean Bean whose property is to be set
- * @param name Mapped property name of the property value to be set
- * @param key Key of the property value to be set
- * @param value The property value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public void setMappedProperty(final Object bean, final String name,
- final String key, final Object value)
- 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() + "'");
- }
- if (key == null) {
- throw new IllegalArgumentException("No key specified for property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
-
- // Handle DynaBean instances specially
- if (bean instanceof DynaBean) {
- final DynaProperty descriptor =
- ((DynaBean) bean).getDynaClass().getDynaProperty(name);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
- ((DynaBean) bean).set(name, key, value);
- return;
- }
-
- // Retrieve the property descriptor for the specified property
- final PropertyDescriptor descriptor =
- getPropertyDescriptor(bean, name);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- }
-
- if (descriptor instanceof MappedPropertyDescriptor) {
- // Call the keyed setter method if there is one
- Method mappedWriteMethod =
- ((MappedPropertyDescriptor) descriptor).
- getMappedWriteMethod();
- mappedWriteMethod = MethodUtils.getAccessibleMethod(bean.getClass(), mappedWriteMethod);
- if (mappedWriteMethod != null) {
- final Object[] params = new Object[2];
- params[0] = key;
- params[1] = value;
- if (log.isTraceEnabled()) {
- final String valueClassName =
- value == null ? "" : value.getClass().getName();
- log.trace("setSimpleProperty: Invoking method "
- + mappedWriteMethod + " with key=" + key
- + ", value=" + value
- + " (class " + valueClassName +")");
- }
- invokeMethod(mappedWriteMethod, bean, params);
- } else {
- throw new NoSuchMethodException
- ("Property '" + name + "' has no mapped setter method" +
- "on bean class '" + bean.getClass() + "'");
- }
- } else {
- /* means that the result has to be retrieved from a map */
- final Method readMethod = getReadMethod(bean.getClass(), descriptor);
- if (readMethod != null) {
- final Object invokeResult = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
- /* test and fetch from the map */
- if (invokeResult instanceof java.util.Map) {
- final java.util.Map map = toPropertyMap(invokeResult);
- map.put(key, value);
- }
- } else {
- throw new NoSuchMethodException("Property '" + name +
- "' has no mapped getter method on bean class '" +
- bean.getClass() + "'");
- }
- }
-
- }
-
- /**
- * Set the value of the (possibly nested) property of the specified
- * name, for the specified bean, with no type conversions.
- *
- * Example values for parameter "name" are:
- *
- *
"a" -- sets the value of property a of the specified bean
- *
"a.b" -- gets the value of property a of the specified bean,
- * then on that object sets the value of property b.
- *
"a(key)" -- sets a value of mapped-property a on the specified
- * bean. This effectively means bean.setA("key").
- *
"a[3]" -- sets a value of indexed-property a on the specified
- * bean. This effectively means bean.setA(3).
- *
- *
- * @param bean Bean whose property is to be modified
- * @param name Possibly nested name of the property to be modified
- * @param value Value to which the property is to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public void setNestedProperty(Object bean,
- String name, final Object value)
- 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() + "'");
- }
-
- // Resolve nested references
- while (resolver.hasNested(name)) {
- final String next = resolver.next(name);
- Object nestedBean = null;
- if (bean instanceof Map) {
- nestedBean = getPropertyOfMapBean((Map, ?>)bean, next);
- } else if (resolver.isMapped(next)) {
- nestedBean = getMappedProperty(bean, next);
- } else if (resolver.isIndexed(next)) {
- nestedBean = getIndexedProperty(bean, next);
- } else {
- nestedBean = getSimpleProperty(bean, next);
- }
- if (nestedBean == null) {
- throw new NestedNullException
- ("Null property value for '" + name +
- "' on bean class '" + bean.getClass() + "'");
- }
- bean = nestedBean;
- name = resolver.remove(name);
- }
-
- if (bean instanceof Map) {
- setPropertyOfMapBean(toPropertyMap(bean), name, value);
- } else if (resolver.isMapped(name)) {
- setMappedProperty(bean, name, value);
- } else if (resolver.isIndexed(name)) {
- setIndexedProperty(bean, name, value);
- } else {
- setSimpleProperty(bean, name, value);
- }
-
- }
-
- /**
- * This method is called by method setNestedProperty when the current bean
- * is found to be a Map object, and defines how to deal with setting
- * a property on a Map.
- *
- * The standard implementation here is to:
- *
- *
call bean.set(propertyName) for all propertyName values.
- *
throw an IllegalArgumentException if the property specifier
- * contains MAPPED_DELIM or INDEXED_DELIM, as Map entries are essentially
- * simple properties; mapping and indexing operations do not make sense
- * when accessing a map (even thought the returned object may be a Map
- * or an Array).
- *
- *
- * The default behavior of beanutils 1.7.1 or later is for assigning to
- * "a.b" to mean a.put(b, obj) always. However the behavior of beanutils
- * version 1.6.0, 1.6.1, 1.7.0 was for "a.b" to mean a.setB(obj) if such
- * a method existed, and a.put(b, obj) otherwise. In version 1.5 it meant
- * a.put(b, obj) always (ie the same as the behavior in the current version).
- * In versions prior to 1.5 it meant a.setB(obj) always. [yes, this is
- * all very unfortunate]
- *
- * Users who would like to customize the meaning of "a.b" in method
- * setNestedProperty when a is a Map can create a custom subclass of
- * this class and override this method to implement the behavior of
- * their choice, such as restoring the pre-1.4 behavior of this class
- * if they wish. When overriding this method, do not forget to deal
- * with MAPPED_DELIM and INDEXED_DELIM characters in the propertyName.
- *
- * Note, however, that the recommended solution for objects that
- * implement Map but want their simple properties to come first is
- * for those objects to override their get/put methods to implement
- * that behavior, and not to solve the problem by modifying the
- * default behavior of the PropertyUtilsBean class by overriding this
- * method.
- *
- * @param bean Map bean
- * @param propertyName The property name
- * @param value the property value
- *
- * @throws IllegalArgumentException when the propertyName is regarded as
- * being invalid.
- *
- * @throws IllegalAccessException just in case subclasses override this
- * method to try to access real setter methods and find permission is denied.
- *
- * @throws InvocationTargetException just in case subclasses override this
- * method to try to access real setter methods, and find it throws an
- * exception when invoked.
- *
- * @throws NoSuchMethodException just in case subclasses override this
- * method to try to access real setter methods, and want to fail if
- * no simple method is available.
- * @since 1.8.0
- */
- protected void setPropertyOfMapBean(final Map bean, String propertyName, final Object value)
- throws IllegalArgumentException, IllegalAccessException,
- InvocationTargetException, NoSuchMethodException {
-
- if (resolver.isMapped(propertyName)) {
- final String name = resolver.getProperty(propertyName);
- if (name == null || name.length() == 0) {
- propertyName = resolver.getKey(propertyName);
- }
- }
-
- if (resolver.isIndexed(propertyName) ||
- resolver.isMapped(propertyName)) {
- throw new IllegalArgumentException(
- "Indexed or mapped properties are not supported on"
- + " objects of type Map: " + propertyName);
- }
-
- bean.put(propertyName, value);
- }
-
- /**
- * Set the value of the specified property of the specified bean,
- * no matter which property reference format is used, with no
- * type conversions.
- *
- * @param bean Bean whose property is to be modified
- * @param name Possibly indexed and/or nested name of the property
- * to be modified
- * @param value Value to which this property is to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public void setProperty(final Object bean, final String name, final Object value)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- setNestedProperty(bean, name, value);
-
- }
-
- /**
- * Set the value of the specified simple property of the specified bean,
- * with no type conversions.
- *
- * @param bean Bean whose property is to be modified
- * @param name Name of the property to be modified
- * @param value Value to which the property should be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if {@code bean} or
- * {@code name} is null
- * @throws IllegalArgumentException if the property name is
- * nested or indexed
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public void setSimpleProperty(final Object bean,
- final String name, final Object value)
- 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() + "'");
- }
-
- // 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() + "'");
- } else if (resolver.isIndexed(name)) {
- throw new IllegalArgumentException
- ("Indexed property names are not allowed: Property '" +
- name + "' on bean class '" + bean.getClass() + "'");
- } else if (resolver.isMapped(name)) {
- 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);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "' on dynaclass '" +
- ((DynaBean) bean).getDynaClass() + "'" );
- }
- ((DynaBean) bean).set(name, value);
- return;
- }
-
- // Retrieve the property setter method for the specified property
- final PropertyDescriptor descriptor =
- getPropertyDescriptor(bean, name);
- if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
- name + "' on class '" + bean.getClass() + "'" );
- }
- final Method writeMethod = getWriteMethod(bean.getClass(), descriptor);
- if (writeMethod == null) {
- throw new NoSuchMethodException("Property '" + name +
- "' has no setter method in class '" + bean.getClass() + "'");
- }
-
- // Call the property setter method
- final Object[] values = new Object[1];
- values[0] = value;
- if (log.isTraceEnabled()) {
- final String valueClassName =
- value == null ? "" : value.getClass().getName();
- log.trace("setSimpleProperty: Invoking method " + writeMethod
- + " with value " + value + " (class " + valueClassName + ")");
- }
- invokeMethod(writeMethod, bean, values);
-
- }
-
- /** This just catches and wraps IllegalArgumentException. */
- private Object invokeMethod(
- final Method method,
- final Object bean,
- final Object[] values)
- throws
- IllegalAccessException,
- InvocationTargetException {
- if(bean == null) {
- throw new IllegalArgumentException("No bean specified " +
- "- this should have been checked before reaching this method");
- }
-
- try {
-
- return method.invoke(bean, values);
-
- } catch (final NullPointerException | IllegalArgumentException cause) {
- // JDK 1.3 and JDK 1.4 throw NullPointerException if an argument is
- // null for a primitive value (JDK 1.5+ throw IllegalArgumentException)
- StringBuilder valueString = new StringBuilder();
- if (values != null) {
- for (int i = 0; i < values.length; i++) {
- if (i>0) {
- valueString.append(", ");
- }
- if (values[i] == null) {
- valueString.append("");
- } else {
- valueString.append(values[i].getClass().getName());
- }
- }
- }
- StringBuilder expectedString = new StringBuilder();
- final Class>[] parTypes = method.getParameterTypes();
- if (parTypes != null) {
- for (int i = 0; i < parTypes.length; i++) {
- if (i > 0) {
- expectedString.append(", ");
- }
- expectedString.append(parTypes[i].getName());
- }
- }
- final IllegalArgumentException e = new IllegalArgumentException(
- "Cannot invoke " + method.getDeclaringClass().getName() + "."
- + method.getName() + " on bean class '" + bean.getClass() +
- "' - " + cause.getMessage()
- // as per https://issues.apache.org/jira/browse/BEANUTILS-224
- + " - had objects of type \"" + valueString
- + "\" but expected signature \""
- + expectedString + "\""
- );
- if (!BeanUtils.initCause(e, cause)) {
- log.error("Method invocation failed", cause);
- }
- throw e;
- }
- }
-
- /**
- * Obtains the {@code BeanIntrospectionData} object describing the specified bean
- * class. This object is looked up in the internal cache. If necessary, introspection
- * is performed now on the affected bean class, and the results object is created.
- *
- * @param beanClass the bean class in question
- * @return the {@code BeanIntrospectionData} object for this class
- * @throws IllegalArgumentException if the bean class is null
- */
- private BeanIntrospectionData getIntrospectionData(final Class> beanClass) {
- if (beanClass == null) {
- throw new IllegalArgumentException("No bean class specified");
- }
-
- // Look up any cached information for this bean class
- BeanIntrospectionData data = descriptorsCache.get(beanClass);
- if (data == null) {
- data = fetchIntrospectionData(beanClass);
- descriptorsCache.put(beanClass, data);
- }
-
- return data;
- }
-
- /**
- * Performs introspection on the specified class. This method invokes all {@code BeanIntrospector} objects that were
- * added to this instance.
- *
- * @param beanClass the class to be inspected
- * @return a data object with the results of introspection
- */
- private BeanIntrospectionData fetchIntrospectionData(final Class> beanClass) {
- final DefaultIntrospectionContext ictx = new DefaultIntrospectionContext(beanClass);
-
- for (final BeanIntrospector bi : introspectors) {
- try {
- bi.introspect(ictx);
- } catch (final IntrospectionException iex) {
- log.error("Exception during introspection", iex);
- }
- }
-
- return new BeanIntrospectionData(ictx.getPropertyDescriptors());
- }
-
- /**
- * Converts an object to a list of objects. This method is used when dealing
- * with indexed properties. It assumes that indexed properties are stored as
- * lists of objects.
- *
- * @param obj the object to be converted
- * @return the resulting list of objects
- */
- private static List toObjectList(final Object obj) {
- @SuppressWarnings("unchecked")
- final
- // indexed properties are stored in lists of objects
- List list = (List) obj;
- return list;
- }
-
- /**
- * Converts an object to a map with property values. This method is used
- * when dealing with mapped properties. It assumes that mapped properties
- * are stored in a Map<String, Object>.
- *
- * @param obj the object to be converted
- * @return the resulting properties map
- */
- private static Map toPropertyMap(final Object obj) {
- @SuppressWarnings("unchecked")
- final
- // mapped properties are stores in maps of type
- Map map = (Map) obj;
- return map;
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ResultSetDynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ResultSetDynaClass.java
deleted file mode 100644
index cf9eee0b2..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ResultSetDynaClass.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.Objects;
-
-/**
- *
Implementation of {@code DynaClass} for DynaBeans that wrap the
- * {@code java.sql.Row
objects of a java.sql.ResultSet}.
- * The normal usage pattern is something like:
- *
Each column in the result set will be represented as a DynaBean
- * property of the corresponding name (optionally forced to lower case
- * for portability).
- *
- *
WARNING - Any {@link DynaBean} instance returned by
- * this class, or from the {@code Iterator} returned by the
- * {@code iterator()} method, is directly linked to the row that the
- * underlying result set is currently positioned at. This has the following
- * implications:
- *
- *
Once you retrieve a different {@link DynaBean} instance, you should
- * no longer use any previous instance.
- *
Changing the position of the underlying result set will change the
- * data that the {@link DynaBean} references.
- *
Once the underlying result set is closed, the {@link DynaBean}
- * instance may no longer be used.
- *
- *
- *
Any database data that you wish to utilize outside the context of the
- * current row of an open result set must be copied. For example, you could
- * use the following code to create standalone copies of the information in
- * a result set:
- *
- */
-
-public class ResultSetDynaClass extends JDBCDynaClass {
-
- private static final long serialVersionUID = 1L;
-
-
-
- /**
- *
Construct a new ResultSetDynaClass for the specified
- * {@code ResultSet}. The property names corresponding
- * to column names in the result set will be lower cased.
- *
- * @param resultSet The result set to be wrapped
- *
- * @throws NullPointerException if {@code resultSet}
- * is {@code null}
- * @throws SQLException if the metadata for this result set
- * cannot be introspected
- */
- public ResultSetDynaClass(final ResultSet resultSet) throws SQLException {
-
- this(resultSet, true);
-
- }
-
- /**
- *
Construct a new ResultSetDynaClass for the specified
- * {@code ResultSet}. The property names corresponding
- * to the column names in the result set will be lower cased or not,
- * depending on the specified {@code lowerCase} value.
- *
- *
WARNING - If you specify {@code false}
- * for {@code lowerCase}, the returned property names will
- * exactly match the column names returned by your JDBC driver.
- * Because different drivers might return column names in different
- * cases, the property names seen by your application will vary
- * depending on which JDBC driver you are using.
- *
- * @param resultSet The result set to be wrapped
- * @param lowerCase Should property names be lower cased?
- *
- * @throws NullPointerException if {@code resultSet}
- * is {@code null}
- * @throws SQLException if the metadata for this result set
- * cannot be introspected
- */
- public ResultSetDynaClass(final ResultSet resultSet, final boolean lowerCase)
- throws SQLException {
-
- this(resultSet, lowerCase, false);
-
- }
-
- /**
- *
Construct a new ResultSetDynaClass for the specified
- * {@code ResultSet}. The property names corresponding
- * to the column names in the result set will be lower cased or not,
- * depending on the specified {@code lowerCase} value.
- *
- *
WARNING - If you specify {@code false}
- * for {@code lowerCase}, the returned property names will
- * exactly match the column names returned by your JDBC driver.
- * Because different drivers might return column names in different
- * cases, the property names seen by your application will vary
- * depending on which JDBC driver you are using.
- *
- * @param resultSet The result set to be wrapped
- * @param lowerCase Should property names be lower cased?
- * @param useColumnLabel true if the column label should be used, otherwise false
- *
- * @throws NullPointerException if {@code resultSet}
- * is {@code null}
- * @throws SQLException if the metadata for this result set
- * cannot be introspected
- * @since 1.8.3
- */
- public ResultSetDynaClass(final ResultSet resultSet, final boolean lowerCase, final boolean useColumnLabel)
- throws SQLException {
- Objects.requireNonNull(resultSet, "resultSet");
- this.resultSet = resultSet;
- this.lowerCase = lowerCase;
- setUseColumnLabel(useColumnLabel);
- introspect(resultSet);
-
- }
-
-
-
- /**
- *
Return an {@code Iterator} of {@link DynaBean} instances for
- * each row of the wrapped {@code ResultSet}, in "forward" order.
- * Unless the underlying result set supports scrolling, this method
- * should be called only once.
- * @return An {@code Iterator} of {@link DynaBean} instances
- */
- public Iterator iterator() {
-
- return new ResultSetIterator(this);
-
- }
-
- /**
- * Get a value from the {@link ResultSet} for the specified
- * property name.
- *
- * @param name The property name
- * @return The value
- * @throws SQLException if an error occurs
- * @since 1.8.0
- */
- public Object getObjectFromResultSet(final String name) throws SQLException {
- return getObject(getResultSet(), name);
- }
-
-
-
- /**
- *
Loads the class of the given name which by default uses the class loader used
- * to load this library.
- * Derivations of this class could implement alternative class loading policies such as
- * using custom ClassLoader or using the Threads's context class loader etc.
- *
- * @param className The name of the class to load
- * @return The loaded class
- * @throws SQLException if the class cannot be loaded
- */
- @Override
- protected Class> loadClass(final String className) throws SQLException {
-
- try {
- return getClass().getClassLoader().loadClass(className);
- }
- catch (final Exception e) {
- throw new SQLException("Cannot load column class '" +
- className + "': " + e);
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ResultSetIterator.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ResultSetIterator.java
deleted file mode 100644
index 35b50b9fc..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ResultSetIterator.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- *
Implementation of {@code java.util.Iterator} returned by the
- * {@code iterator()} method of {@link ResultSetDynaClass}. Each
- * object returned by this iterator will be a {@link DynaBean} that
- * represents a single row from the result set being wrapped.
Flag indicating whether the result set has indicated that there are
- * no further rows.
- */
- protected boolean eof = false;
-
-
-
- /**
- * Does the specified mapped property contain a value for the specified
- * key value?
- *
- * @param name Name of the property to check
- * @param key Name of the key to check
- * @return {@code true} if the mapped property contains a value for
- * the specified key, otherwise {@code false}
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- @Override
- public boolean contains(final String name, final String key) {
-
- throw new UnsupportedOperationException
- ("FIXME - mapped properties not currently supported");
-
- }
-
- /**
- * Return the value of a simple property with the specified name.
- *
- * @param name Name of the property whose value is to be retrieved
- * @return The property's value
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- @Override
- public Object get(final String name) {
-
- if (dynaClass.getDynaProperty(name) == null) {
- throw new IllegalArgumentException(name);
- }
- try {
- return dynaClass.getObjectFromResultSet(name);
- } catch (final SQLException e) {
- throw new RuntimeException
- ("get(" + name + "): SQLException: " + e);
- }
-
- }
-
- /**
- * Return the value of an indexed property with the specified name.
- *
- * @param name Name of the property whose value is to be retrieved
- * @param index Index of the value to be retrieved
- * @return The indexed property's value
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not indexed
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the range of the underlying property
- * @throws NullPointerException if no array or List has been
- * initialized for this property
- */
- @Override
- public Object get(final String name, final int index) {
-
- throw new UnsupportedOperationException
- ("FIXME - indexed properties not currently supported");
-
- }
-
- /**
- * Return the value of a mapped property with the specified name,
- * or {@code null} if there is no value for the specified key.
- *
- * @param name Name of the property whose value is to be retrieved
- * @param key Key of the value to be retrieved
- * @return The mapped property's value
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not mapped
- */
- @Override
- public Object get(final String name, final String key) {
-
- throw new UnsupportedOperationException
- ("FIXME - mapped properties not currently supported");
-
- }
-
- /**
- * Return the {@code DynaClass} instance that describes the set of
- * properties available for this DynaBean.
- *
- * @return The associated DynaClass
- */
- @Override
- public DynaClass getDynaClass() {
-
- return this.dynaClass;
-
- }
-
- /**
- * Remove any existing value for the specified key on the
- * specified mapped property.
- *
- * @param name Name of the property for which a value is to
- * be removed
- * @param key Key of the value to be removed
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- @Override
- public void remove(final String name, final String key) {
-
- throw new UnsupportedOperationException
- ("FIXME - mapped operations not currently supported");
-
- }
-
- /**
- * Set the value of a simple property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws NullPointerException if an attempt is made to set a
- * primitive property to null
- */
- @Override
- public void set(final String name, final Object value) {
-
- if (dynaClass.getDynaProperty(name) == null) {
- throw new IllegalArgumentException(name);
- }
- try {
- dynaClass.getResultSet().updateObject(name, value);
- } catch (final SQLException e) {
- throw new RuntimeException
- ("set(" + name + "): SQLException: " + e);
- }
-
- }
-
- /**
- * Set the value of an indexed property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param index Index of the property to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not indexed
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the range of the underlying property
- */
- @Override
- public void set(final String name, final int index, final Object value) {
-
- throw new UnsupportedOperationException
- ("FIXME - indexed properties not currently supported");
-
- }
-
- /**
- * Set the value of a mapped property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param key Key of the property to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not mapped
- */
- @Override
- public void set(final String name, final String key, final Object value) {
-
- throw new UnsupportedOperationException
- ("FIXME - mapped properties not currently supported");
-
- }
-
-
-
- /**
- *
Return {@code true} if the iteration has more elements.
- *
- * @return {@code true} if the result set has another
- * row, otherwise {@code false}
- */
- @Override
- public boolean hasNext() {
-
- try {
- advance();
- return !eof;
- } catch (final SQLException e) {
- throw new RuntimeException("hasNext(): SQLException: " + e);
- }
-
- }
-
- /**
- *
Return the next element in the iteration.
- *
- * @return advance to the new row and return this
- */
- @Override
- public DynaBean next() {
-
- try {
- advance();
- if (eof) {
- throw new NoSuchElementException();
- }
- current = false;
- return this;
- } catch (final SQLException e) {
- throw new RuntimeException("next(): SQLException: " + e);
- }
-
- }
-
- /**
- *
Remove the current element from the iteration. This method is
- * not supported.
Advance the result set to the next row, if there is not a current
- * row (and if we are not already at eof).
- *
- * @throws SQLException if the result set throws an exception
- */
- protected void advance() throws SQLException {
-
- if (!current && !eof) {
- if (dynaClass.getResultSet().next()) {
- current = true;
- eof = false;
- } else {
- current = false;
- eof = true;
- }
- }
-
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/RowSetDynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/RowSetDynaClass.java
deleted file mode 100644
index 10a4b1af0..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/RowSetDynaClass.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-/**
- *
Implementation of {@link DynaClass} that creates an in-memory collection
- * of {@link DynaBean}s representing the results of an SQL query. Once the
- * {@link DynaClass} instance has been created, the JDBC {@code ResultSet}
- * and {@code Statement} on which it is based can be closed, and the
- * underlying {@code Connection} can be returned to its connection pool
- * (if you are using one).
- *
- *
The normal usage pattern is something like:
- *
- * Connection conn = ...; // Acquire connection from pool
- * Statement stmt = conn.createStatement();
- * ResultSet rs = stmt.executeQuery("SELECT ...");
- * RowSetDynaClass rsdc = new RowSetDynaClass(rs);
- * rs.close();
- * stmt.close();
- * ...; // Return connection to pool
- * List rows = rsdc.getRows();
- * ...; // Process the rows as desired
- *
- *
- *
Each column in the result set will be represented as a {@link DynaBean}
- * property of the corresponding name (optionally forced to lower case
- * for portability). There will be one {@link DynaBean} in the
- * {@code List
returned by getRows()} for each
- * row in the original {@code ResultSet}.
- *
- *
In general, instances of {@link RowSetDynaClass} can be serialized
- * and deserialized, which will automatically include the list of
- * {@link DynaBean}s representing the data content. The only exception
- * to this rule would be when the underlying property values that were
- * copied from the {@code ResultSet} originally cannot themselves
- * be serialized. Therefore, a {@link RowSetDynaClass} makes a very
- * convenient mechanism for transporting data sets to remote Java-based
- * application components.
- *
- */
-
-public class RowSetDynaClass extends JDBCDynaClass {
-
- private static final long serialVersionUID = 1L;
-
-
-
- /**
- *
Limits the size of the returned list. The call to
- * {@code getRows()} will return at most limit number of rows.
- * If less than or equal to 0, does not limit the size of the result.
- */
- protected int limit = -1;
-
- /**
- *
The list of {@link DynaBean}s representing the contents of
- * the original {@code ResultSet} on which this
- * {@link RowSetDynaClass} was based.
- */
- protected List rows = new ArrayList<>();
-
-
-
- /**
- *
Construct a new {@link RowSetDynaClass} for the specified
- * {@code ResultSet}. The property names corresponding
- * to column names in the result set will be lower cased.
- *
- * @param resultSet The result set to be wrapped
- *
- * @throws NullPointerException if {@code resultSet}
- * is {@code null}
- * @throws SQLException if the metadata for this result set
- * cannot be introspected
- */
- public RowSetDynaClass(final ResultSet resultSet) throws SQLException {
-
- this(resultSet, true, -1);
-
- }
-
- /**
- *
Construct a new {@link RowSetDynaClass} for the specified
- * {@code ResultSet}. The property names corresponding
- * to column names in the result set will be lower cased.
- *
- * If {@code limit is not less than 0, max limit}
- * number of rows will be copied into the list.
- *
- * @param resultSet The result set to be wrapped
- * @param limit The maximum for the size of the result.
- *
- * @throws NullPointerException if {@code resultSet}
- * is {@code null}
- * @throws SQLException if the metadata for this result set
- * cannot be introspected
- */
- public RowSetDynaClass(final ResultSet resultSet, final int limit) throws SQLException {
-
- this(resultSet, true, limit);
-
- }
-
- /**
- *
Construct a new {@link RowSetDynaClass} for the specified
- * {@code ResultSet}. The property names corresponding
- * to the column names in the result set will be lower cased or not,
- * depending on the specified {@code lowerCase} value.
- *
- * If {@code limit is not less than 0, max limit}
- * number of rows will be copied into the resultset.
- *
- *
- * @param resultSet The result set to be wrapped
- * @param lowerCase Should property names be lower cased?
- *
- * @throws NullPointerException if {@code resultSet}
- * is {@code null}
- * @throws SQLException if the metadata for this result set
- * cannot be introspected
- */
- public RowSetDynaClass(final ResultSet resultSet, final boolean lowerCase)
- throws SQLException {
- this(resultSet, lowerCase, -1);
-
- }
-
- /**
- *
Construct a new {@link RowSetDynaClass} for the specified
- * {@code ResultSet}. The property names corresponding
- * to the column names in the result set will be lower cased or not,
- * depending on the specified {@code lowerCase} value.
- *
- *
WARNING - If you specify {@code false}
- * for {@code lowerCase}, the returned property names will
- * exactly match the column names returned by your JDBC driver.
- * Because different drivers might return column names in different
- * cases, the property names seen by your application will vary
- * depending on which JDBC driver you are using.
- *
- * @param resultSet The result set to be wrapped
- * @param lowerCase Should property names be lower cased?
- * @param limit Maximum limit for the {@code List} of {@link DynaBean}
- *
- * @throws NullPointerException if {@code resultSet}
- * is {@code null}
- * @throws SQLException if the metadata for this result set
- * cannot be introspected
- */
- public RowSetDynaClass(final ResultSet resultSet, final boolean lowerCase, final int limit)
- throws SQLException {
-
- this(resultSet, lowerCase, limit, false);
-
- }
-
- /**
- *
Construct a new {@link RowSetDynaClass} for the specified
- * {@code ResultSet}. The property names corresponding
- * to the column names in the result set will be lower cased or not,
- * depending on the specified {@code lowerCase} value.
- *
- *
WARNING - If you specify {@code false}
- * for {@code lowerCase}, the returned property names will
- * exactly match the column names returned by your JDBC driver.
- * Because different drivers might return column names in different
- * cases, the property names seen by your application will vary
- * depending on which JDBC driver you are using.
- *
- * @param resultSet The result set to be wrapped
- * @param lowerCase Should property names be lower cased?
- * @param useColumnLabel true if the column label should be used, otherwise false
- *
- * @throws NullPointerException if {@code resultSet}
- * is {@code null}
- * @throws SQLException if the metadata for this result set
- * cannot be introspected
- * @since 1.8.3
- */
- public RowSetDynaClass(final ResultSet resultSet, final boolean lowerCase, final boolean useColumnLabel)
- throws SQLException {
- this(resultSet, lowerCase, -1, useColumnLabel);
-
- }
-
- /**
- *
Construct a new {@link RowSetDynaClass} for the specified
- * {@code ResultSet}. The property names corresponding
- * to the column names in the result set will be lower cased or not,
- * depending on the specified {@code lowerCase} value.
- *
- *
WARNING - If you specify {@code false}
- * for {@code lowerCase}, the returned property names will
- * exactly match the column names returned by your JDBC driver.
- * Because different drivers might return column names in different
- * cases, the property names seen by your application will vary
- * depending on which JDBC driver you are using.
- *
- * @param resultSet The result set to be wrapped
- * @param lowerCase Should property names be lower cased?
- * @param limit Maximum limit for the {@code List} of {@link DynaBean}
- * @param useColumnLabel true if the column label should be used, otherwise false
- *
- * @throws NullPointerException if {@code resultSet}
- * is {@code null}
- * @throws SQLException if the metadata for this result set
- * cannot be introspected
- * @since 1.8.3
- */
- public RowSetDynaClass(final ResultSet resultSet, final boolean lowerCase, final int limit, final boolean useColumnLabel)
- throws SQLException {
- Objects.requireNonNull(resultSet, "resultSet");
- this.lowerCase = lowerCase;
- this.limit = limit;
- setUseColumnLabel(useColumnLabel);
- introspect(resultSet);
- copy(resultSet);
-
- }
-
- /**
- *
Return a {@code List} containing the {@link DynaBean}s that
- * represent the contents of each {@code Row} from the
- * {@code ResultSet} that was the basis of this
- * {@link RowSetDynaClass} instance. These {@link DynaBean}s are
- * disconnected from the database itself, so there is no problem with
- * modifying the contents of the list, or the values of the properties
- * of these {@link DynaBean}s. However, it is the application's
- * responsibility to persist any such changes back to the database,
- * if it so desires.
- *
- * @return A {@code List} of {@link DynaBean} instances
- */
- public List getRows() {
-
- return this.rows;
-
- }
-
-
-
- /**
- *
Copy the column values for each row in the specified
- * {@code ResultSet} into a newly created {@link DynaBean}, and add
- * this bean to the list of {@link DynaBean}s that will later by
- * returned by a call to {@code getRows()}.
- *
- * @param resultSet The {@code ResultSet} whose data is to be
- * copied
- *
- * @throws SQLException if an error is encountered copying the data
- */
- protected void copy(final ResultSet resultSet) throws SQLException {
-
- int cnt = 0;
- while (resultSet.next() && (limit < 0 || cnt++ < limit) ) {
- final DynaBean bean = createDynaBean();
- for (final DynaProperty property : properties) {
- final String name = property.getName();
- final Object value = getObject(resultSet, name);
- bean.set(name, value);
- }
- rows.add(bean);
- }
-
- }
-
- /**
- *
Create and return a new {@link DynaBean} instance to be used for
- * representing a row in the underlying result set.
- *
- * @return A new {@code DynaBean} instance
- */
- protected DynaBean createDynaBean() {
-
- return new BasicDynaBean(this);
-
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospector.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospector.java
deleted file mode 100644
index cc1aedc8a..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/SuppressPropertiesBeanIntrospector.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.beans.IntrospectionException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- *
- * A specialized {@code BeanIntrospector} implementation which suppresses some properties.
- *
- *
- * An instance of this class is passed a set with the names of the properties it should
- * process. During introspection of a bean class it removes all these properties from the
- * {@link IntrospectionContext}. So effectively, properties added by a different
- * {@code BeanIntrospector} are removed again.
- *
- *
- * @since 1.9.2
- */
-public class SuppressPropertiesBeanIntrospector implements BeanIntrospector {
- /**
- * A specialized instance which is configured to suppress the special {@code class}
- * properties of Java beans. Unintended access to the property {@code class} (which is
- * common to all Java objects) can be a security risk because it also allows access to
- * the class loader. Adding this instance as {@code BeanIntrospector} to an instance
- * of {@code PropertyUtilsBean} suppresses the {@code class} property; it can then no
- * longer be accessed.
- */
- public static final SuppressPropertiesBeanIntrospector SUPPRESS_CLASS =
- new SuppressPropertiesBeanIntrospector(Collections.singleton("class"));
-
- /** A set with the names of the properties to be suppressed. */
- private final Set propertyNames;
-
- /**
- * Creates a new instance of {@code SuppressPropertiesBeanIntrospector} and sets the
- * names of the properties to be suppressed.
- *
- * @param propertiesToSuppress the names of the properties to be suppressed (must not
- * be null)
- * @throws IllegalArgumentException if the collection with property names is
- * null
- */
- public SuppressPropertiesBeanIntrospector(final Collection propertiesToSuppress) {
- if (propertiesToSuppress == null) {
- throw new IllegalArgumentException("Property names must not be null!");
- }
-
- propertyNames = Collections.unmodifiableSet(new HashSet<>(
- propertiesToSuppress));
- }
-
- /**
- * Returns a (unmodifiable) set with the names of the properties which are suppressed
- * by this {@code BeanIntrospector}.
- *
- * @return a set with the names of the suppressed properties
- */
- public Set getSuppressedProperties() {
- return propertyNames;
- }
-
- /**
- * {@inheritDoc} This implementation removes all properties from the given context it
- * is configured for.
- */
- @Override
- public void introspect(final IntrospectionContext icontext) throws IntrospectionException {
- for (final String property : getSuppressedProperties()) {
- icontext.removePropertyDescriptor(property);
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/WeakFastHashMap.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/WeakFastHashMap.java
deleted file mode 100644
index 7572877d0..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/WeakFastHashMap.java
+++ /dev/null
@@ -1,752 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.util.Collection;
-import java.util.ConcurrentModificationException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-
-/**
- *
A customized implementation of {@code java.util.HashMap} designed
- * to operate in a multi-threaded environment where the large majority of
- * method calls are read-only, instead of structural changes. When operating
- * in "fast" mode, read calls are non-synchronized and write calls perform the
- * following steps:
- *
- *
Clone the existing collection
- *
Perform the modification on the clone
- *
Replace the existing collection with the (modified) clone
- *
- *
When first created, objects of this class default to "slow" mode, where
- * all accesses of any type are synchronized but no cloning takes place. This
- * is appropriate for initially populating the collection, followed by a switch
- * to "fast" mode (by calling {@code setFast(true)}) after initialization
- * is complete.
- *
- *
NOTE: If you are creating and accessing a
- * {@code HashMap} only within a single thread, you should use
- * {@code java.util.HashMap} directly (with no synchronization), for
- * maximum performance.
- *
- *
NOTE: This class is not cross-platform.
- * Using it may cause unexpected failures on some architectures.
- * It suffers from the same problems as the double-checked locking idiom.
- * In particular, the instruction that clones the internal collection and the
- * instruction that sets the internal reference to the clone can be executed
- * or perceived out-of-order. This means that any read operation might fail
- * unexpectedly, as it may be reading the state of the internal collection
- * before the internal collection is fully formed.
- * For more information on the double-checked locking idiom, see the
- *
- * Double-Checked Locking Idiom Is Broken Declaration.
- *
- * @since Commons Collections 1.0
- */
-public class WeakFastHashMap extends HashMap {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * The underlying map we are managing.
- */
- private volatile Map map = null;
-
- /**
- * Are we currently operating in "fast" mode?
- */
- private boolean fast = false;
-
- // Constructors
-
-
- /**
- * Construct an empty map.
- */
- public WeakFastHashMap() {
- super();
- this.map = createMap();
- }
-
- /**
- * Construct an empty map with the specified capacity.
- *
- * @param capacity the initial capacity of the empty map
- */
- public WeakFastHashMap(final int capacity) {
- super();
- this.map = createMap(capacity);
- }
-
- /**
- * Construct an empty map with the specified capacity and load factor.
- *
- * @param capacity the initial capacity of the empty map
- * @param factor the load factor of the new map
- */
- public WeakFastHashMap(final int capacity, final float factor) {
- super();
- this.map = createMap(capacity, factor);
- }
-
- /**
- * Construct a new map with the same mappings as the specified map.
- *
- * @param map the map whose mappings are to be copied
- */
- public WeakFastHashMap(final Map extends K, ? extends V> map) {
- super();
- this.map = createMap(map);
- }
-
- // Property access
-
-
- /**
- * Returns true if this map is operating in fast mode.
- *
- * @return true if this map is operating in fast mode
- */
- public boolean getFast() {
- return this.fast;
- }
-
- /**
- * Sets whether this map is operating in fast mode.
- *
- * @param fast true if this map should operate in fast mode
- */
- public void setFast(final boolean fast) {
- this.fast = fast;
- }
-
- // Map access
-
- // These methods can forward straight to the wrapped Map in 'fast' mode.
- // (because they are query methods)
-
- /**
- * Return the value to which this map maps the specified key. Returns
- * {@code null} if the map contains no mapping for this key, or if
- * there is a mapping with a value of {@code null}. Use the
- * {@code containsKey()} method to disambiguate these cases.
- *
- * @param key the key whose value is to be returned
- * @return the value mapped to that key, or null
- */
- @Override
- public V get(final Object key) {
- if (fast) {
- return map.get(key);
- }
- synchronized (map) {
- return map.get(key);
- }
- }
-
- /**
- * Return the number of key-value mappings in this map.
- *
- * @return the current size of the map
- */
- @Override
- public int size() {
- if (fast) {
- return map.size();
- }
- synchronized (map) {
- return map.size();
- }
- }
-
- /**
- * Return {@code true} if this map contains no mappings.
- *
- * @return is the map currently empty
- */
- @Override
- public boolean isEmpty() {
- if (fast) {
- return map.isEmpty();
- }
- synchronized (map) {
- return map.isEmpty();
- }
- }
-
- /**
- * Return {@code true} if this map contains a mapping for the
- * specified key.
- *
- * @param key the key to be searched for
- * @return true if the map contains the key
- */
- @Override
- public boolean containsKey(final Object key) {
- if (fast) {
- return map.containsKey(key);
- }
- synchronized (map) {
- return map.containsKey(key);
- }
- }
-
- /**
- * Return {@code true} if this map contains one or more keys mapping
- * to the specified value.
- *
- * @param value the value to be searched for
- * @return true if the map contains the value
- */
- @Override
- public boolean containsValue(final Object value) {
- if (fast) {
- return map.containsValue(value);
- }
- synchronized (map) {
- return map.containsValue(value);
- }
- }
-
- // Map modification
-
- // These methods perform special behavior in 'fast' mode.
- // The map is cloned, updated and then assigned back.
- // See the comments at the top as to why this won't always work.
-
- /**
- * Associate the specified value with the specified key in this map.
- * If the map previously contained a mapping for this key, the old
- * value is replaced and returned.
- *
- * @param key the key with which the value is to be associated
- * @param value the value to be associated with this key
- * @return the value previously mapped to the key, or null
- */
- @Override
- public V put(final K key, final V value) {
- if (fast) {
- synchronized (this) {
- final Map temp = cloneMap(map);
- final V result = temp.put(key, value);
- map = temp;
- return result;
- }
- }
- synchronized (map) {
- return map.put(key, value);
- }
- }
-
- /**
- * Copy all of the mappings from the specified map to this one, replacing
- * any mappings with the same keys.
- *
- * @param in the map whose mappings are to be copied
- */
- @Override
- public void putAll(final Map extends K, ? extends V> in) {
- if (fast) {
- synchronized (this) {
- final Map temp = cloneMap(map);
- temp.putAll(in);
- map = temp;
- }
- } else {
- synchronized (map) {
- map.putAll(in);
- }
- }
- }
-
- /**
- * Remove any mapping for this key, and return any previously
- * mapped value.
- *
- * @param key the key whose mapping is to be removed
- * @return the value removed, or null
- */
- @Override
- public V remove(final Object key) {
- if (fast) {
- synchronized (this) {
- final Map temp = cloneMap(map);
- final V result = temp.remove(key);
- map = temp;
- return result;
- }
- }
- synchronized (map) {
- return map.remove(key);
- }
- }
-
- /**
- * Remove all mappings from this map.
- */
- @Override
- public void clear() {
- if (fast) {
- synchronized (this) {
- map = createMap();
- }
- } else {
- synchronized (map) {
- map.clear();
- }
- }
- }
-
- // Basic object methods
-
-
- /**
- * Compare the specified object with this list for equality. This
- * implementation uses exactly the code that is used to define the
- * list equals function in the documentation for the
- * {@code Map.equals} method.
- *
- * @param o the object to be compared to this list
- * @return true if the two maps are equal
- */
- @Override
- public boolean equals(final Object o) {
- // Simple tests that require no synchronization
- if (o == this) {
- return true;
- } else if (!(o instanceof Map)) {
- return false;
- }
- final Map, ?> mo = (Map, ?>) o;
-
- // Compare the two maps for equality
- if (fast) {
- if (mo.size() != map.size()) {
- return false;
- }
- for (final Map.Entry e : map.entrySet()) {
- final K key = e.getKey();
- final V value = e.getValue();
- if (value == null) {
- if (!(mo.get(key) == null && mo.containsKey(key))) {
- return false;
- }
- } else {
- if (!value.equals(mo.get(key))) {
- return false;
- }
- }
- }
- return true;
-
- }
- synchronized (map) {
- if (mo.size() != map.size()) {
- return false;
- }
- for (final Map.Entry e : map.entrySet()) {
- final K key = e.getKey();
- final V value = e.getValue();
- if (value == null) {
- if (!(mo.get(key) == null && mo.containsKey(key))) {
- return false;
- }
- } else {
- if (!value.equals(mo.get(key))) {
- return false;
- }
- }
- }
- return true;
- }
- }
-
- /**
- * Return the hash code value for this map. This implementation uses
- * exactly the code that is used to define the list hash function in the
- * documentation for the {@code Map.hashCode} method.
- *
- * @return suitable integer hash code
- */
- @Override
- public int hashCode() {
- if (fast) {
- int h = 0;
- for (final Map.Entry e : map.entrySet()) {
- h += e.hashCode();
- }
- return h;
- }
- synchronized (map) {
- int h = 0;
- for (final Map.Entry e : map.entrySet()) {
- h += e.hashCode();
- }
- return h;
- }
- }
-
- /**
- * Return a shallow copy of this {@code FastHashMap} instance.
- * The keys and values themselves are not copied.
- *
- * @return a clone of this map
- */
- @Override
- public Object clone() {
- WeakFastHashMap results = null;
- if (fast) {
- results = new WeakFastHashMap<>(map);
- } else {
- synchronized (map) {
- results = new WeakFastHashMap<>(map);
- }
- }
- results.setFast(getFast());
- return results;
- }
-
- // Map views
-
-
- /**
- * Return a collection view of the mappings contained in this map. Each
- * element in the returned collection is a {@code Map.Entry}.
- * @return the set of map Map entries
- */
- @Override
- public Set> entrySet() {
- return new EntrySet();
- }
-
- /**
- * Return a set view of the keys contained in this map.
- * @return the set of the Map's keys
- */
- @Override
- public Set keySet() {
- return new KeySet();
- }
-
- /**
- * Return a collection view of the values contained in this map.
- * @return the set of the Map's values
- */
- @Override
- public Collection values() {
- return new Values();
- }
-
- // Abstractions on Map creations (for subclasses such as WeakFastHashMap)
-
-
- protected Map createMap() {
- return new WeakHashMap<>();
- }
-
- protected Map createMap(final int capacity) {
- return new WeakHashMap<>(capacity);
- }
-
- protected Map createMap(final int capacity, final float factor) {
- return new WeakHashMap<>(capacity, factor);
- }
-
- protected Map createMap(final Map extends K, ? extends V> map) {
- return new WeakHashMap<>(map);
- }
-
- protected Map cloneMap(final Map extends K, ? extends V> map) {
- return createMap(map);
- }
-
- // Map view inner classes
-
-
- /**
- * Abstract collection implementation shared by keySet(), values() and entrySet().
- *
- * @param the element type
- */
- private abstract class CollectionView implements Collection {
-
- public CollectionView() {
- }
-
- protected abstract Collection get(Map map);
- protected abstract E iteratorNext(Map.Entry entry);
-
- @Override
- public void clear() {
- if (fast) {
- synchronized (WeakFastHashMap.this) {
- map = createMap();
- }
- } else {
- synchronized (map) {
- get(map).clear();
- }
- }
- }
-
- @Override
- public boolean remove(final Object o) {
- if (fast) {
- synchronized (WeakFastHashMap.this) {
- final Map temp = cloneMap(map);
- final boolean r = get(temp).remove(o);
- map = temp;
- return r;
- }
- }
- synchronized (map) {
- return get(map).remove(o);
- }
- }
-
- @Override
- public boolean removeAll(final Collection> o) {
- if (fast) {
- synchronized (WeakFastHashMap.this) {
- final Map temp = cloneMap(map);
- final boolean r = get(temp).removeAll(o);
- map = temp;
- return r;
- }
- }
- synchronized (map) {
- return get(map).removeAll(o);
- }
- }
-
- @Override
- public boolean retainAll(final Collection> o) {
- if (fast) {
- synchronized (WeakFastHashMap.this) {
- final Map temp = cloneMap(map);
- final boolean r = get(temp).retainAll(o);
- map = temp;
- return r;
- }
- }
- synchronized (map) {
- return get(map).retainAll(o);
- }
- }
-
- @Override
- public int size() {
- if (fast) {
- return get(map).size();
- }
- synchronized (map) {
- return get(map).size();
- }
- }
-
- @Override
- public boolean isEmpty() {
- if (fast) {
- return get(map).isEmpty();
- }
- synchronized (map) {
- return get(map).isEmpty();
- }
- }
-
- @Override
- public boolean contains(final Object o) {
- if (fast) {
- return get(map).contains(o);
- }
- synchronized (map) {
- return get(map).contains(o);
- }
- }
-
- @Override
- public boolean containsAll(final Collection> o) {
- if (fast) {
- return get(map).containsAll(o);
- }
- synchronized (map) {
- return get(map).containsAll(o);
- }
- }
-
- @Override
- public T[] toArray(final T[] o) {
- if (fast) {
- return get(map).toArray(o);
- }
- synchronized (map) {
- return get(map).toArray(o);
- }
- }
-
- @Override
- public Object[] toArray() {
- if (fast) {
- return get(map).toArray();
- }
- synchronized (map) {
- return get(map).toArray();
- }
- }
-
- @Override
- public boolean equals(final Object o) {
- if (o == this) {
- return true;
- }
- if (fast) {
- return get(map).equals(o);
- }
- synchronized (map) {
- return get(map).equals(o);
- }
- }
-
- @Override
- public int hashCode() {
- if (fast) {
- return get(map).hashCode();
- }
- synchronized (map) {
- return get(map).hashCode();
- }
- }
-
- @Override
- public boolean add(final E o) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean addAll(final Collection extends E> c) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Iterator iterator() {
- return new CollectionViewIterator();
- }
-
- private class CollectionViewIterator implements Iterator {
-
- private Map expected;
- private Map.Entry lastReturned = null;
- private final Iterator> iterator;
-
- public CollectionViewIterator() {
- this.expected = map;
- this.iterator = expected.entrySet().iterator();
- }
-
- @Override
- public boolean hasNext() {
- if (expected != map) {
- throw new ConcurrentModificationException();
- }
- return iterator.hasNext();
- }
-
- @Override
- public E next() {
- if (expected != map) {
- throw new ConcurrentModificationException();
- }
- lastReturned = iterator.next();
- return iteratorNext(lastReturned);
- }
-
- @Override
- public void remove() {
- if (lastReturned == null) {
- throw new IllegalStateException();
- }
- if (fast) {
- synchronized (WeakFastHashMap.this) {
- if (expected != map) {
- throw new ConcurrentModificationException();
- }
- WeakFastHashMap.this.remove(lastReturned.getKey());
- lastReturned = null;
- expected = map;
- }
- } else {
- iterator.remove();
- lastReturned = null;
- }
- }
- }
- }
-
- /**
- * Set implementation over the keys of the FastHashMap
- */
- private class KeySet extends CollectionView implements Set {
-
- @Override
- protected Collection get(final Map map) {
- return map.keySet();
- }
-
- @Override
- protected K iteratorNext(final Map.Entry entry) {
- return entry.getKey();
- }
-
- }
-
- /**
- * Collection implementation over the values of the FastHashMap
- */
- private class Values extends CollectionView {
-
- @Override
- protected Collection get(final Map map) {
- return map.values();
- }
-
- @Override
- protected V iteratorNext(final Map.Entry entry) {
- return entry.getValue();
- }
- }
-
- /**
- * Set implementation over the entries of the FastHashMap
- */
- private class EntrySet extends CollectionView> implements Set> {
-
- @Override
- protected Collection> get(final Map map) {
- return map.entrySet();
- }
-
- @Override
- protected Map.Entry iteratorNext(final Map.Entry entry) {
- return entry;
- }
-
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/WrapDynaBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/WrapDynaBean.java
deleted file mode 100644
index dc4a13e65..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/WrapDynaBean.java
+++ /dev/null
@@ -1,400 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-
-/**
- *
Implementation of {@code DynaBean} that wraps a standard JavaBean
- * instance, so that DynaBean APIs can be used to access its properties.
- *
- *
- * The most common use cases for this class involve wrapping an existing java bean.
- * (This makes it different from the typical use cases for other {@code DynaBean}'s.)
- * For example:
- *
IMPLEMENTATION NOTE - This implementation does not
- * support the {@code contains()
and remove()} methods.
- *
- */
-
-public class WrapDynaBean implements DynaBean, Serializable {
-
- private static final long serialVersionUID = 1L;
-
-
-
- /**
- * Construct a new {@code DynaBean} associated with the specified
- * JavaBean instance.
- *
- * @param instance JavaBean instance to be wrapped
- */
- public WrapDynaBean(final Object instance) {
-
- this(instance, null);
-
- }
-
- /**
- * Creates a new instance of {@code WrapDynaBean}, associates it with the specified
- * JavaBean instance, and initializes the bean's {@code DynaClass}. Using this
- * constructor this {@code WrapDynaBean} instance can be assigned a class which has
- * been configured externally. If no {@code WrapDynaClass} is provided, a new one is
- * created using a standard mechanism.
- *
- * @param instance JavaBean instance to be wrapped
- * @param cls the optional {@code WrapDynaClass} to be used for this bean
- * @since 1.9
- */
- public WrapDynaBean(final Object instance, final WrapDynaClass cls) {
-
- this.instance = instance;
- this.dynaClass = cls != null ? cls : (WrapDynaClass) getDynaClass();
-
- }
-
-
-
- /**
- * The {@code DynaClass} "base class" that this DynaBean
- * is associated with.
- */
- protected transient WrapDynaClass dynaClass = null;
-
- /**
- * The JavaBean instance wrapped by this WrapDynaBean.
- */
- protected Object instance = null;
-
-
-
- /**
- * Does the specified mapped property contain a value for the specified
- * key value?
- *
- * @param name Name of the property to check
- * @param key Name of the key to check
- * @return {@code true} if the mapped property contains a value for
- * the specified key, otherwise {@code false}
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- @Override
- public boolean contains(final String name, final String key) {
-
- throw new UnsupportedOperationException
- ("WrapDynaBean does not support contains()");
-
- }
-
- /**
- * Return the value of a simple property with the specified name.
- *
- * @param name Name of the property whose value is to be retrieved
- * @return The property's value
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- @Override
- public Object get(final String name) {
-
- Object value = null;
- try {
- value = getPropertyUtils().getSimpleProperty(instance, name);
- } catch (final InvocationTargetException ite) {
- final Throwable cause = ite.getTargetException();
- throw new IllegalArgumentException
- ("Error reading property '" + name +
- "' nested exception - " + cause);
- } catch (final Throwable t) {
- throw new IllegalArgumentException
- ("Error reading property '" + name +
- "', exception - " + t);
- }
- return value;
-
- }
-
- /**
- * Return the value of an indexed property with the specified name.
- *
- * @param name Name of the property whose value is to be retrieved
- * @param index Index of the value to be retrieved
- * @return The indexed property's value
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not indexed
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the range of the underlying property
- * @throws NullPointerException if no array or List has been
- * initialized for this property
- */
- @Override
- public Object get(final String name, final int index) {
-
- Object value = null;
- try {
- value = getPropertyUtils().getIndexedProperty(instance, name, index);
- } catch (final IndexOutOfBoundsException e) {
- throw e;
- } catch (final InvocationTargetException ite) {
- final Throwable cause = ite.getTargetException();
- throw new IllegalArgumentException
- ("Error reading indexed property '" + name +
- "' nested exception - " + cause);
- } catch (final Throwable t) {
- throw new IllegalArgumentException
- ("Error reading indexed property '" + name +
- "', exception - " + t);
- }
- return value;
-
- }
-
- /**
- * Return the value of a mapped property with the specified name,
- * or {@code null} if there is no value for the specified key.
- *
- * @param name Name of the property whose value is to be retrieved
- * @param key Key of the value to be retrieved
- * @return The mapped property's value
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not mapped
- */
- @Override
- public Object get(final String name, final String key) {
-
- Object value = null;
- try {
- value = getPropertyUtils().getMappedProperty(instance, name, key);
- } catch (final InvocationTargetException ite) {
- final Throwable cause = ite.getTargetException();
- throw new IllegalArgumentException
- ("Error reading mapped property '" + name +
- "' nested exception - " + cause);
- } catch (final Throwable t) {
- throw new IllegalArgumentException
- ("Error reading mapped property '" + name +
- "', exception - " + t);
- }
- return value;
-
- }
-
- /**
- * Return the {@code DynaClass} instance that describes the set of
- * properties available for this DynaBean.
- * @return The associated DynaClass
- */
- @Override
- public DynaClass getDynaClass() {
-
- if (dynaClass == null) {
- dynaClass = WrapDynaClass.createDynaClass(instance.getClass());
- }
-
- return this.dynaClass;
-
- }
-
- /**
- * Remove any existing value for the specified key on the
- * specified mapped property.
- *
- * @param name Name of the property for which a value is to
- * be removed
- * @param key Key of the value to be removed
- *
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- */
- @Override
- public void remove(final String name, final String key) {
-
- throw new UnsupportedOperationException
- ("WrapDynaBean does not support remove()");
-
- }
-
- /**
- * Set the value of a simple property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws NullPointerException if an attempt is made to set a
- * primitive property to null
- */
- @Override
- public void set(final String name, final Object value) {
-
- try {
- getPropertyUtils().setSimpleProperty(instance, name, value);
- } catch (final InvocationTargetException ite) {
- final Throwable cause = ite.getTargetException();
- throw new IllegalArgumentException
- ("Error setting property '" + name +
- "' nested exception -" + cause);
- } catch (final Throwable t) {
- throw new IllegalArgumentException
- ("Error setting property '" + name +
- "', exception - " + t);
- }
-
- }
-
- /**
- * Set the value of an indexed property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param index Index of the property to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not indexed
- * @throws IndexOutOfBoundsException if the specified index
- * is outside the range of the underlying property
- */
- @Override
- public void set(final String name, final int index, final Object value) {
-
- try {
- getPropertyUtils().setIndexedProperty(instance, name, index, value);
- } catch (final IndexOutOfBoundsException e) {
- throw e;
- } catch (final InvocationTargetException ite) {
- final Throwable cause = ite.getTargetException();
- throw new IllegalArgumentException
- ("Error setting indexed property '" + name +
- "' nested exception - " + cause);
- } catch (final Throwable t) {
- throw new IllegalArgumentException
- ("Error setting indexed property '" + name +
- "', exception - " + t);
- }
-
- }
-
- /**
- * Set the value of a mapped property with the specified name.
- *
- * @param name Name of the property whose value is to be set
- * @param key Key of the property to be set
- * @param value Value to which this property is to be set
- *
- * @throws ConversionException if the specified value cannot be
- * converted to the type required for this property
- * @throws IllegalArgumentException if there is no property
- * of the specified name
- * @throws IllegalArgumentException if the specified property
- * exists, but is not mapped
- */
- @Override
- public void set(final String name, final String key, final Object value) {
-
- try {
- getPropertyUtils().setMappedProperty(instance, name, key, value);
- } catch (final InvocationTargetException ite) {
- final Throwable cause = ite.getTargetException();
- throw new IllegalArgumentException
- ("Error setting mapped property '" + name +
- "' nested exception - " + cause);
- } catch (final Throwable t) {
- throw new IllegalArgumentException
- ("Error setting mapped property '" + name +
- "', exception - " + t);
- }
-
- }
-
- /**
- * Gets the bean instance wrapped by this DynaBean.
- * For most common use cases,
- * this object should already be known
- * and this method safely be ignored.
- * But some creators of frameworks using {@code DynaBean}'s may
- * find this useful.
- *
- * @return the java bean Object wrapped by this {@code DynaBean}
- */
- public Object getInstance() {
- return instance;
- }
-
-
-
- /**
- * Return the property descriptor for the specified property name.
- *
- * @param name Name of the property for which to retrieve the descriptor
- * @return The descriptor for the specified property
- *
- * @throws IllegalArgumentException if this is not a valid property
- * name for our DynaClass
- */
- protected DynaProperty getDynaProperty(final String name) {
-
- final DynaProperty descriptor = getDynaClass().getDynaProperty(name);
- if (descriptor == null) {
- throw new IllegalArgumentException
- ("Invalid property name '" + name + "'");
- }
- return descriptor;
-
- }
-
- /**
- * Returns the {@code PropertyUtilsBean} instance to be used for accessing properties.
- * If available, this object is obtained from the associated {@code WrapDynaClass}.
- *
- * @return the associated {@code PropertyUtilsBean}
- */
- private PropertyUtilsBean getPropertyUtils() {
-
- PropertyUtilsBean propUtils = null;
- if (dynaClass != null) {
- propUtils = dynaClass.getPropertyUtilsBean();
- }
- return propUtils != null ? propUtils : PropertyUtilsBean.getInstance();
-
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/WrapDynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/WrapDynaClass.java
deleted file mode 100644
index f63084243..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/WrapDynaClass.java
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-
-import java.beans.PropertyDescriptor;
-import java.lang.ref.Reference;
-import java.lang.ref.SoftReference;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-
-/**
- * Implementation of {@link DynaClass} that wrap
- * standard JavaBean instances.
- *
- * This class should not usually need to be used directly
- * to create new {@link WrapDynaBean} instances -
- * it's usually better to call the {@link WrapDynaBean} constructor.
- * For example:
- *
- *
- */
-
-public class WrapDynaClass implements DynaClass {
-
-
-
-
-
- /**
- * Construct a new WrapDynaClass for the specified JavaBean class. This
- * constructor is private; WrapDynaClass instances will be created as
- * needed via calls to the {@code createDynaClass(Class)} method.
- *
- * @param beanClass JavaBean class to be introspected around
- * @param propUtils the {@code PropertyUtilsBean} associated with this class
- */
- private WrapDynaClass(final Class> beanClass, final PropertyUtilsBean propUtils) {
-
- this.beanClassRef = new SoftReference<>(beanClass);
- this.beanClassName = beanClass.getName();
- propertyUtilsBean = propUtils;
- introspect();
-
- }
-
-
-
-
- /**
- * Name of the JavaBean class represented by this WrapDynaClass.
- */
- private String beanClassName = null;
-
- /**
- * Reference to the JavaBean class represented by this WrapDynaClass.
- */
- private Reference> beanClassRef = null;
-
- /** Stores the associated {@code PropertyUtilsBean} instance. */
- private final PropertyUtilsBean propertyUtilsBean;
-
- /**
- * The set of PropertyDescriptors for this bean class.
- */
- protected PropertyDescriptor[] descriptors = null;
-
-
- /**
- * The set of PropertyDescriptors for this bean class, keyed by the
- * property name. Individual descriptor instances will be the same
- * instances as those in the {@code descriptors} list.
- */
- protected HashMap descriptorsMap = new HashMap<>();
-
-
- /**
- * The set of dynamic properties that are part of this DynaClass.
- */
- protected DynaProperty[] properties = null;
-
-
- /**
- * The set of dynamic properties that are part of this DynaClass,
- * keyed by the property name. Individual descriptor instances will
- * be the same instances as those in the {@code properties} list.
- */
- protected HashMap propertiesMap = new HashMap<>();
-
-
-
-
-
- private static final ContextClassLoaderLocal from the java.util.Timezone}
- * set or use the system default if no time zone is set.
- * @return the {@code ZoneId}
- */
- private ZoneId getZoneId() {
- return timeZone == null ? ZoneId.systemDefault() : timeZone.toZoneId();
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/DoubleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/DoubleConverter.java
deleted file mode 100644
index 1a8de7853..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/DoubleConverter.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-/**
- * {@link NumberConverter} implementation that handles conversion to
- * and from java.lang.Double objects.
- *
- * This implementation can be configured to handle conversion either
- * by using Double's default String conversion, or by using a Locale's pattern
- * or by specifying a format pattern. See the {@link NumberConverter}
- * documentation for further details.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.3
- */
-public final class DoubleConverter extends NumberConverter {
-
- /**
- * Construct a java.lang.DoubleConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public DoubleConverter() {
- super(true);
- }
-
- /**
- * Construct a java.lang.DoubleConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public DoubleConverter(final Object defaultValue) {
- super(true, defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class getDefaultType() {
- return Double.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/DurationConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/DurationConverter.java
deleted file mode 100644
index ea7866c65..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/DurationConverter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.Duration;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.time.Duration objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.Duration
- */
-public final class DurationConverter extends AbstractConverter {
-
- /**
- * Construct a java.time.DurationConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public DurationConverter() {
- super();
- }
-
- /**
- * Construct a java.time.DurationConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public DurationConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return Duration.class;
- }
-
- /**
- *
Convert a java.time.Duration or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (Duration.class.equals(type)) {
- return type.cast(Duration.parse((String.valueOf(value))));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/EnumConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/EnumConverter.java
deleted file mode 100644
index bf5386979..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/EnumConverter.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.lang.Enum objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.lang.Enum
- */
-public final class EnumConverter extends AbstractConverter {
-
- /**
- * Construct a java.lang.EnumConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public EnumConverter() {
- super();
- }
-
- /**
- * Construct a java.lang.EnumConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public EnumConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return Enum.class;
- }
-
- /**
- *
Convert a java.lang.Enum or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @SuppressWarnings({ "rawtypes" })
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (Enum.class.isAssignableFrom(type)) {
- final String enumValue = String.valueOf(value);
- final T[] constants = type.getEnumConstants();
- if (constants == null) {
- throw conversionException(type, value);
- }
- for (final T candidate : constants) {
- if (((Enum)candidate).name().equalsIgnoreCase(enumValue)) {
- return candidate;
- }
- }
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/FileConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/FileConverter.java
deleted file mode 100644
index 718907003..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/FileConverter.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.io.File;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.io.File objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.6
- */
-public final class FileConverter extends AbstractConverter {
-
- /**
- * Construct a java.io.FileConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public FileConverter() {
- super();
- }
-
- /**
- * Construct a java.io.FileConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public FileConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class> getDefaultType() {
- return File.class;
- }
-
- /**
- *
Convert the input object into a java.io.File.
- *
- * @param The target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 1.8.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (File.class.equals(type)) {
- return type.cast(new File(value.toString()));
- }
-
- throw conversionException(type, value);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/FloatConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/FloatConverter.java
deleted file mode 100644
index 573543614..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/FloatConverter.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-/**
- * {@link NumberConverter} implementation that handles conversion to
- * and from java.lang.Float objects.
- *
- * This implementation can be configured to handle conversion either
- * by using Float's default String conversion, or by using a Locale's pattern
- * or by specifying a format pattern. See the {@link NumberConverter}
- * documentation for further details.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.3
- */
-public final class FloatConverter extends NumberConverter {
-
- /**
- * Construct a java.lang.FloatConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public FloatConverter() {
- super(true);
- }
-
- /**
- * Construct a java.lang.FloatConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public FloatConverter(final Object defaultValue) {
- super(true, defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class getDefaultType() {
- return Float.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/IntegerConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/IntegerConverter.java
deleted file mode 100644
index da51a3f7d..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/IntegerConverter.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-/**
- * {@link NumberConverter} implementation that handles conversion to
- * and from java.lang.Integer objects.
- *
- * This implementation can be configured to handle conversion either
- * by using Integer's default String conversion, or by using a Locale's pattern
- * or by specifying a format pattern. See the {@link NumberConverter}
- * documentation for further details.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.3
- */
-public final class IntegerConverter extends NumberConverter {
-
- /**
- * Construct a java.lang.IntegerConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public IntegerConverter() {
- super(false);
- }
-
- /**
- * Construct a java.lang.IntegerConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public IntegerConverter(final Object defaultValue) {
- super(false, defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class getDefaultType() {
- return Integer.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java
deleted file mode 100644
index e37fdeacf..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LocalDateConverter.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.LocalDate;
-
-/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from java.time.LocalDate objects.
- *
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
- *
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.LocalDate
- */
-public final class LocalDateConverter extends DateTimeConverter {
-
- /**
- * Construct a java.time.LocalDateConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public LocalDateConverter() {
- super();
- }
-
- /**
- * Construct a java.time.LocalDateConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public LocalDateConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- */
- @Override
- protected Class> getDefaultType() {
- return LocalDate.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LocalDateTimeConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LocalDateTimeConverter.java
deleted file mode 100644
index 2c355e550..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LocalDateTimeConverter.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.LocalDateTime;
-
-/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from java.time.LocalDateTime objects.
- *
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
- *
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.LocalDateTime
- */
-public final class LocalDateTimeConverter extends DateTimeConverter {
-
- /**
- * Construct a java.time.LocalDateTimeConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public LocalDateTimeConverter() {
- super();
- }
-
- /**
- * Construct a java.time.LocalDateTimeConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public LocalDateTimeConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- */
- @Override
- protected Class> getDefaultType() {
- return LocalDateTime.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LocalTimeConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LocalTimeConverter.java
deleted file mode 100644
index 176d299ce..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LocalTimeConverter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.LocalTime;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.time.LocalTime objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.LocalTime
- */
-public final class LocalTimeConverter extends AbstractConverter {
-
- /**
- * Construct a java.time.LocalTimeConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public LocalTimeConverter() {
- super();
- }
-
- /**
- * Construct a java.time.LocalTimeConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public LocalTimeConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return LocalTime.class;
- }
-
- /**
- *
Convert a java.time.LocalTime or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (LocalTime.class.equals(type)) {
- return type.cast(LocalTime.parse((String.valueOf(value))));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LongConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LongConverter.java
deleted file mode 100644
index bcac3bb24..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/LongConverter.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-/**
- * {@link NumberConverter} implementation that handles conversion to
- * and from java.lang.Long objects.
- *
- * This implementation can be configured to handle conversion either
- * by using Long's default String conversion, or by using a Locale's pattern
- * or by specifying a format pattern. See the {@link NumberConverter}
- * documentation for further details.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.3
- */
-public final class LongConverter extends NumberConverter {
-
- /**
- * Construct a java.lang.LongConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public LongConverter() {
- super(false);
- }
-
- /**
- * Construct a java.lang.LongConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public LongConverter(final Object defaultValue) {
- super(false, defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class getDefaultType() {
- return Long.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/MonthDayConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/MonthDayConverter.java
deleted file mode 100644
index b9b342aab..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/MonthDayConverter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.MonthDay;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.time.MonthDay objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.MonthDay
- */
-public final class MonthDayConverter extends AbstractConverter {
-
- /**
- * Construct a java.time.MonthDayConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public MonthDayConverter() {
- super();
- }
-
- /**
- * Construct a java.time.MonthDayConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public MonthDayConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return MonthDay.class;
- }
-
- /**
- *
Convert a java.time.MonthDay or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (MonthDay.class.equals(type)) {
- return type.cast(MonthDay.parse((String.valueOf(value))));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/NumberConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/NumberConverter.java
deleted file mode 100644
index 4e312f701..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/NumberConverter.java
+++ /dev/null
@@ -1,565 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.lang.Number objects.
- *
- * This implementation handles conversion for the following
- * {@code java.lang.Number} types.
- *
- *
{@code java.lang.Byte}
- *
{@code java.lang.Short}
- *
{@code java.lang.Integer}
- *
{@code java.lang.Long}
- *
{@code java.lang.Float}
- *
{@code java.lang.Double}
- *
{@code java.math.BigDecimal}
- *
{@code java.math.BigInteger}
- *
- *
- *
String Conversions (to and from)
- * This class provides a number of ways in which number
- * conversions to/from Strings can be achieved:
- *
- *
Using the default format for the default Locale, configure using:
- *
- *
{@code setUseLocaleFormat(true)}
- *
- *
- *
Using the default format for a specified Locale, configure using:
- *
- *
{@code setLocale(Locale)}
- *
- *
- *
Using a specified pattern for the default Locale, configure using:
- *
- *
{@code setPattern(String)}
- *
- *
- *
Using a specified pattern for a specified Locale, configure using:
- *
- *
{@code setPattern(String)}
- *
{@code setLocale(Locale)}
- *
- *
- *
If none of the above are configured the
- * {@code toNumber(String)} method is used to convert
- * from String to Number and the Number's
- * {@code toString()} method used to convert from
- * Number to String.
- *
- *
- *
- * N.B.Patterns can only be specified using the standard
- * pattern characters and NOT in localized form (see {@code java.text.DecimalFormat}).
- * For example to cater for number styles used in Germany such as {@code 0.000,00} the pattern
- * is specified in the normal form {@code 0,000.00
and the locale set to Locale.GERMANY}.
- *
- * @since 1.8.0
- */
-public abstract class NumberConverter extends AbstractConverter {
-
- private static final Integer ZERO = Integer.valueOf(0);
- private static final Integer ONE = Integer.valueOf(1);
-
- private String pattern;
- private final boolean allowDecimals;
- private boolean useLocaleFormat;
- private Locale locale;
-
-
-
- /**
- * Construct a java.lang.NumberConverter
- * that throws a {@code ConversionException} if a error occurs.
- *
- * @param allowDecimals Indicates whether decimals are allowed
- */
- public NumberConverter(final boolean allowDecimals) {
- super();
- this.allowDecimals = allowDecimals;
- }
-
- /**
- * Construct a {@code java.lang.Number} Converter that returns
- * a default value if an error occurs.
- *
- * @param allowDecimals Indicates whether decimals are allowed
- * @param defaultValue The default value to be returned
- */
- public NumberConverter(final boolean allowDecimals, final Object defaultValue) {
- super();
- this.allowDecimals = allowDecimals;
- setDefaultValue(defaultValue);
- }
-
-
-
- /**
- * Return whether decimals are allowed in the number.
- *
- * @return Whether decimals are allowed in the number
- */
- public boolean isAllowDecimals() {
- return allowDecimals;
- }
-
- /**
- * Set whether a format should be used to convert
- * the Number.
- *
- * @param useLocaleFormat {@code true} if a number format
- * should be used.
- */
- public void setUseLocaleFormat(final boolean useLocaleFormat) {
- this.useLocaleFormat = useLocaleFormat;
- }
-
- /**
- * Return the number format pattern used to convert
- * Numbers to/from a {@code java.lang.String}
- * (or {@code null} if none specified).
- *
- * See {@code java.text.DecimalFormat} for details
- * of how to specify the pattern.
- *
- * @return The format pattern.
- */
- public String getPattern() {
- return pattern;
- }
-
- /**
- * Set a number format pattern to use to convert
- * Numbers to/from a {@code java.lang.String}.
- *
- * See {@code java.text.DecimalFormat} for details
- * of how to specify the pattern.
- *
- * @param pattern The format pattern.
- */
- public void setPattern(final String pattern) {
- this.pattern = pattern;
- setUseLocaleFormat(true);
- }
-
- /**
- * Return the Locale for the Converter
- * (or {@code null} if none specified).
- *
- * @return The locale to use for conversion
- */
- public Locale getLocale() {
- return locale;
- }
-
- /**
- * Set the Locale for the Converter.
- *
- * @param locale The locale to use for conversion
- */
- public void setLocale(final Locale locale) {
- this.locale = locale;
- setUseLocaleFormat(true);
- }
-
-
-
- /**
- * Convert an input Number object into a String.
- *
- * @param value The input value to be converted
- * @return the converted String value.
- * @throws Throwable if an error occurs converting to a String
- */
- @Override
- protected String convertToString(final Object value) throws Throwable {
-
- String result = null;
- if (useLocaleFormat && value instanceof Number) {
- final NumberFormat format = getFormat();
- format.setGroupingUsed(false);
- result = format.format(value);
- if (log().isDebugEnabled()) {
- log().debug(" Converted to String using format '" + result + "'");
- }
-
- } else {
- result = value.toString();
- if (log().isDebugEnabled()) {
- log().debug(" Converted to String using toString() '" + result + "'");
- }
- }
- return result;
-
- }
-
- /**
- * Convert the input object into a Number object of the
- * specified type.
- *
- * @param Target type of the conversion.
- * @param targetType Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- */
- @Override
- protected T convertToType(final Class targetType, final Object value) throws Throwable {
-
- final Class> sourceType = value.getClass();
- // Handle Number
- if (value instanceof Number) {
- return toNumber(sourceType, targetType, (Number)value);
- }
-
- // Handle Boolean
- if (value instanceof Boolean) {
- return toNumber(sourceType, targetType, ((Boolean)value).booleanValue() ? ONE : ZERO);
- }
-
- // Handle Date --> Long
- if (value instanceof Date && Long.class.equals(targetType)) {
- return targetType.cast(Long.valueOf(((Date)value).getTime()));
- }
-
- // Handle Calendar --> Long
- if (value instanceof Calendar && Long.class.equals(targetType)) {
- return targetType.cast(Long.valueOf(((Calendar)value).getTime().getTime()));
- }
-
- // Convert all other types to String & handle
- final String stringValue = value.toString().trim();
- if (stringValue.length() == 0) {
- return handleMissing(targetType);
- }
-
- // Convert/Parse a String
- Number number = null;
- if (useLocaleFormat) {
- final NumberFormat format = getFormat();
- number = parse(sourceType, targetType, stringValue, format);
- } else {
- if (log().isDebugEnabled()) {
- log().debug(" No NumberFormat, using default conversion");
- }
- number = toNumber(sourceType, targetType, stringValue);
- }
-
- // Ensure the correct number type is returned
- return toNumber(sourceType, targetType, number);
-
- }
-
- /**
- * Convert any Number object to the specified type for this
- * Converter.
- *
- * This method handles conversion to the following types:
- *
- *
{@code java.lang.Byte}
- *
{@code java.lang.Short}
- *
{@code java.lang.Integer}
- *
{@code java.lang.Long}
- *
{@code java.lang.Float}
- *
{@code java.lang.Double}
- *
{@code java.math.BigDecimal}
- *
{@code java.math.BigInteger}
- *
- * @param sourceType The type being converted from
- * @param targetType The Number type to convert to
- * @param value The Number to convert.
- *
- * @return The converted value.
- */
- private T toNumber(final Class> sourceType, final Class targetType, final Number value) {
-
- // Correct Number type already
- if (targetType.equals(value.getClass())) {
- return targetType.cast(value);
- }
-
- // Byte
- if (targetType.equals(Byte.class)) {
- final long longValue = value.longValue();
- if (longValue > Byte.MAX_VALUE) {
- throw new ConversionException(toString(sourceType) + " value '" + value
- + "' is too large for " + toString(targetType));
- }
- if (longValue < Byte.MIN_VALUE) {
- throw new ConversionException(toString(sourceType) + " value '" + value
- + "' is too small " + toString(targetType));
- }
- return targetType.cast(Byte.valueOf(value.byteValue()));
- }
-
- // Short
- if (targetType.equals(Short.class)) {
- final long longValue = value.longValue();
- if (longValue > Short.MAX_VALUE) {
- throw new ConversionException(toString(sourceType) + " value '" + value
- + "' is too large for " + toString(targetType));
- }
- if (longValue < Short.MIN_VALUE) {
- throw new ConversionException(toString(sourceType) + " value '" + value
- + "' is too small " + toString(targetType));
- }
- return targetType.cast(Short.valueOf(value.shortValue()));
- }
-
- // Integer
- if (targetType.equals(Integer.class)) {
- final long longValue = value.longValue();
- if (longValue > Integer.MAX_VALUE) {
- throw new ConversionException(toString(sourceType) + " value '" + value
- + "' is too large for " + toString(targetType));
- }
- if (longValue < Integer.MIN_VALUE) {
- throw new ConversionException(toString(sourceType) + " value '" + value
- + "' is too small " + toString(targetType));
- }
- return targetType.cast(Integer.valueOf(value.intValue()));
- }
-
- // Long
- if (targetType.equals(Long.class)) {
- return targetType.cast(Long.valueOf(value.longValue()));
- }
-
- // Float
- if (targetType.equals(Float.class)) {
- if (value.doubleValue() > Float.MAX_VALUE) {
- throw new ConversionException(toString(sourceType) + " value '" + value
- + "' is too large for " + toString(targetType));
- }
- return targetType.cast(Float.valueOf(value.floatValue()));
- }
-
- // Double
- if (targetType.equals(Double.class)) {
- return targetType.cast(Double.valueOf(value.doubleValue()));
- }
-
- // BigDecimal
- if (targetType.equals(BigDecimal.class)) {
- if (value instanceof Float || value instanceof Double) {
- return targetType.cast(new BigDecimal(value.toString()));
- } else if (value instanceof BigInteger) {
- return targetType.cast(new BigDecimal((BigInteger)value));
- } else if (value instanceof BigDecimal) {
- return targetType.cast(new BigDecimal(value.toString()));
- } else {
- return targetType.cast(BigDecimal.valueOf(value.longValue()));
- }
- }
-
- // BigInteger
- if (targetType.equals(BigInteger.class)) {
- if (value instanceof BigDecimal) {
- return targetType.cast(((BigDecimal)value).toBigInteger());
- }
- return targetType.cast(BigInteger.valueOf(value.longValue()));
- }
-
- final String msg = toString(getClass()) + " cannot handle conversion to '"
- + toString(targetType) + "'";
- if (log().isWarnEnabled()) {
- log().warn(" " + msg);
- }
- throw new ConversionException(msg);
-
- }
-
- /**
- * Default String to Number conversion.
- *
- * This method handles conversion from a String to the following types:
- *
- *
{@code java.lang.Byte}
- *
{@code java.lang.Short}
- *
{@code java.lang.Integer}
- *
{@code java.lang.Long}
- *
{@code java.lang.Float}
- *
{@code java.lang.Double}
- *
{@code java.math.BigDecimal}
- *
{@code java.math.BigInteger}
- *
- * @param sourceType The type being converted from
- * @param targetType The Number type to convert to
- * @param value The String value to convert.
- *
- * @return The converted Number value.
- */
- private Number toNumber(final Class> sourceType, final Class> targetType, final String value) {
-
- // Byte
- if (targetType.equals(Byte.class)) {
- return Byte.valueOf(value);
- }
-
- // Short
- if (targetType.equals(Short.class)) {
- return Short.valueOf(value);
- }
-
- // Integer
- if (targetType.equals(Integer.class)) {
- return Integer.valueOf(value);
- }
-
- // Long
- if (targetType.equals(Long.class)) {
- return Long.valueOf(value);
- }
-
- // Float
- if (targetType.equals(Float.class)) {
- return Float.valueOf(value);
- }
-
- // Double
- if (targetType.equals(Double.class)) {
- return Double.valueOf(value);
- }
-
- // BigDecimal
- if (targetType.equals(BigDecimal.class)) {
- return new BigDecimal(value);
- }
-
- // BigInteger
- if (targetType.equals(BigInteger.class)) {
- return new BigInteger(value);
- }
-
- final String msg = toString(getClass()) + " cannot handle conversion from '" +
- toString(sourceType) + "' to '" + toString(targetType) + "'";
- if (log().isWarnEnabled()) {
- log().warn(" " + msg);
- }
- throw new ConversionException(msg);
- }
-
- /**
- * Provide a String representation of this number converter.
- *
- * @return A String representation of this number converter
- */
- @Override
- public String toString() {
- final StringBuilder buffer = new StringBuilder();
- buffer.append(toString(getClass()));
- buffer.append("[UseDefault=");
- buffer.append(isUseDefault());
- buffer.append(", UseLocaleFormat=");
- buffer.append(useLocaleFormat);
- if (pattern != null) {
- buffer.append(", Pattern=");
- buffer.append(pattern);
- }
- if (locale != null) {
- buffer.append(", Locale=");
- buffer.append(locale);
- }
- buffer.append(']');
- return buffer.toString();
- }
-
- /**
- * Return a NumberFormat to use for Conversion.
- *
- * @return The NumberFormat.
- */
- private NumberFormat getFormat() {
- NumberFormat format = null;
- if (pattern != null) {
- if (locale == null) {
- if (log().isDebugEnabled()) {
- log().debug(" Using pattern '" + pattern + "'");
- }
- format = new DecimalFormat(pattern);
- } else {
- if (log().isDebugEnabled()) {
- log().debug(" Using pattern '" + pattern + "'" +
- " with Locale[" + locale + "]");
- }
- final DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
- format = new DecimalFormat(pattern, symbols);
- }
- } else {
- if (locale == null) {
- if (log().isDebugEnabled()) {
- log().debug(" Using default Locale format");
- }
- format = NumberFormat.getInstance();
- } else {
- if (log().isDebugEnabled()) {
- log().debug(" Using Locale[" + locale + "] format");
- }
- format = NumberFormat.getInstance(locale);
- }
- }
- if (!allowDecimals) {
- format.setParseIntegerOnly(true);
- }
- return format;
- }
-
- /**
- * Convert a String into a {@code Number} object.
- * @param sourceType the source type of the conversion
- * @param targetType The type to convert the value to
- * @param value The String date value.
- * @param format The NumberFormat to parse the String value.
- *
- * @return The converted Number object.
- * @throws ConversionException if the String cannot be converted.
- */
- private Number parse(final Class> sourceType, final Class> targetType, final String value, final NumberFormat format) {
- final ParsePosition pos = new ParsePosition(0);
- final Number parsedNumber = format.parse(value, pos);
- if (pos.getErrorIndex() >= 0 || pos.getIndex() != value.length() || parsedNumber == null) {
- String msg = "Error converting from '" + toString(sourceType) + "' to '" + toString(targetType) + "'";
- if (format instanceof DecimalFormat) {
- msg += " using pattern '" + ((DecimalFormat)format).toPattern() + "'";
- }
- if (locale != null) {
- msg += " for locale=[" + locale + "]";
- }
- if (log().isDebugEnabled()) {
- log().debug(" " + msg);
- }
- throw new ConversionException(msg);
- }
- return parsedNumber;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
deleted file mode 100644
index a85751410..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/OffsetDateTimeConverter.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.OffsetDateTime;
-
-/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from java.time.OffsetDateTime objects.
- *
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
- *
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.OffsetDateTime
- */
-public final class OffsetDateTimeConverter extends DateTimeConverter {
-
- /**
- * Construct a java.time.OffsetDateTimeConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public OffsetDateTimeConverter() {
- super();
- }
-
- /**
- * Construct a java.time.OffsetDateTimeConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public OffsetDateTimeConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- */
- @Override
- protected Class> getDefaultType() {
- return OffsetDateTime.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/OffsetTimeConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/OffsetTimeConverter.java
deleted file mode 100644
index 0c2795058..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/OffsetTimeConverter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.OffsetTime;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.time.OffsetTime objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.OffsetTime
- */
-public final class OffsetTimeConverter extends AbstractConverter {
-
- /**
- * Construct a java.time.OffsetTimeConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public OffsetTimeConverter() {
- super();
- }
-
- /**
- * Construct a java.time.OffsetTimeConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public OffsetTimeConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return OffsetTime.class;
- }
-
- /**
- *
Convert a java.time.OffsetTime or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (OffsetTime.class.equals(type)) {
- return type.cast(OffsetTime.parse((String.valueOf(value))));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/PathConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/PathConverter.java
deleted file mode 100644
index d454f29bd..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/PathConverter.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.nio.file.Path objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 2.0
- */
-public final class PathConverter extends AbstractConverter {
-
- /**
- * Construct a java.nio.file.PathConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public PathConverter() {
- super();
- }
-
- /**
- * Construct a java.nio.file.PathConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public PathConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return Path.class;
- }
-
- /**
- *
Convert a java.nio.file.Path or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (Path.class.isAssignableFrom(type)) {
- return type.cast(Paths.get(String.valueOf(value)));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/PeriodConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/PeriodConverter.java
deleted file mode 100644
index a714a98b9..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/PeriodConverter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.Period;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.time.Period objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.Period
- */
-public final class PeriodConverter extends AbstractConverter {
-
- /**
- * Construct a java.time.PeriodConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public PeriodConverter() {
- super();
- }
-
- /**
- * Construct a java.time.PeriodConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public PeriodConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return Period.class;
- }
-
- /**
- *
Convert a java.time.Period or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (Period.class.equals(type)) {
- return type.cast(Period.parse((String.valueOf(value))));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ShortConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ShortConverter.java
deleted file mode 100644
index 99e236288..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ShortConverter.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-/**
- * {@link NumberConverter} implementation that handles conversion to
- * and from java.lang.Short objects.
- *
- * This implementation can be configured to handle conversion either
- * by using Short's default String conversion, or by using a Locale's pattern
- * or by specifying a format pattern. See the {@link NumberConverter}
- * documentation for further details.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.3
- */
-public final class ShortConverter extends NumberConverter {
-
- /**
- * Construct a java.lang.ShortConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public ShortConverter() {
- super(false);
- }
-
- /**
- * Construct a java.lang.ShortConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public ShortConverter(final Object defaultValue) {
- super(false, defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class getDefaultType() {
- return Short.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/SqlDateConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/SqlDateConverter.java
deleted file mode 100644
index 109e6a636..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/SqlDateConverter.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.sql.Date;
-
-/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from java.sql.Date objects.
- *
- * This implementation can be configured to handle conversion either
- * by using java.sql.Date's default String conversion, or by using a
- * Locale's default format or by specifying a set of format patterns.
- * See the {@link DateTimeConverter} documentation for further details.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.3
- */
-public final class SqlDateConverter extends DateTimeConverter {
-
- /**
- * Construct a java.sql.DateConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public SqlDateConverter() {
- super();
- }
-
- /**
- * Construct a java.sql.DateConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public SqlDateConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class> getDefaultType() {
- return Date.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/SqlTimeConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/SqlTimeConverter.java
deleted file mode 100644
index 4fdc9442a..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/SqlTimeConverter.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.sql.Time;
-import java.text.DateFormat;
-import java.util.Locale;
-import java.util.TimeZone;
-
-/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from java.sql.Time objects.
- *
- * This implementation can be configured to handle conversion either
- * by using java.sql.Time's default String conversion, or by using a
- * Locale's default format or by specifying a set of format patterns.
- * See the {@link DateTimeConverter} documentation for further details.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.3
- */
-public final class SqlTimeConverter extends DateTimeConverter {
-
- /**
- * Construct a java.sql.TimeConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public SqlTimeConverter() {
- super();
- }
-
- /**
- * Construct a java.sql.TimeConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public SqlTimeConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class> getDefaultType() {
- return Time.class;
- }
-
- /**
- * Return a {@code DateFormat} for the Locale.
- * @param locale TODO
- * @param timeZone TODO
- *
- * @return The DateFormat.
- * @since 1.8.0
- */
- @Override
- protected DateFormat getFormat(final Locale locale, final TimeZone timeZone) {
- DateFormat format = null;
- if (locale == null) {
- format = DateFormat.getTimeInstance(DateFormat.SHORT);
- } else {
- format = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
- }
- if (timeZone != null) {
- format.setTimeZone(timeZone);
- }
- return format;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/SqlTimestampConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/SqlTimestampConverter.java
deleted file mode 100644
index c4576d8cc..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/SqlTimestampConverter.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.sql.Timestamp;
-import java.text.DateFormat;
-import java.util.Locale;
-import java.util.TimeZone;
-
-/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from java.sql.Timestamp objects.
- *
- * This implementation can be configured to handle conversion either
- * by using java.sql.Timestamp's default String conversion, or by using a
- * Locale's default format or by specifying a set of format patterns.
- * See the {@link DateTimeConverter} documentation for further details.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.3
- */
-public final class SqlTimestampConverter extends DateTimeConverter {
-
- /**
- * Construct a java.sql.TimestampConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public SqlTimestampConverter() {
- super();
- }
-
- /**
- * Construct a java.sql.TimestampConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public SqlTimestampConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class> getDefaultType() {
- return Timestamp.class;
- }
-
- /**
- * Return a {@code DateFormat} for the Locale.
- * @param locale TODO
- * @param timeZone TODO
- *
- * @return The DateFormat.
- * @since 1.8.0
- */
- @Override
- protected DateFormat getFormat(final Locale locale, final TimeZone timeZone) {
- DateFormat format = null;
- if (locale == null) {
- format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
- } else {
- format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
- }
- if (timeZone != null) {
- format.setTimeZone(timeZone);
- }
- return format;
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/StringConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/StringConverter.java
deleted file mode 100644
index 2d1ca40c0..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/StringConverter.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter}
- * implementation that converts an incoming
- * object into a {@code java.lang.String} object.
- *
- * Note that ConvertUtils really is designed to do string->object conversions,
- * and offers very little support for object->string conversions. The
- * ConvertUtils/ConvertUtilsBean methods only select a converter to apply
- * based upon the target type being converted to, and generally assume that
- * the input is a string (by calling its toString method if needed).
- *
- * This class is therefore just a dummy converter that converts its input
- * into a string by calling the input object's toString method and returning
- * that value.
- *
- * It is possible to replace this converter with something that has a big
- * if/else statement that selects behavior based on the real type of the
- * object being converted (or possibly has a map of converters, and looks
- * them up based on the class of the input object). However this is not part
- * of the existing ConvertUtils framework.
- *
- *
- * @since 1.3
- */
-public final class StringConverter extends AbstractConverter {
-
- /**
- * Construct a java.lang.StringConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public StringConverter() {
- super();
- }
-
- /**
- * Construct a java.lang.StringConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public StringConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class> getDefaultType() {
- return String.class;
- }
-
- /**
- * Convert the specified input object into an output object of the
- * specified type.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 1.8.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- // We have to support Object, too, because this class is sometimes
- // used for a standard to Object conversion
- if (String.class.equals(type) || Object.class.equals(type)) {
- return type.cast(value.toString());
- }
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/URIConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/URIConverter.java
deleted file mode 100644
index 902ebe2ed..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/URIConverter.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.net.URI;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.net.URI objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 2.0
- */
-public final class URIConverter extends AbstractConverter {
-
- /**
- * Construct a java.net.URIConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public URIConverter() {
- super();
- }
-
- /**
- * Construct a java.net.URIConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public URIConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return URI.class;
- }
-
- /**
- *
Convert a java.net.URI or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (URI.class.equals(type)) {
- return type.cast(new URI(value.toString()));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/URLConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/URLConverter.java
deleted file mode 100644
index d4f269506..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/URLConverter.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.net.URL;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.net.URL objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 1.3
- */
-public final class URLConverter extends AbstractConverter {
-
- /**
- * Construct a java.net.URLConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public URLConverter() {
- super();
- }
-
- /**
- * Construct a java.net.URLConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public URLConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 1.8.0
- */
- @Override
- protected Class> getDefaultType() {
- return URL.class;
- }
-
- /**
- *
Convert a java.net.URL or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 1.8.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (URL.class.equals(type)) {
- return type.cast(new URL(value.toString()));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/UUIDConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/UUIDConverter.java
deleted file mode 100644
index c2f09e6d5..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/UUIDConverter.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.util.UUID;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.util.UUID objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- * @since 2.0
- */
-public final class UUIDConverter extends AbstractConverter {
-
- /**
- * Construct a java.util.UUIDConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public UUIDConverter() {
- super();
- }
-
- /**
- * Construct a java.util.UUIDConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public UUIDConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return UUID.class;
- }
-
- /**
- *
Convert a java.util.UUID or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (UUID.class.equals(type)) {
- return type.cast(UUID.fromString(String.valueOf(value)));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/YearConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/YearConverter.java
deleted file mode 100644
index 89395baf0..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/YearConverter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.Year;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.time.Year objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.Year
- */
-public final class YearConverter extends AbstractConverter {
-
- /**
- * Construct a java.time.YearConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public YearConverter() {
- super();
- }
-
- /**
- * Construct a java.time.YearConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public YearConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return Year.class;
- }
-
- /**
- *
Convert a java.time.Year or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (Year.class.equals(type)) {
- return type.cast(Year.parse((String.valueOf(value))));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/YearMonthConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/YearMonthConverter.java
deleted file mode 100644
index a47e9f680..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/YearMonthConverter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.YearMonth;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.time.YearMonth objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.YearMonth
- */
-public final class YearMonthConverter extends AbstractConverter {
-
- /**
- * Construct a java.time.YearMonthConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public YearMonthConverter() {
- super();
- }
-
- /**
- * Construct a java.time.YearMonthConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public YearMonthConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return YearMonth.class;
- }
-
- /**
- *
Convert a java.time.YearMonth or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (YearMonth.class.equals(type)) {
- return type.cast(YearMonth.parse((String.valueOf(value))));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ZoneIdConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ZoneIdConverter.java
deleted file mode 100644
index f5e5928e4..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ZoneIdConverter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.ZoneId;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.time.ZoneId objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.ZoneId
- */
-public final class ZoneIdConverter extends AbstractConverter {
-
- /**
- * Construct a java.time.ZoneIdConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public ZoneIdConverter() {
- super();
- }
-
- /**
- * Construct a java.time.ZoneIdConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public ZoneIdConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return ZoneId.class;
- }
-
- /**
- *
Convert a java.time.ZoneId or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (ZoneId.class.equals(type)) {
- return type.cast(ZoneId.of((String.valueOf(value))));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ZoneOffsetConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ZoneOffsetConverter.java
deleted file mode 100644
index 00133ca9b..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ZoneOffsetConverter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.ZoneOffset;
-
-/**
- * {@link org.apache.commons.beanutils2.Converter} implementation that handles conversion
- * to and from java.time.ZoneOffset objects.
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.ZoneOffset
- */
-public final class ZoneOffsetConverter extends AbstractConverter {
-
- /**
- * Construct a java.time.ZoneOffsetConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public ZoneOffsetConverter() {
- super();
- }
-
- /**
- * Construct a java.time.ZoneOffsetConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public ZoneOffsetConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- * @since 2.0
- */
- @Override
- protected Class> getDefaultType() {
- return ZoneOffset.class;
- }
-
- /**
- *
Convert a java.time.ZoneOffset or object into a String.
- *
- * @param Target type of the conversion.
- * @param type Data type to which this value should be converted.
- * @param value The input value to be converted.
- * @return The converted value.
- * @throws Throwable if an error occurs converting to the specified type
- * @since 2.0
- */
- @Override
- protected T convertToType(final Class type, final Object value) throws Throwable {
- if (ZoneOffset.class.equals(type)) {
- return type.cast(ZoneOffset.of((String.valueOf(value))));
- }
-
- throw conversionException(type, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ZonedDateTimeConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ZonedDateTimeConverter.java
deleted file mode 100644
index c1c9f1e53..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/ZonedDateTimeConverter.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.converters;
-
-import java.time.ZonedDateTime;
-
-/**
- * {@link DateTimeConverter} implementation that handles conversion to
- * and from java.time.ZonedDateTime objects.
- *
- * This implementation can be configured to handle conversion either
- * by using a Locale's default format or by specifying a set of format
- * patterns (note, there is no default String conversion for Calendar).
- * See the {@link DateTimeConverter} documentation for further details.
- *
- *
- * Can be configured to either return a default value or throw a
- * {@code ConversionException} if a conversion error occurs.
- *
- *
- * @since 2.0
- * @see java.time.ZonedDateTime
- */
-public final class ZonedDateTimeConverter extends DateTimeConverter {
-
- /**
- * Construct a java.time.ZonedDateTimeConverter that throws
- * a {@code ConversionException} if an error occurs.
- */
- public ZonedDateTimeConverter() {
- super();
- }
-
- /**
- * Construct a java.time.ZonedDateTimeConverter that returns
- * a default value if an error occurs.
- *
- * @param defaultValue The default value to be returned
- * if the value to be converted is missing or an error
- * occurs converting the value.
- */
- public ZonedDateTimeConverter(final Object defaultValue) {
- super(defaultValue);
- }
-
- /**
- * Return the default type this {@code Converter} handles.
- *
- * @return The default type this {@code Converter} handles.
- */
- @Override
- protected Class> getDefaultType() {
- return ZonedDateTime.class;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/package-info.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/package-info.java
deleted file mode 100644
index e29d80ca0..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/converters/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Standard implementations of the
- * {@link org.apache.commons.beanutils2.Converter} interface that are
- * pre-registered with {@link org.apache.commons.beanutils2.ConvertUtils} at
- * startup time.
- */
-package org.apache.commons.beanutils2.converters;
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/expression/DefaultResolver.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/expression/DefaultResolver.java
deleted file mode 100644
index 32e30d8dd..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/expression/DefaultResolver.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.expression;
-
-/**
- * Default Property Name Expression {@link Resolver} Implementation.
- *
- * This class assists in resolving property names in the following five formats,
- * with the layout of an identifying String in parentheses:
- *
- *
Simple ({@code name}) - The specified
- * {@code name} identifies an individual property of a particular
- * JavaBean. The name of the actual getter or setter method to be used
- * is determined using standard JavaBeans introspection, so that (unless
- * overridden by a {@code BeanInfo} class, a property named "xyz"
- * will have a getter method named {@code getXyz()} or (for boolean
- * properties only) {@code isXyz()}, and a setter method named
- * {@code setXyz()}.
- *
Nested ({@code name1.name2.name3}) The first
- * name element is used to select a property getter, as for simple
- * references above. The object returned for this property is then
- * consulted, using the same approach, for a property getter for a
- * property named {@code name2}, and so on. The property value that
- * is ultimately retrieved or modified is the one identified by the
- * last name element.
- *
Indexed ({@code name[index]}) - The underlying
- * property value is assumed to be an array, or this JavaBean is assumed
- * to have indexed property getter and setter methods. The appropriate
- * (zero-relative) entry in the array is selected. {@code List}
- * objects are now also supported for read/write. You simply need to define
- * a getter that returns the {@code List}
- *
Mapped ({@code name(key)}) - The JavaBean
- * is assumed to have an property getter and setter methods with an
- * additional attribute of type {@code java.lang.String}.
- *
Combined ({@code name1.name2[index].name3(key)}) -
- * Combining mapped, nested, and indexed references is also
- * supported.
- *
- *
- * @since 1.8.0
- */
-public class DefaultResolver implements Resolver {
-
- private static final char NESTED = '.';
- private static final char MAPPED_START = '(';
- private static final char MAPPED_END = ')';
- private static final char INDEXED_START = '[';
- private static final char INDEXED_END = ']';
-
- /**
- * Default Constructor.
- */
- public DefaultResolver() {
- }
-
- /**
- * Return the index value from the property expression or -1.
- *
- * @param expression The property expression
- * @return The index value or -1 if the property is not indexed
- * @throws IllegalArgumentException If the indexed property is illegally
- * formed or has an invalid (non-numeric) value.
- */
- @Override
- public int getIndex(final String expression) {
- if (expression == null || expression.length() == 0) {
- return -1;
- }
- for (int i = 0; i < expression.length(); i++) {
- final char c = expression.charAt(i);
- if (c == NESTED || c == MAPPED_START) {
- return -1;
- } else if (c == INDEXED_START) {
- final int end = expression.indexOf(INDEXED_END, i);
- if (end < 0) {
- throw new IllegalArgumentException("Missing End Delimiter");
- }
- final String value = expression.substring(i + 1, end);
- if (value.length() == 0) {
- throw new IllegalArgumentException("No Index Value");
- }
- int index = 0;
- try {
- index = Integer.parseInt(value, 10);
- } catch (final Exception e) {
- throw new IllegalArgumentException("Invalid index value '"
- + value + "'");
- }
- return index;
- }
- }
- return -1;
- }
-
- /**
- * Return the map key from the property expression or {@code null}.
- *
- * @param expression The property expression
- * @return The index value
- * @throws IllegalArgumentException If the mapped property is illegally formed.
- */
- @Override
- public String getKey(final String expression) {
- if (expression == null || expression.length() == 0) {
- return null;
- }
- for (int i = 0; i < expression.length(); i++) {
- final char c = expression.charAt(i);
- if (c == NESTED || c == INDEXED_START) {
- return null;
- } else if (c == MAPPED_START) {
- final int end = expression.indexOf(MAPPED_END, i);
- if (end < 0) {
- throw new IllegalArgumentException("Missing End Delimiter");
- }
- return expression.substring(i + 1, end);
- }
- }
- return null;
- }
-
- /**
- * Return the property name from the property expression.
- *
- * @param expression The property expression
- * @return The property name
- */
- @Override
- public String getProperty(final String expression) {
- if (expression == null || expression.length() == 0) {
- return expression;
- }
- for (int i = 0; i < expression.length(); i++) {
- final char c = expression.charAt(i);
- if ((c == NESTED) || (c == MAPPED_START || c == INDEXED_START)) {
- return expression.substring(0, i);
- }
- }
- return expression;
- }
-
- /**
- * Indicates whether or not the expression
- * contains nested property expressions or not.
- *
- * @param expression The property expression
- * @return The next property expression
- */
- @Override
- public boolean hasNested(final String expression) {
- if (expression == null || expression.length() == 0) {
- return false;
- }
- return remove(expression) != null;
- }
-
- /**
- * Indicate whether the expression is for an indexed property or not.
- *
- * @param expression The property expression
- * @return {@code true} if the expression is indexed,
- * otherwise {@code false}
- */
- @Override
- public boolean isIndexed(final String expression) {
- if (expression == null || expression.length() == 0) {
- return false;
- }
- for (int i = 0; i < expression.length(); i++) {
- final char c = expression.charAt(i);
- if (c == NESTED || c == MAPPED_START) {
- return false;
- } else if (c == INDEXED_START) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Indicate whether the expression is for a mapped property or not.
- *
- * @param expression The property expression
- * @return {@code true} if the expression is mapped,
- * otherwise {@code false}
- */
- @Override
- public boolean isMapped(final String expression) {
- if (expression == null || expression.length() == 0) {
- return false;
- }
- for (int i = 0; i < expression.length(); i++) {
- final char c = expression.charAt(i);
- if (c == NESTED || c == INDEXED_START) {
- return false;
- } else if (c == MAPPED_START) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Extract the next property expression from the
- * current expression.
- *
- * @param expression The property expression
- * @return The next property expression
- */
- @Override
- public String next(final String expression) {
- if (expression == null || expression.length() == 0) {
- return null;
- }
- boolean indexed = false;
- boolean mapped = false;
- for (int i = 0; i < expression.length(); i++) {
- final char c = expression.charAt(i);
- if (indexed) {
- if (c == INDEXED_END) {
- return expression.substring(0, i + 1);
- }
- } else if (mapped) {
- if (c == MAPPED_END) {
- return expression.substring(0, i + 1);
- }
- } else {
- if (c == NESTED) {
- return expression.substring(0, i);
- } else if (c == MAPPED_START) {
- mapped = true;
- } else if (c == INDEXED_START) {
- indexed = true;
- }
- }
- }
- return expression;
- }
-
- /**
- * Remove the last property expression from the
- * current expression.
- *
- * @param expression The property expression
- * @return The new expression value, with first property
- * expression removed - null if there are no more expressions
- */
- @Override
- public String remove(final String expression) {
- if (expression == null || expression.length() == 0) {
- return null;
- }
- final String property = next(expression);
- if (expression.length() == property.length()) {
- return null;
- }
- int start = property.length();
- if (expression.charAt(start) == NESTED) {
- start++;
- }
- return expression.substring(start);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/expression/Resolver.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/expression/Resolver.java
deleted file mode 100644
index 5748f92be..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/expression/Resolver.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2.expression;
-
-/**
- * Property Name Expression Resolver.
- *
- * Methods such as PropertyUtilsBean's {@code setNestedProperty()} method
- * use a {@code Resolver} to process a property name
- * expression and resolve nested, indexed and mapped
- * property names. The following code provides an example usage
- * demonstrating all the methods:
- *
- *
- * // Iterate through a nested property expression
- * while (resolver.hasNested(name)) {
- *
- * // isolate a single property from a nested expression
- * String next = resolver.next(name);
- *
- * // Process...
- * String property = resolver.getProperty(next);
- * if (resolver.isIndexed(next)) {
- *
- * int index = resolver.getIndex(next);
- * bean = getIndexedProperty(bean, property, index);
- *
- * } else if (resolver.isMapped(next)) {
- *
- * String key = resolver.getKey(next);
- * bean = getMappedProperty(bean, property, key);
- *
- * } else {
- *
- * bean = getSimpleProperty(bean, property);
- *
- * }
- *
- * // remove the processed property from the expression
- * name = resolver.remove(name);
- * }
- *
- *
- * In order to create an implementation, it is important to understand how
- * BeanUtils/PropertyUtils uses the {@code resolver}. The following are
- * the main methods that use it:
- *
- *
- * @see org.apache.commons.beanutils2.PropertyUtilsBean#setResolver(Resolver)
- * @since 1.8.0
- */
-public interface Resolver {
-
- /**
- * Extract the index value from the property expression or -1.
- *
- * @param expression The property expression
- * @return The index value or -1 if the property is not indexed
- * @throws IllegalArgumentException If the indexed property is illegally
- * formed or has an invalid (non-numeric) value
- */
- int getIndex(String expression);
-
- /**
- * Extract the map key from the property expression or {@code null}.
- *
- * @param expression The property expression
- * @return The index value
- * @throws IllegalArgumentException If the mapped property is illegally formed
- */
- String getKey(String expression);
-
- /**
- * Return the property name from the property expression.
- *
- * @param expression The property expression
- * @return The property name
- */
- String getProperty(String expression);
-
- /**
- * Indicates whether or not the expression
- * contains nested property expressions or not.
- *
- * @param expression The property expression
- * @return The next property expression
- */
- boolean hasNested(String expression);
-
- /**
- * Indicate whether the expression is for an indexed property or not.
- *
- * @param expression The property expression
- * @return {@code true} if the expression is indexed,
- * otherwise {@code false}
- */
- boolean isIndexed(String expression);
-
- /**
- * Indicate whether the expression is for a mapped property or not.
- *
- * @param expression The property expression
- * @return {@code true} if the expression is mapped,
- * otherwise {@code false}
- */
- boolean isMapped(String expression);
-
- /**
- * Extract the next property expression from the
- * current expression.
- *
- * @param expression The property expression
- * @return The next property expression
- */
- String next(String expression);
-
- /**
- * Remove the last property expression from the
- * current expression.
- *
- * @param expression The property expression
- * @return The new expression value, with first property
- * expression removed - null if there are no more expressions
- */
- String remove(String expression);
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/expression/package-info.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/expression/package-info.java
deleted file mode 100644
index 2f922a87d..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/expression/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Contains the {@link org.apache.commons.beanutils2.expression.Resolver}
- * interface and implementations.
- */
-package org.apache.commons.beanutils2.expression;
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/BaseLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/BaseLocaleConverter.java
deleted file mode 100644
index 3e4d7259a..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/BaseLocaleConverter.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale;
-
-import java.text.ParseException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-import org.apache.commons.beanutils2.ConvertUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
The base class for all standard type locale-sensitive converters.
- * It has {@link LocaleConverter} and {@link org.apache.commons.beanutils2.Converter} implementations,
- * that convert an incoming locale-sensitive Object into an object of correspond type,
- * optionally using a default value or throwing a {@link ConversionException}
- * if a conversion error occurs.
- *
- */
-
-public abstract class BaseLocaleConverter implements LocaleConverter {
-
-
-
- /** All logging goes through this logger */
- private final Log log = LogFactory.getLog(BaseLocaleConverter.class);
-
- /** The default value specified to our Constructor, if any. */
- private Object defaultValue = null;
-
- /** Should we return the default value on conversion errors? */
- protected boolean useDefault = false;
-
- /** The locale specified to our Constructor, by default - system locale. */
- protected Locale locale = Locale.getDefault();
-
- /** The default pattern specified to our Constructor, if any. */
- protected String pattern = null;
-
- /** The flag indicating whether the given pattern string is localized or not. */
- protected boolean locPattern = false;
-
-
-
- /**
- * Create a {@link LocaleConverter} that will throw a {@link ConversionException}
- * if a conversion error occurs.
- * An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- protected BaseLocaleConverter(final Locale locale, final String pattern) {
-
- this(null, locale, pattern, false, false);
- }
-
- /**
- * Create a {@link LocaleConverter} that will throw a {@link ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- protected BaseLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
-
- this(null, locale, pattern, false, locPattern);
- }
-
- /**
- * Create a {@link LocaleConverter} that will return the specified default value
- * if a conversion error occurs.
- * An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- protected BaseLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
-
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link LocaleConverter} that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- protected BaseLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
-
- this(defaultValue, locale, pattern, true, locPattern);
- }
-
- /**
- * Create a {@link LocaleConverter} that will return the specified default value
- * or throw a {@link ConversionException} if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param useDefault Indicate whether the default value is used or not
- * @param locPattern Indicate whether the pattern is localized or not
- */
- private BaseLocaleConverter(final Object defaultValue, final Locale locale,
- final String pattern, final boolean useDefault, final boolean locPattern) {
-
- if (useDefault) {
- this.defaultValue = defaultValue;
- this.useDefault = true;
- }
-
- if (locale != null) {
- this.locale = locale;
- }
-
- this.pattern = pattern;
- this.locPattern = locPattern;
- }
-
-
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws ParseException if conversion cannot be performed
- * successfully
- */
-
- abstract protected Object parse(Object value, String pattern) throws ParseException;
-
- /**
- * Convert the specified locale-sensitive input object into an output object.
- * The default pattern is used for the conversion.
- *
- * @param value The input object to be converted
- * @return The converted value
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- */
- public Object convert(final Object value) {
- return convert(value, null);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- */
- public Object convert(final Object value, final String pattern) {
- return convert(null, value, pattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type. The default pattern is used for the conversion.
- *
- * @param The desired target type of the conversion
- * @param type Data type to which this value should be converted
- * @param value The input object to be converted
- * @return The converted value
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- */
- @Override
- public T convert(final Class type, final Object value) {
- return convert(type, value, null);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type.
- *
- * @param The desired target type of the conversion
- * @param type Data is type to which this value should be converted
- * @param value is the input object to be converted
- * @param pattern is the pattern is used for the conversion; if null is
- * passed then the default pattern associated with the converter object
- * will be used.
- * @return The converted value
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- */
- @Override
- public T convert(final Class type, final Object value, final String pattern) {
- final Class targetType = ConvertUtils.primitiveToWrapper(type);
- if (value == null) {
- if (useDefault) {
- return getDefaultAs(targetType);
- }
- // symmetric beanutils function allows null
- // so do not: throw new ConversionException("No value specified");
- log.debug("Null value specified for conversion, returning null");
- return null;
- }
-
- try {
- if (pattern != null) {
- return checkConversionResult(targetType, parse(value, pattern));
- }
- return checkConversionResult(targetType, parse(value, this.pattern));
- } catch (final Exception e) {
- if (useDefault) {
- return getDefaultAs(targetType);
- }
- if (e instanceof ConversionException) {
- throw (ConversionException)e;
- }
- throw new ConversionException(e);
- }
- }
-
- /**
- * Returns the default object specified for this converter cast for the
- * given target type. If the default value is not conform to the given type,
- * an exception is thrown.
- *
- * @param the desired target type
- * @param type the target class of the conversion
- * @return the default value in the given target type
- * @throws ConversionException if the default object is not compatible with
- * the target type
- */
- private T getDefaultAs(final Class type) {
- return checkConversionResult(type, defaultValue);
- }
-
- /**
- * Checks whether the result of a conversion is conform to the specified
- * target type. If this is the case, the passed in result object is cast to
- * the correct target type. Otherwise, an exception is thrown.
- *
- * @param the desired result type
- * @param type the target class of the conversion
- * @param result the conversion result object
- * @return the result cast to the target class
- * @throws ConversionException if the result object is not compatible with
- * the target type
- */
- private static T checkConversionResult(final Class type, final Object result) {
- if (type == null) {
- // in this case we cannot do much; the result object is returned
- @SuppressWarnings("unchecked")
- final
- T temp = (T) result;
- return temp;
- }
-
- if (result == null) {
- return null;
- }
- if (type.isInstance(result)) {
- return type.cast(result);
- }
- throw new ConversionException("Unsupported target type: " + type);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleBeanUtils.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleBeanUtils.java
deleted file mode 100644
index 2a0a14e83..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleBeanUtils.java
+++ /dev/null
@@ -1,616 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.BeanUtils;
-
-/**
- *
Utility methods for populating JavaBeans properties
- * via reflection in a locale-dependent manner.
- *
- *
The implementations for these methods are provided by {@code LocaleBeanUtilsBean}.
- * For more details see {@link LocaleBeanUtilsBean}.
Return the value of the specified locale-sensitive indexed property
- * of the specified bean, as a String.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname[index]} of the property value
- * to be extracted
- * @param pattern The conversion pattern
- * @return The indexed property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getIndexedProperty(Object, String, String)
- */
- public static String getIndexedProperty(final Object bean, final String name, final String pattern)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getIndexedProperty(bean, name, pattern);
- }
-
- /**
- * Return the value of the specified locale-sensitive indexed property
- * of the specified bean, as a String using the default conversion pattern of
- * the corresponding {@link LocaleConverter}.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname[index]} of the property value
- * to be extracted
- * @return The indexed property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getIndexedProperty(Object, String)
- */
- public static String getIndexedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getIndexedProperty(bean, name);
- }
-
- /**
- *
Return the value of the specified locale-sensitive indexed property
- * of the specified bean, as a String using the specified conversion pattern.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param index Index of the property value to be extracted
- * @param pattern The conversion pattern
- * @return The indexed property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getIndexedProperty(Object, String, int, String)
- */
- public static String getIndexedProperty(final Object bean,
- final String name, final int index, final String pattern)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getIndexedProperty(bean, name, index, pattern);
- }
-
- /**
- *
Return the value of the specified locale-sensitive indexed property
- * of the specified bean, as a String using the default conversion pattern of
- * the corresponding {@link LocaleConverter}.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param index Index of the property value to be extracted
- * @return The indexed property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getIndexedProperty(Object, String, int)
- */
- public static String getIndexedProperty(final Object bean,
- final String name, final int index)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getIndexedProperty(bean, name, index);
- }
-
- /**
- *
Return the value of the specified simple locale-sensitive property
- * of the specified bean, converted to a String using the specified
- * conversion pattern.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Name of the property to be extracted
- * @param pattern The conversion pattern
- * @return The property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getSimpleProperty(Object, String, String)
- */
- public static String getSimpleProperty(final Object bean, final String name, final String pattern)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getSimpleProperty(bean, name, pattern);
- }
-
- /**
- *
Return the value of the specified simple locale-sensitive property
- * of the specified bean, converted to a String using the default
- * conversion pattern of the corresponding {@link LocaleConverter}.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Name of the property to be extracted
- * @return The property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getSimpleProperty(Object, String)
- */
- public static String getSimpleProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getSimpleProperty(bean, name);
- }
-
- /**
- *
Return the value of the specified mapped locale-sensitive property
- * of the specified bean, as a String using the specified conversion pattern.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param key Lookup key of the property value to be extracted
- * @param pattern The conversion pattern
- * @return The mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getMappedProperty(Object, String, String, String)
- */
- public static String getMappedProperty(final Object bean,
- final String name, final String key, final String pattern)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getMappedProperty(bean, name, key, pattern);
- }
-
- /**
- *
Return the value of the specified mapped locale-sensitive property
- * of the specified bean, as a String
- * The key is specified as a method parameter and must *not* be included
- * in the property name expression.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param key Lookup key of the property value to be extracted
- * @return The mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getMappedProperty(Object, String, String)
- */
- public static String getMappedProperty(final Object bean,
- final String name, final String key)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getMappedProperty(bean, name, key);
- }
-
- /**
- *
Return the value of the specified locale-sensitive mapped property
- * of the specified bean, as a String using the specified pattern.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname(index)} of the property value
- * to be extracted
- * @param pattern The conversion pattern
- * @return The mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getMappedPropertyLocale(Object, String, String)
- */
- public static String getMappedPropertyLocale(final Object bean, final String name, final String pattern)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getMappedPropertyLocale(bean, name, pattern);
- }
-
- /**
- *
Return the value of the specified locale-sensitive mapped property
- * of the specified bean, as a String using the default
- * conversion pattern of the corresponding {@link LocaleConverter}.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname(index)} of the property value
- * to be extracted
- * @return The mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getMappedProperty(Object, String)
- */
- public static String getMappedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getMappedProperty(bean, name);
- }
-
- /**
- *
Return the value of the (possibly nested) locale-sensitive property
- * of the specified name, for the specified bean,
- * as a String using the specified pattern.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly nested name of the property to be extracted
- * @param pattern The conversion pattern
- * @return The nested property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getNestedProperty(Object, String, String)
- */
- public static String getNestedProperty(final Object bean, final String name, final String pattern)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getNestedProperty(bean, name, pattern);
- }
-
- /**
- *
Return the value of the (possibly nested) locale-sensitive property
- * of the specified name.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly nested name of the property to be extracted
- * @return The nested property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getNestedProperty(Object, String)
- */
- public static String getNestedProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getNestedProperty(bean, name);
- }
-
- /**
- *
Return the value of the specified locale-sensitive property
- * of the specified bean.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly indexed and/or nested name of the property
- * to be extracted
- * @param pattern The conversion pattern
- * @return The nested property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getProperty(Object, String, String)
- */
- public static String getProperty(final Object bean, final String name, final String pattern)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getProperty(bean, name, pattern);
- }
-
- /**
- *
Return the value of the specified locale-sensitive property
- * of the specified bean.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly indexed and/or nested name of the property
- * to be extracted
- * @return The property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- *
- * @see LocaleBeanUtilsBean#getProperty(Object, String)
- */
- public static String getProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getProperty(bean, name);
- }
-
- /**
- *
Set the specified locale-sensitive property value, performing type
- * conversions as required to conform to the type of the destination property
- * using the default conversion pattern of the corresponding {@link LocaleConverter}.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean on which setting is to be performed
- * @param name Property name (can be nested/indexed/mapped/combo)
- * @param value Value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- *
- * @see LocaleBeanUtilsBean#setProperty(Object, String, Object)
- */
- public static void setProperty(final Object bean, final String name, final Object value)
- throws IllegalAccessException, InvocationTargetException {
-
- LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().setProperty(bean, name, value);
- }
-
- /**
- *
Set the specified locale-sensitive property value, performing type
- * conversions as required to conform to the type of the destination
- * property using the specified conversion pattern.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param bean Bean on which setting is to be performed
- * @param name Property name (can be nested/indexed/mapped/combo)
- * @param value Value to be set
- * @param pattern The conversion pattern
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- *
- * @see LocaleBeanUtilsBean#setProperty(Object, String, Object, String)
- */
- public static void setProperty(final Object bean, final String name, final Object value, final String pattern)
- throws IllegalAccessException, InvocationTargetException {
-
- LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().setProperty(bean, name, value, pattern);
- }
-
- /**
- *
Calculate the property type.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param target The bean
- * @param name The property name
- * @param propName The Simple name of target property
- * @return The property's type
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- *
- * @see LocaleBeanUtilsBean#definePropertyType(Object, String, String)
- */
- protected static Class> definePropertyType(final Object target, final String name, final String propName)
- throws IllegalAccessException, InvocationTargetException {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().definePropertyType(target, name, propName);
- }
-
- /**
- *
Convert the specified value to the required type using the
- * specified conversion pattern.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param type The Java type of target property
- * @param index The indexed subscript value (if any)
- * @param value The value to be converted
- * @param pattern The conversion pattern
- * @return The converted value
- * @see LocaleBeanUtilsBean#convert(Class, int, Object, String)
- */
- protected static Object convert(final Class> type, final int index, final Object value, final String pattern) {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().convert(type, index, value, pattern);
- }
-
- /**
- *
Convert the specified value to the required type.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param type The Java type of target property
- * @param index The indexed subscript value (if any)
- * @param value The value to be converted
- * @return The converted value
- * @see LocaleBeanUtilsBean#convert(Class, int, Object)
- */
- protected static Object convert(final Class> type, final int index, final Object value) {
-
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().convert(type, index, value);
- }
-
- /**
- *
Invoke the setter method.
- *
- *
For more details see {@code LocaleBeanUtilsBean}
- *
- * @param target The bean
- * @param propName The Simple name of target property
- * @param key The Mapped key value (if any)
- * @param index The indexed subscript value (if any)
- * @param newValue The value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- *
- * @see LocaleBeanUtilsBean#invokeSetter(Object, String, String, int, Object)
- */
- protected static void invokeSetter(final Object target, final String propName, final String key, final int index, final Object newValue)
- throws IllegalAccessException, InvocationTargetException {
-
- LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().invokeSetter(target, propName, key, index, newValue);
- }
-}
-
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleBeanUtilsBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleBeanUtilsBean.java
deleted file mode 100644
index 7987b6e36..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleBeanUtilsBean.java
+++ /dev/null
@@ -1,891 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale;
-
-import java.beans.IndexedPropertyDescriptor;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.BeanUtilsBean;
-import org.apache.commons.beanutils2.ContextClassLoaderLocal;
-import org.apache.commons.beanutils2.ConvertUtils;
-import org.apache.commons.beanutils2.ConvertUtilsBean;
-import org.apache.commons.beanutils2.DynaBean;
-import org.apache.commons.beanutils2.DynaClass;
-import org.apache.commons.beanutils2.DynaProperty;
-import org.apache.commons.beanutils2.MappedPropertyDescriptor;
-import org.apache.commons.beanutils2.PropertyUtilsBean;
-import org.apache.commons.beanutils2.expression.Resolver;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
Utility methods for populating JavaBeans properties
- * via reflection in a locale-dependent manner.
- *
- * @since 1.7
- */
-
-public class LocaleBeanUtilsBean extends BeanUtilsBean {
-
- /**
- * Contains {@code LocaleBeanUtilsBean} instances indexed by context classloader.
- */
- private static final ContextClassLoaderLocal
- LOCALE_BEANS_BY_CLASSLOADER = new ContextClassLoaderLocal() {
- // Creates the default instance used when the context classloader is unavailable
- @Override
- protected LocaleBeanUtilsBean initialValue() {
- return new LocaleBeanUtilsBean();
- }
- };
-
- /**
- * Gets singleton instance
- *
- * @return the singleton instance
- */
- public static LocaleBeanUtilsBean getLocaleBeanUtilsInstance() {
- return LOCALE_BEANS_BY_CLASSLOADER.get();
- }
-
- /**
- * Sets the instance which provides the functionality for {@link LocaleBeanUtils}.
- * This is a pseudo-singleton - an single instance is provided per (thread) context classloader.
- * This mechanism provides isolation for web apps deployed in the same container.
- *
- * @param newInstance a new singleton instance
- */
- public static void setInstance(final LocaleBeanUtilsBean newInstance) {
- LOCALE_BEANS_BY_CLASSLOADER.set(newInstance);
- }
-
- /** All logging goes through this logger */
- private final Log log = LogFactory.getLog(LocaleBeanUtilsBean.class);
-
-
-
- /** Convertor used by this class */
- private final LocaleConvertUtilsBean localeConvertUtils;
-
-
-
- /** Construct instance with standard conversion bean */
- public LocaleBeanUtilsBean() {
- this.localeConvertUtils = new LocaleConvertUtilsBean();
- }
-
- /**
- * Construct instance that uses given locale conversion
- *
- * @param localeConvertUtils use this {@code localeConvertUtils} to perform
- * conversions
- * @param convertUtilsBean use this for standard conversions
- * @param propertyUtilsBean use this for property conversions
- */
- public LocaleBeanUtilsBean(
- final LocaleConvertUtilsBean localeConvertUtils,
- final ConvertUtilsBean convertUtilsBean,
- final PropertyUtilsBean propertyUtilsBean) {
- super(convertUtilsBean, propertyUtilsBean);
- this.localeConvertUtils = localeConvertUtils;
- }
-
- /**
- * Construct instance that uses given locale conversion
- *
- * @param localeConvertUtils use this {@code localeConvertUtils} to perform
- * conversions
- */
- public LocaleBeanUtilsBean(final LocaleConvertUtilsBean localeConvertUtils) {
- this.localeConvertUtils = localeConvertUtils;
- }
-
-
-
- /**
- * Gets the bean instance used for conversions
- *
- * @return the locale converter bean instance
- */
- public LocaleConvertUtilsBean getLocaleConvertUtils() {
- return localeConvertUtils;
- }
-
- /**
- * Gets the default Locale
- * @return the default locale
- */
- public Locale getDefaultLocale() {
-
- return getLocaleConvertUtils().getDefaultLocale();
- }
-
- /**
- * Sets the default Locale.
- *
- * @param locale the default locale
- */
- public void setDefaultLocale(final Locale locale) {
-
- getLocaleConvertUtils().setDefaultLocale(locale);
- }
-
- /**
- * Is the pattern to be applied localized
- * (Indicate whether the pattern is localized or not)
- *
- * @return {@code true} if pattern is localized,
- * otherwise {@code false}
- */
- public boolean getApplyLocalized() {
-
- return getLocaleConvertUtils().getApplyLocalized();
- }
-
- /**
- * Sets whether the pattern is applied localized
- * (Indicate whether the pattern is localized or not)
- *
- * @param newApplyLocalized {@code true} if pattern is localized,
- * otherwise {@code false}
- */
- public void setApplyLocalized(final boolean newApplyLocalized) {
-
- getLocaleConvertUtils().setApplyLocalized(newApplyLocalized);
- }
-
-
-
- /**
- * Return the value of the specified locale-sensitive indexed property
- * of the specified bean, as a String. The zero-relative index of the
- * required value must be included (in square brackets) as a suffix to
- * the property name, or {@code IllegalArgumentException} will be
- * thrown.
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname[index]} of the property value
- * to be extracted
- * @param pattern The conversion pattern
- * @return The indexed property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public String getIndexedProperty(
- final Object bean,
- final String name,
- final String pattern)
- throws
- IllegalAccessException,
- InvocationTargetException,
- NoSuchMethodException {
-
- final Object value = getPropertyUtils().getIndexedProperty(bean, name);
- return getLocaleConvertUtils().convert(value, pattern);
- }
-
- /**
- * Return the value of the specified locale-sensitive indexed property
- * of the specified bean, as a String using the default conversion pattern of
- * the corresponding {@link LocaleConverter}. The zero-relative index
- * of the required value must be included (in square brackets) as a suffix
- * to the property name, or {@code IllegalArgumentException} will be thrown.
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname[index]} of the property value
- * to be extracted
- * @return The indexed property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- @Override
- public String getIndexedProperty(
- final Object bean,
- final String name)
- throws
- IllegalAccessException,
- InvocationTargetException,
- NoSuchMethodException {
-
- return getIndexedProperty(bean, name, null);
- }
-
- /**
- * Return the value of the specified locale-sensetive indexed property
- * of the specified bean, as a String using the specified conversion pattern.
- * The index is specified as a method parameter and
- * must *not* be included in the property name expression
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param index Index of the property value to be extracted
- * @param pattern The conversion pattern
- * @return The indexed property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public String getIndexedProperty(final Object bean,
- final String name, final int index, final String pattern)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- final Object value = getPropertyUtils().getIndexedProperty(bean, name, index);
- return getLocaleConvertUtils().convert(value, pattern);
- }
-
- /**
- * Return the value of the specified locale-sensetive indexed property
- * of the specified bean, as a String using the default conversion pattern of
- * the corresponding {@link LocaleConverter}.
- * The index is specified as a method parameter and
- * must *not* be included in the property name expression
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param index Index of the property value to be extracted
- * @return The indexed property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- @Override
- public String getIndexedProperty(final Object bean,
- final String name, final int index)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
- return getIndexedProperty(bean, name, index, null);
- }
-
- /**
- * Return the value of the specified simple locale-sensitive property
- * of the specified bean, converted to a String using the specified
- * conversion pattern.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Name of the property to be extracted
- * @param pattern The conversion pattern
- * @return The property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public String getSimpleProperty(final Object bean, final String name, final String pattern)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- final Object value = getPropertyUtils().getSimpleProperty(bean, name);
- return getLocaleConvertUtils().convert(value, pattern);
- }
-
- /**
- * Return the value of the specified simple locale-sensitive property
- * of the specified bean, converted to a String using the default
- * conversion pattern of the corresponding {@link LocaleConverter}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Name of the property to be extracted
- * @return The property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- @Override
- public String getSimpleProperty(final Object bean, final String name)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return getSimpleProperty(bean, name, null);
- }
-
- /**
- * Return the value of the specified mapped locale-sensitive property
- * of the specified bean, as a String using the specified conversion pattern.
- * The key is specified as a method parameter and must *not* be included in
- * the property name expression.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param key Lookup key of the property value to be extracted
- * @param pattern The conversion pattern
- * @return The mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public String getMappedProperty(
- final Object bean,
- final String name,
- final String key,
- final String pattern)
- throws
- IllegalAccessException,
- InvocationTargetException,
- NoSuchMethodException {
-
- final Object value = getPropertyUtils().getMappedProperty(bean, name, key);
- return getLocaleConvertUtils().convert(value, pattern);
- }
-
- /**
- * Return the value of the specified mapped locale-sensitive property
- * of the specified bean, as a String
- * The key is specified as a method parameter and must *not* be included
- * in the property name expression
- *
- * @param bean Bean whose property is to be extracted
- * @param name Simple property name of the property value to be extracted
- * @param key Lookup key of the property value to be extracted
- * @return The mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- @Override
- public String getMappedProperty(final Object bean,
- final String name, final String key)
- throws IllegalAccessException, InvocationTargetException,
- NoSuchMethodException {
-
- return getMappedProperty(bean, name, key, null);
- }
-
- /**
- * Return the value of the specified locale-sensitive mapped property
- * of the specified bean, as a String using the specified pattern.
- * The String-valued key of the required value
- * must be included (in parentheses) as a suffix to
- * the property name, or {@code IllegalArgumentException} will be
- * thrown.
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname(index)} of the property value
- * to be extracted
- * @param pattern The conversion pattern
- * @return The mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public String getMappedPropertyLocale(
- final Object bean,
- final String name,
- final String pattern)
- throws
- IllegalAccessException,
- InvocationTargetException,
- NoSuchMethodException {
-
- final Object value = getPropertyUtils().getMappedProperty(bean, name);
- return getLocaleConvertUtils().convert(value, pattern);
- }
-
- /**
- * Return the value of the specified locale-sensitive mapped property
- * of the specified bean, as a String using the default
- * conversion pattern of the corresponding {@link LocaleConverter}.
- * The String-valued key of the required value
- * must be included (in parentheses) as a suffix to
- * the property name, or {@code IllegalArgumentException} will be
- * thrown.
- *
- * @param bean Bean whose property is to be extracted
- * @param name {@code propertyname(index)} of the property value
- * to be extracted
- * @return The mapped property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- @Override
- public String getMappedProperty(final Object bean, final String name)
- throws
- IllegalAccessException,
- InvocationTargetException,
- NoSuchMethodException {
-
- return getMappedPropertyLocale(bean, name, null);
- }
-
- /**
- * Return the value of the (possibly nested) locale-sensitive property
- * of the specified name, for the specified bean,
- * as a String using the specified pattern.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly nested name of the property to be extracted
- * @param pattern The conversion pattern
- * @return The nested property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public String getNestedProperty(
- final Object bean,
- final String name,
- final String pattern)
- throws
- IllegalAccessException,
- InvocationTargetException,
- NoSuchMethodException {
-
- final Object value = getPropertyUtils().getNestedProperty(bean, name);
- return getLocaleConvertUtils().convert(value, pattern);
- }
-
- /**
- * Return the value of the (possibly nested) locale-sensitive property
- * of the specified name, for the specified bean, as a String using the default
- * conversion pattern of the corresponding {@link LocaleConverter}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly nested name of the property to be extracted
- * @return The nested property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws IllegalArgumentException if a nested reference to a
- * property returns null
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- @Override
- public String getNestedProperty(final Object bean, final String name)
- throws
- IllegalAccessException,
- InvocationTargetException,
- NoSuchMethodException {
-
- return getNestedProperty(bean, name, null);
- }
-
- /**
- * Return the value of the specified locale-sensitive property
- * of the specified bean, no matter which property reference
- * format is used, as a String using the specified conversion pattern.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly indexed and/or nested name of the property
- * to be extracted
- * @param pattern The conversion pattern
- * @return The nested property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- public String getProperty(final Object bean, final String name, final String pattern)
- throws
- IllegalAccessException,
- InvocationTargetException,
- NoSuchMethodException {
-
- return getNestedProperty(bean, name, pattern);
- }
-
- /**
- * Return the value of the specified locale-sensitive property
- * of the specified bean, no matter which property reference
- * format is used, as a String using the default
- * conversion pattern of the corresponding {@link LocaleConverter}.
- *
- * @param bean Bean whose property is to be extracted
- * @param name Possibly indexed and/or nested name of the property
- * to be extracted
- * @return The property's value, converted to a String
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- * @throws NoSuchMethodException if an accessor method for this
- * property cannot be found
- */
- @Override
- public String getProperty(final Object bean, final String name)
- throws
- IllegalAccessException,
- InvocationTargetException,
- NoSuchMethodException {
-
- return getNestedProperty(bean, name);
- }
-
- /**
- * Set the specified locale-sensitive property value, performing type
- * conversions as required to conform to the type of the destination property
- * using the default conversion pattern of the corresponding {@link LocaleConverter}.
- *
- * @param bean Bean on which setting is to be performed
- * @param name Property name (can be nested/indexed/mapped/combo)
- * @param value Value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- */
- @Override
- public void setProperty(final Object bean, final String name, final Object value)
- throws
- IllegalAccessException,
- InvocationTargetException {
-
- setProperty(bean, name, value, null);
- }
-
- /**
- * Set the specified locale-sensitive property value, performing type
- * conversions as required to conform to the type of the destination
- * property using the specified conversion pattern.
- *
- * @param bean Bean on which setting is to be performed
- * @param name Property name (can be nested/indexed/mapped/combo)
- * @param value Value to be set
- * @param pattern The conversion pattern
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- */
- public void setProperty(
- final Object bean,
- String name,
- final Object value,
- final String pattern)
- throws
- IllegalAccessException,
- InvocationTargetException {
-
- // Trace logging (if enabled)
- if (log.isTraceEnabled()) {
- final StringBuilder sb = new StringBuilder(" setProperty(");
- sb.append(bean);
- sb.append(", ");
- sb.append(name);
- sb.append(", ");
- if (value == null) {
- sb.append("");
- }
- else if (value instanceof String) {
- sb.append((String) value);
- }
- else if (value instanceof String[]) {
- final String[] values = (String[]) value;
- sb.append('[');
- for (int i = 0; i < values.length; i++) {
- if (i > 0) {
- sb.append(',');
- }
- sb.append(values[i]);
- }
- sb.append(']');
- }
- else {
- sb.append(value.toString());
- }
- sb.append(')');
- log.trace(sb.toString());
- }
-
- // Resolve any nested expression to get the actual target bean
- Object target = bean;
- final Resolver resolver = getPropertyUtils().getResolver();
- while (resolver.hasNested(name)) {
- try {
- target = getPropertyUtils().getProperty(target, resolver.next(name));
- name = resolver.remove(name);
- } catch (final NoSuchMethodException e) {
- return; // Skip this property setter
- }
- }
- if (log.isTraceEnabled()) {
- log.trace(" Target bean = " + target);
- log.trace(" Target name = " + name);
- }
-
- // Declare local variables we will require
- final String propName = resolver.getProperty(name); // Simple name of target property
- final int index = resolver.getIndex(name); // Indexed subscript value (if any)
- final String key = resolver.getKey(name); // Mapped key value (if any)
-
- final Class> type = definePropertyType(target, name, propName);
- if (type != null) {
- final Object newValue = convert(type, index, value, pattern);
- invokeSetter(target, propName, key, index, newValue);
- }
- }
-
- /**
- * Calculate the property type.
- *
- * @param target The bean
- * @param name The property name
- * @param propName The Simple name of target property
- * @return The property's type
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- */
- protected Class> definePropertyType(final Object target, final String name, final String propName)
- throws IllegalAccessException, InvocationTargetException {
-
- Class> type = null; // Java type of target property
-
- if (target instanceof DynaBean) {
- final DynaClass dynaClass = ((DynaBean) target).getDynaClass();
- final DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
- if (dynaProperty == null) {
- return null; // Skip this property setter
- }
- type = dynaProperty.getType();
- }
- else {
- PropertyDescriptor descriptor = null;
- try {
- descriptor =
- getPropertyUtils().getPropertyDescriptor(target, name);
- if (descriptor == null) {
- return null; // Skip this property setter
- }
- }
- catch (final NoSuchMethodException e) {
- return null; // Skip this property setter
- }
- if (descriptor instanceof MappedPropertyDescriptor) {
- type = ((MappedPropertyDescriptor) descriptor).
- getMappedPropertyType();
- }
- else if (descriptor instanceof IndexedPropertyDescriptor) {
- type = ((IndexedPropertyDescriptor) descriptor).
- getIndexedPropertyType();
- }
- else {
- type = descriptor.getPropertyType();
- }
- }
- return type;
- }
-
- /**
- * Convert the specified value to the required type using the
- * specified conversion pattern.
- *
- * @param type The Java type of target property
- * @param index The indexed subscript value (if any)
- * @param value The value to be converted
- * @param pattern The conversion pattern
- * @return The converted value
- */
- protected Object convert(final Class> type, final int index, final Object value, final String pattern) {
-
- if (log.isTraceEnabled()) {
- log.trace("Converting value '" + value + "' to type:" + type);
- }
-
- Object newValue = null;
-
- if (type.isArray() && index < 0) { // Scalar value into array
- if (value instanceof String) {
- final String[] values = new String[1];
- values[0] = (String) value;
- newValue = getLocaleConvertUtils().convert(values, type, pattern);
- }
- else if (value instanceof String[]) {
- newValue = getLocaleConvertUtils().convert((String[]) value, type, pattern);
- }
- else {
- newValue = value;
- }
- }
- else if (type.isArray()) { // Indexed value into array
- if (value instanceof String) {
- newValue = getLocaleConvertUtils().convert((String) value,
- type.getComponentType(), pattern);
- }
- else if (value instanceof String[]) {
- newValue = getLocaleConvertUtils().convert(((String[]) value)[0],
- type.getComponentType(), pattern);
- }
- else {
- newValue = value;
- }
- }
- else { // Value into scalar
- if (value instanceof String) {
- newValue = getLocaleConvertUtils().convert((String) value, type, pattern);
- }
- else if (value instanceof String[]) {
- newValue = getLocaleConvertUtils().convert(((String[]) value)[0],
- type, pattern);
- }
- else {
- newValue = value;
- }
- }
- return newValue;
- }
-
- /**
- * Convert the specified value to the required type.
- *
- * @param type The Java type of target property
- * @param index The indexed subscript value (if any)
- * @param value The value to be converted
- * @return The converted value
- */
- protected Object convert(final Class> type, final int index, final Object value) {
-
- Object newValue = null;
-
- if (type.isArray() && index < 0) { // Scalar value into array
- if (value instanceof String) {
- final String[] values = new String[1];
- values[0] = (String) value;
- newValue = ConvertUtils.convert(values, type);
- }
- else if (value instanceof String[]) {
- newValue = ConvertUtils.convert((String[]) value, type);
- }
- else {
- newValue = value;
- }
- }
- else if (type.isArray()) { // Indexed value into array
- if (value instanceof String) {
- newValue = ConvertUtils.convert((String) value,
- type.getComponentType());
- }
- else if (value instanceof String[]) {
- newValue = ConvertUtils.convert(((String[]) value)[0],
- type.getComponentType());
- }
- else {
- newValue = value;
- }
- }
- else { // Value into scalar
- if (value instanceof String) {
- newValue = ConvertUtils.convert((String) value, type);
- }
- else if (value instanceof String[]) {
- newValue = ConvertUtils.convert(((String[]) value)[0],
- type);
- }
- else {
- newValue = value;
- }
- }
- return newValue;
- }
-
- /**
- * Invoke the setter method.
- *
- * @param target The bean
- * @param propName The Simple name of target property
- * @param key The Mapped key value (if any)
- * @param index The indexed subscript value (if any)
- * @param newValue The value to be set
- *
- * @throws IllegalAccessException if the caller does not have
- * access to the property accessor method
- * @throws InvocationTargetException if the property accessor method
- * throws an exception
- */
- protected void invokeSetter(final Object target, final String propName, final String key, final int index, final Object newValue)
- throws IllegalAccessException, InvocationTargetException {
-
- try {
- if (index >= 0) {
- getPropertyUtils().setIndexedProperty(target, propName,
- index, newValue);
- }
- else if (key != null) {
- getPropertyUtils().setMappedProperty(target, propName,
- key, newValue);
- }
- else {
- getPropertyUtils().setProperty(target, propName, newValue);
- }
- }
- catch (final NoSuchMethodException e) {
- throw new InvocationTargetException
- (e, "Cannot set " + propName);
- }
- }
-}
-
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleConvertUtils.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleConvertUtils.java
deleted file mode 100644
index 10c2d0831..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleConvertUtils.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale;
-
-import java.util.Locale;
-
-/**
- *
Utility methods for converting locale-sensitive String scalar values to objects of the
- * specified Class, String arrays to arrays of the specified Class and
- * object to locale-sensitive String scalar value.
- *
- *
The implementations for these method are provided by {@link LocaleConvertUtilsBean}.
- * These static utility method use the default instance. More sophisticated can be provided
- * by using a {@code LocaleConvertUtilsBean} instance.
Convert the specified locale-sensitive value into a String.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param value The Value to be converted
- * @return the converted value
- * @see LocaleConvertUtilsBean#convert(Object)
- */
- public static String convert(final Object value) {
- return LocaleConvertUtilsBean.getInstance().convert(value);
- }
-
- /**
- *
Convert the specified locale-sensitive value into a String
- * using the conversion pattern.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param value The Value to be converted
- * @param pattern The conversion pattern
- * @return the converted value
- * @see LocaleConvertUtilsBean#convert(Object, String)
- */
- public static String convert(final Object value, final String pattern) {
- return LocaleConvertUtilsBean.getInstance().convert(value, pattern);
- }
-
- /**
- *
Convert the specified locale-sensitive value into a String
- * using the particular conversion pattern.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param value The Value to be converted
- * @param locale The locale
- * @param pattern The conversion pattern
- * @return the converted value
- * @see LocaleConvertUtilsBean#convert(Object, Locale, String)
- */
- public static String convert(final Object value, final Locale locale, final String pattern) {
-
- return LocaleConvertUtilsBean.getInstance().convert(value, locale, pattern);
- }
-
- /**
- *
Convert the specified value to an object of the specified class (if
- * possible). Otherwise, return a String representation of the value.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param value The String scalar value to be converted
- * @param clazz The Data type to which this value should be converted.
- * @return the converted value
- * @see LocaleConvertUtilsBean#convert(String, Class)
- */
- public static Object convert(final String value, final Class> clazz) {
-
- return LocaleConvertUtilsBean.getInstance().convert(value, clazz);
- }
-
- /**
- *
Convert the specified value to an object of the specified class (if
- * possible) using the conversion pattern. Otherwise, return a String
- * representation of the value.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param value The String scalar value to be converted
- * @param clazz The Data type to which this value should be converted.
- * @param pattern The conversion pattern
- * @return the converted value
- * @see LocaleConvertUtilsBean#convert(String, Class, String)
- */
- public static Object convert(final String value, final Class> clazz, final String pattern) {
-
- return LocaleConvertUtilsBean.getInstance().convert(value, clazz, pattern);
- }
-
- /**
- *
Convert the specified value to an object of the specified class (if
- * possible) using the conversion pattern. Otherwise, return a String
- * representation of the value.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param value The String scalar value to be converted
- * @param clazz The Data type to which this value should be converted.
- * @param locale The locale
- * @param pattern The conversion pattern
- * @return the converted value
- * @see LocaleConvertUtilsBean#convert(String, Class, Locale, String)
- */
- public static Object convert(final String value, final Class> clazz, final Locale locale, final String pattern) {
-
- return LocaleConvertUtilsBean.getInstance().convert(value, clazz, locale, pattern);
- }
-
- /**
- *
Convert an array of specified values to an array of objects of the
- * specified class (if possible) using the conversion pattern.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param values Value to be converted (may be null)
- * @param clazz Java array or element class to be converted to
- * @param pattern The conversion pattern
- * @return the converted value
- * @see LocaleConvertUtilsBean#convert(String[], Class, String)
- */
- public static Object convert(final String[] values, final Class> clazz, final String pattern) {
-
- return LocaleConvertUtilsBean.getInstance().convert(values, clazz, pattern);
- }
-
- /**
- *
Convert an array of specified values to an array of objects of the
- * specified class (if possible).
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param values Value to be converted (may be null)
- * @param clazz Java array or element class to be converted to
- * @return the converted value
- * @see LocaleConvertUtilsBean#convert(String[], Class)
- */
- public static Object convert(final String[] values, final Class> clazz) {
-
- return LocaleConvertUtilsBean.getInstance().convert(values, clazz);
- }
-
- /**
- *
Convert an array of specified values to an array of objects of the
- * specified class (if possible) using the conversion pattern.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param values Value to be converted (may be null)
- * @param clazz Java array or element class to be converted to
- * @param locale The locale
- * @param pattern The conversion pattern
- * @return the converted value
- * @see LocaleConvertUtilsBean#convert(String[], Class, Locale, String)
- */
- public static Object convert(final String[] values, final Class> clazz, final Locale locale, final String pattern) {
-
- return LocaleConvertUtilsBean.getInstance().convert(values, clazz, locale, pattern);
- }
-
- /**
- *
Register a custom {@link LocaleConverter} for the specified destination
- * {@code Class}, replacing any previously registered converter.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param converter The LocaleConverter to be registered
- * @param clazz The Destination class for conversions performed by this
- * Converter
- * @param locale The locale
- * @see LocaleConvertUtilsBean#register(LocaleConverter, Class, Locale)
- */
- public static void register(final LocaleConverter converter, final Class> clazz, final Locale locale) {
-
- LocaleConvertUtilsBean.getInstance().register(converter, clazz, locale);
- }
-
- /**
- *
Remove any registered {@link LocaleConverter}.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
Remove any registered {@link LocaleConverter} for the specified locale and Class.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param clazz Class for which to remove a registered Converter
- * @param locale The locale
- * @see LocaleConvertUtilsBean#deregister(Class, Locale)
- */
- public static void deregister(final Class> clazz, final Locale locale) {
-
- LocaleConvertUtilsBean.getInstance().deregister(clazz, locale);
- }
-
- /**
- *
Look up and return any registered {@link LocaleConverter} for the specified
- * destination class and locale; if there is no registered Converter, return
- * {@code null}.
- *
- *
For more details see {@code LocaleConvertUtilsBean}
- *
- * @param clazz Class for which to return a registered Converter
- * @param locale The Locale
- * @return The registered locale Converter, if any
- * @see LocaleConvertUtilsBean#lookup(Class, Locale)
- */
- public static LocaleConverter lookup(final Class> clazz, final Locale locale) {
-
- return LocaleConvertUtilsBean.getInstance().lookup(clazz, locale);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleConvertUtilsBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleConvertUtilsBean.java
deleted file mode 100644
index b59b31c2d..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleConvertUtilsBean.java
+++ /dev/null
@@ -1,569 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale;
-
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Collection;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.beanutils2.BeanUtils;
-import org.apache.commons.beanutils2.WeakFastHashMap;
-import org.apache.commons.beanutils2.locale.converters.BigDecimalLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.BigIntegerLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.ByteLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.DoubleLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.FloatLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.IntegerLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.LongLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.ShortLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.SqlDateLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.SqlTimeLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.SqlTimestampLocaleConverter;
-import org.apache.commons.beanutils2.locale.converters.StringLocaleConverter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
Utility methods for converting locale-sensitive String scalar values to objects of the
- * specified Class, String arrays to arrays of the specified Class and
- * object to locale-sensitive String scalar value.
- *
- *
This class provides the implementations used by the static utility methods in
- * {@link LocaleConvertUtils}.
- *
- *
The actual {@link LocaleConverter} instance to be used
- * can be registered for each possible destination Class. Unless you override them, standard
- * {@link LocaleConverter} instances are provided for all of the following
- * destination Classes:
- *
- *
java.lang.BigDecimal
- *
java.lang.BigInteger
- *
byte and java.lang.Byte
- *
double and java.lang.Double
- *
float and java.lang.Float
- *
int and java.lang.Integer
- *
long and java.lang.Long
- *
short and java.lang.Short
- *
java.lang.String
- *
java.sql.Date
- *
java.sql.Time
- *
java.sql.Timestamp
- *
- *
- *
For backwards compatibility, the standard locale converters
- * for primitive types (and the corresponding wrapper classes).
- *
- * If you prefer to have another {@link LocaleConverter}
- * thrown instead, replace the standard {@link LocaleConverter} instances
- * with ones created with the one of the appropriate constructors.
- *
- * It's important that {@link LocaleConverter} should be registered for
- * the specified locale and Class (or primitive type).
- *
- * @since 1.7
- */
-public class LocaleConvertUtilsBean {
-
- /**
- * Gets singleton instance.
- * This is the same as the instance used by the default {@link LocaleBeanUtilsBean} singleton.
- * @return the singleton instance
- */
- public static LocaleConvertUtilsBean getInstance() {
- return LocaleBeanUtilsBean.getLocaleBeanUtilsInstance().getLocaleConvertUtils();
- }
-
-
-
- /** The locale - default for conversion. */
- private Locale defaultLocale = Locale.getDefault();
-
- /** Indicate whether the pattern is localized or not */
- private boolean applyLocalized = false;
-
- /** The {@code Log} instance for this class. */
- private final Log log = LogFactory.getLog(LocaleConvertUtilsBean.class);
-
- /** Every entry of the mapConverters is:
- * key = locale
- * value = map of converters for the certain locale.
- */
- private final DelegateFastHashMap mapConverters = new DelegateFastHashMap(BeanUtils.createCache());
-
-
-
- /**
- * Makes the state by default (deregisters all converters for all locales)
- * and then registers default locale converters.
- */
- public LocaleConvertUtilsBean() {
- mapConverters.setFast(false);
- deregister();
- mapConverters.setFast(true);
- }
-
-
-
- /**
- * getter for defaultLocale.
- * @return the default locale
- */
- public Locale getDefaultLocale() {
-
- return defaultLocale;
- }
-
- /**
- * setter for defaultLocale.
- * @param locale the default locale
- */
- public void setDefaultLocale(final Locale locale) {
-
- if (locale == null) {
- defaultLocale = Locale.getDefault();
- }
- else {
- defaultLocale = locale;
- }
- }
-
- /**
- * getter for applyLocalized
- *
- * @return {@code true} if pattern is localized,
- * otherwise {@code false}
- */
- public boolean getApplyLocalized() {
- return applyLocalized;
- }
-
- /**
- * setter for applyLocalized
- *
- * @param newApplyLocalized {@code true} if pattern is localized,
- * otherwise {@code false}
- */
- public void setApplyLocalized(final boolean newApplyLocalized) {
- applyLocalized = newApplyLocalized;
- }
-
-
-
- /**
- * Convert the specified locale-sensitive value into a String.
- *
- * @param value The Value to be converted
- * @return the converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if thrown by an
- * underlying Converter
- */
- public String convert(final Object value) {
- return convert(value, defaultLocale, null);
- }
-
- /**
- * Convert the specified locale-sensitive value into a String
- * using the conversion pattern.
- *
- * @param value The Value to be converted
- * @param pattern The conversion pattern
- * @return the converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if thrown by an
- * underlying Converter
- */
- public String convert(final Object value, final String pattern) {
- return convert(value, defaultLocale, pattern);
- }
-
- /**
- * Convert the specified locale-sensitive value into a String
- * using the particular conversion pattern.
- *
- * @param value The Value to be converted
- * @param locale The locale
- * @param pattern The conversion pattern
- * @return the converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if thrown by an
- * underlying Converter
- */
- public String convert(final Object value, final Locale locale, final String pattern) {
-
- final LocaleConverter converter = lookup(String.class, locale);
-
- return converter.convert(String.class, value, pattern);
- }
-
- /**
- * Convert the specified value to an object of the specified class (if
- * possible). Otherwise, return a String representation of the value.
- *
- * @param value The String scalar value to be converted
- * @param clazz The Data type to which this value should be converted.
- * @return the converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if thrown by an
- * underlying Converter
- */
- public Object convert(final String value, final Class> clazz) {
-
- return convert(value, clazz, defaultLocale, null);
- }
-
- /**
- * Convert the specified value to an object of the specified class (if
- * possible) using the conversion pattern. Otherwise, return a String
- * representation of the value.
- *
- * @param value The String scalar value to be converted
- * @param clazz The Data type to which this value should be converted.
- * @param pattern The conversion pattern
- * @return the converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if thrown by an
- * underlying Converter
- */
- public Object convert(final String value, final Class> clazz, final String pattern) {
-
- return convert(value, clazz, defaultLocale, pattern);
- }
-
- /**
- * Convert the specified value to an object of the specified class (if
- * possible) using the conversion pattern. Otherwise, return a String
- * representation of the value.
- *
- * @param value The String scalar value to be converted
- * @param clazz The Data type to which this value should be converted.
- * @param locale The locale
- * @param pattern The conversion pattern
- * @return the converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if thrown by an
- * underlying Converter
- */
- public Object convert(final String value, final Class> clazz, final Locale locale, final String pattern) {
-
- if (log.isDebugEnabled()) {
- log.debug("Convert string " + value + " to class " +
- clazz.getName() + " using " + locale +
- " locale and " + pattern + " pattern");
- }
-
- Class> targetClass = clazz;
- LocaleConverter converter = lookup(clazz, locale);
-
- if (converter == null) {
- converter = lookup(String.class, locale);
- targetClass = String.class;
- }
- if (log.isTraceEnabled()) {
- log.trace(" Using converter " + converter);
- }
-
- return converter.convert(targetClass, value, pattern);
- }
-
- /**
- * Convert an array of specified values to an array of objects of the
- * specified class (if possible) using the conversion pattern.
- *
- * @param values Value to be converted (may be null)
- * @param clazz Java array or element class to be converted to
- * @param pattern The conversion pattern
- * @return the converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if thrown by an
- * underlying Converter
- */
- public Object convert(final String[] values, final Class> clazz, final String pattern) {
-
- return convert(values, clazz, getDefaultLocale(), pattern);
- }
-
- /**
- * Convert an array of specified values to an array of objects of the
- * specified class (if possible) .
- *
- * @param values Value to be converted (may be null)
- * @param clazz Java array or element class to be converted to
- * @return the converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if thrown by an
- * underlying Converter
- */
- public Object convert(final String[] values, final Class> clazz) {
-
- return convert(values, clazz, getDefaultLocale(), null);
- }
-
- /**
- * Convert an array of specified values to an array of objects of the
- * specified class (if possible) using the conversion pattern.
- *
- * @param values Value to be converted (may be null)
- * @param clazz Java array or element class to be converted to
- * @param locale The locale
- * @param pattern The conversion pattern
- * @return the converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if thrown by an
- * underlying Converter
- */
- public Object convert(final String[] values, final Class> clazz, final Locale locale, final String pattern) {
-
- Class> type = clazz;
- if (clazz.isArray()) {
- type = clazz.getComponentType();
- }
- if (log.isDebugEnabled()) {
- log.debug("Convert String[" + values.length + "] to class " +
- type.getName() + "[] using " + locale +
- " locale and " + pattern + " pattern");
- }
-
- final Object array = Array.newInstance(type, values.length);
- for (int i = 0; i < values.length; i++) {
- Array.set(array, i, convert(values[i], type, locale, pattern));
- }
-
- return array;
- }
-
- /**
- * Register a custom {@link LocaleConverter} for the specified destination
- * {@code Class}, replacing any previously registered converter.
- *
- * @param converter The LocaleConverter to be registered
- * @param clazz The Destination class for conversions performed by this
- * Converter
- * @param locale The locale
- */
- public void register(final LocaleConverter converter, final Class> clazz, final Locale locale) {
-
- lookup(locale).put(clazz, converter);
- }
-
- /**
- * Remove any registered {@link LocaleConverter}.
- */
- public void deregister() {
-
- final Map, LocaleConverter> defaultConverter = lookup(defaultLocale);
-
- mapConverters.setFast(false);
-
- mapConverters.clear();
- mapConverters.put(defaultLocale, defaultConverter);
-
- mapConverters.setFast(true);
- }
-
- /**
- * Remove any registered {@link LocaleConverter} for the specified locale
- *
- * @param locale The locale
- */
- public void deregister(final Locale locale) {
-
- mapConverters.remove(locale);
- }
-
- /**
- * Remove any registered {@link LocaleConverter} for the specified locale and Class.
- *
- * @param clazz Class for which to remove a registered Converter
- * @param locale The locale
- */
- public void deregister(final Class> clazz, final Locale locale) {
-
- lookup(locale).remove(clazz);
- }
-
- /**
- * Look up and return any registered {@link LocaleConverter} for the specified
- * destination class and locale; if there is no registered Converter, return
- * {@code null}.
- *
- * @param clazz Class for which to return a registered Converter
- * @param locale The Locale
- * @return The registered locale Converter, if any
- */
- public LocaleConverter lookup(final Class> clazz, final Locale locale) {
-
- final LocaleConverter converter = lookup(locale).get(clazz);
-
- if (log.isTraceEnabled()) {
- log.trace("LocaleConverter:" + converter);
- }
-
- return converter;
- }
-
- /**
- * Look up and return any registered map instance for the specified locale;
- * if there is no registered one, return {@code null}.
- *
- * @param locale The Locale
- * @return The map instance contains the all {@link LocaleConverter} types for
- * the specified locale.
- */
- protected Map, LocaleConverter> lookup(final Locale locale) {
- Map, LocaleConverter> localeConverters;
-
- if (locale == null) {
- localeConverters = (Map, LocaleConverter>) mapConverters.get(defaultLocale);
- }
- else {
- localeConverters = (Map, LocaleConverter>) mapConverters.get(locale);
-
- if (localeConverters == null) {
- localeConverters = create(locale);
- mapConverters.put(locale, localeConverters);
- }
- }
-
- return localeConverters;
- }
-
- /**
- * Create all {@link LocaleConverter} types for specified locale.
- *
- * @param locale The Locale
- * @return The map instance contains the all {@link LocaleConverter} types
- * for the specified locale.
- */
- protected Map, LocaleConverter> create(final Locale locale) {
-
- final DelegateFastHashMap converter = new DelegateFastHashMap(BeanUtils.createCache());
- converter.setFast(false);
-
- converter.put(BigDecimal.class, new BigDecimalLocaleConverter(locale, applyLocalized));
- converter.put(BigInteger.class, new BigIntegerLocaleConverter(locale, applyLocalized));
-
- converter.put(Byte.class, new ByteLocaleConverter(locale, applyLocalized));
- converter.put(Byte.TYPE, new ByteLocaleConverter(locale, applyLocalized));
-
- converter.put(Double.class, new DoubleLocaleConverter(locale, applyLocalized));
- converter.put(Double.TYPE, new DoubleLocaleConverter(locale, applyLocalized));
-
- converter.put(Float.class, new FloatLocaleConverter(locale, applyLocalized));
- converter.put(Float.TYPE, new FloatLocaleConverter(locale, applyLocalized));
-
- converter.put(Integer.class, new IntegerLocaleConverter(locale, applyLocalized));
- converter.put(Integer.TYPE, new IntegerLocaleConverter(locale, applyLocalized));
-
- converter.put(Long.class, new LongLocaleConverter(locale, applyLocalized));
- converter.put(Long.TYPE, new LongLocaleConverter(locale, applyLocalized));
-
- converter.put(Short.class, new ShortLocaleConverter(locale, applyLocalized));
- converter.put(Short.TYPE, new ShortLocaleConverter(locale, applyLocalized));
-
- converter.put(String.class, new StringLocaleConverter(locale, applyLocalized));
-
- // conversion format patterns of java.sql.* types should correspond to default
- // behavior 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.setFast(true);
-
- return converter;
- }
-
- private static class DelegateFastHashMap implements Map {
-
- private final Map map;
-
- private DelegateFastHashMap(final Map map) {
- this.map = map;
- }
- @Override
- public void clear() {
- map.clear();
- }
- @Override
- public boolean containsKey(final Object key) {
- return map.containsKey(key);
- }
- @Override
- public boolean containsValue(final Object value) {
- return map.containsValue(value);
- }
- @Override
- public Set> entrySet() {
- return map.entrySet();
- }
- @Override
- public boolean equals(final Object o) {
- return map.equals(o);
- }
- @Override
- public Object get(final Object key) {
- return map.get(key);
- }
- @Override
- public int hashCode() {
- return map.hashCode();
- }
- @Override
- public boolean isEmpty() {
- return map.isEmpty();
- }
- @Override
- public Set keySet() {
- return map.keySet();
- }
- @Override
- public Object put(final Object key, final Object value) {
- return map.put(key, value);
- }
- // we operate on very generic types (), so there is
- // no need for doing type checks
- @Override
- public void putAll(final Map m) {
- map.putAll(m);
- }
- @Override
- public Object remove(final Object key) {
- return map.remove(key);
- }
- @Override
- public int size() {
- return map.size();
- }
- @Override
- public Collection values() {
- return map.values();
- }
- public void setFast(final boolean fast) {
- if (map instanceof WeakFastHashMap) {
- ((WeakFastHashMap, ?>)map).setFast(fast);
- }
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleConverter.java
deleted file mode 100644
index e35eb119b..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/LocaleConverter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale;
-
-import org.apache.commons.beanutils2.Converter;
-
-/**
- *
General purpose locale-sensitive data type converter that can be registered and used
- * within the BeanUtils package to manage the conversion of objects from
- * one type to another.
- *
- */
-
-public interface LocaleConverter extends Converter {
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type.
- *
- * @param The desired target type of the conversion
- * @param type Data type to which this value should be converted
- * @param value The input value to be converted
- * @param pattern The user-defined pattern is used for the input object formatting.
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion
- * cannot be performed successfully or if the target type is not supported
- */
- T convert(Class type, Object value, String pattern);
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/BigDecimalLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/BigDecimalLocaleConverter.java
deleted file mode 100644
index 4bc99fa83..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/BigDecimalLocaleConverter.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.math.BigDecimal;
-import java.text.ParseException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.math.BigDecimal} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class BigDecimalLocaleConverter extends DecimalLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- */
- public BigDecimalLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigDecimalLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public BigDecimalLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigDecimalLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public BigDecimalLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigDecimalLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public BigDecimalLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigDecimalLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public BigDecimalLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigDecimalLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public BigDecimalLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigDecimalLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of
- * BigDecimal type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- * @since 1.8.0
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
-
- final Object result = super.parse(value, pattern);
-
- if (result == null || result instanceof BigDecimal) {
- return result;
- }
-
- try {
- return new BigDecimal(result.toString());
- }
- catch (final NumberFormatException ex) {
- throw new ConversionException("Supplied number is not of type BigDecimal: " + result);
- }
-
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/BigIntegerLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/BigIntegerLocaleConverter.java
deleted file mode 100644
index 89fbf1aae..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/BigIntegerLocaleConverter.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.math.BigInteger;
-import java.text.ParseException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.math.BigInteger} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class BigIntegerLocaleConverter extends DecimalLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- */
- public BigIntegerLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigIntegerLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public BigIntegerLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigIntegerLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public BigIntegerLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigIntegerLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public BigIntegerLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigIntegerLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public BigIntegerLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigIntegerLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public BigIntegerLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public BigIntegerLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of
- * BigInteger type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- * @since 1.8.0
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
-
- final Object result = super.parse(value, pattern);
-
- if (result == null || result instanceof BigInteger) {
- return result;
- }
-
- if (result instanceof Number) {
- return BigInteger.valueOf(((Number)result).longValue());
- }
-
- try {
- return new BigInteger(result.toString());
- }
- catch (final NumberFormatException ex) {
- throw new ConversionException("Supplied number is not of type BigInteger: " + result);
- }
-
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/ByteLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/ByteLocaleConverter.java
deleted file mode 100644
index 3a6fcd202..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/ByteLocaleConverter.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.text.ParseException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.lang.Byte} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class ByteLocaleConverter extends DecimalLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- */
- public ByteLocaleConverter() {
-
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ByteLocaleConverter(final boolean locPattern) {
-
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public ByteLocaleConverter(final Locale locale) {
-
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ByteLocaleConverter(final Locale locale, final boolean locPattern) {
-
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public ByteLocaleConverter(final Locale locale, final String pattern) {
-
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ByteLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
-
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public ByteLocaleConverter(final Object defaultValue) {
-
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ByteLocaleConverter(final Object defaultValue, final boolean locPattern) {
-
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public ByteLocaleConverter(final Object defaultValue, final Locale locale) {
-
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ByteLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
-
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public ByteLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
-
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ByteLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
-
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type. This method will return values of type Byte.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion cannot be performed
- * successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
- final Number parsed = (Number) super.parse(value, pattern);
- if (parsed.longValue() != parsed.byteValue()) {
- throw new ConversionException("Supplied number is not of type Byte: " + parsed.longValue());
- }
- // now returns property Byte
- return Byte.valueOf(parsed.byteValue());
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/DateLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/DateLocaleConverter.java
deleted file mode 100644
index dc80004e3..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/DateLocaleConverter.java
+++ /dev/null
@@ -1,358 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.text.DateFormat;
-import java.text.DateFormatSymbols;
-import java.text.ParseException;
-import java.text.ParsePosition;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-import org.apache.commons.beanutils2.locale.BaseLocaleConverter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.util.Date} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class DateLocaleConverter extends BaseLocaleConverter {
-
- /** All logging goes through this logger */
- private final Log log = LogFactory.getLog(DateLocaleConverter.class);
-
- /** Should the date conversion be lenient? */
- boolean isLenient = false;
-
- /**
- * Default Pattern Characters
- */
- private static final String DEFAULT_PATTERN_CHARS = DateLocaleConverter.initDefaultChars();
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- */
- public DateLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DateLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public DateLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DateLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public DateLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DateLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public DateLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DateLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public DateLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DateLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public DateLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DateLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
-
-
- /**
- * Returns whether date formatting is lenient.
- *
- * @return true if the {@code DateFormat} used for formatting is lenient
- * @see java.text.DateFormat#isLenient
- */
- public boolean isLenient() {
- return isLenient;
- }
-
- /**
- * Specify whether or not date-time parsing should be lenient.
- *
- * @param lenient true if the {@code DateFormat} used for formatting should be lenient
- * @see java.text.DateFormat#setLenient
- */
- public void setLenient(final boolean lenient) {
- isLenient = lenient;
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return the converted Date value
- *
- * @throws org.apache.commons.beanutils2.ConversionException
- * if conversion cannot be performed successfully
- * @throws ParseException if an error occurs parsing
- */
- @Override
- protected Object parse(final Object value, String pattern) throws ParseException {
-
- // Handle Date
- if (value instanceof java.util.Date) {
- return value;
- }
-
- // Handle Calendar
- if (value instanceof java.util.Calendar) {
- return ((java.util.Calendar)value).getTime();
- }
-
- if (locPattern) {
- pattern = convertLocalizedPattern(pattern, locale);
- }
-
- // Create Formatter - use default if pattern is null
- final DateFormat formatter = pattern == null ? DateFormat.getDateInstance(DateFormat.SHORT, locale)
- : new SimpleDateFormat(pattern, locale);
- formatter.setLenient(isLenient);
-
- // Parse the Date
- final ParsePosition pos = new ParsePosition(0);
- final String strValue = value.toString();
- final Object parsedValue = formatter.parseObject(strValue, pos);
- if (pos.getErrorIndex() > -1) {
- throw new ConversionException("Error parsing date '" + value +
- "' at position="+ pos.getErrorIndex());
- }
- if (pos.getIndex() < strValue.length()) {
- throw new ConversionException("Date '" + value +
- "' contains unparsed characters from position=" + pos.getIndex());
- }
-
- return parsedValue;
- }
-
- /**
- * Convert a pattern from a localized format to the default format.
- *
- * @param locale The locale
- * @param localizedPattern The pattern in 'local' symbol format
- * @return pattern in 'default' symbol format
- */
- private String convertLocalizedPattern(final String localizedPattern, final Locale locale) {
-
- if (localizedPattern == null) {
- return null;
- }
-
- // Note that this is a little obtuse.
- // However, it is the best way that anyone can come up with
- // that works with some 1.4 series JVM.
-
- // Get the symbols for the localized pattern
- final DateFormatSymbols localizedSymbols = new DateFormatSymbols(locale);
- final String localChars = localizedSymbols.getLocalPatternChars();
-
- if (DEFAULT_PATTERN_CHARS.equals(localChars)) {
- return localizedPattern;
- }
-
- // Convert the localized pattern to default
- String convertedPattern = null;
- try {
- convertedPattern = convertPattern(localizedPattern,
- localChars,
- DEFAULT_PATTERN_CHARS);
- } catch (final Exception ex) {
- log.debug("Converting pattern '" + localizedPattern + "' for " + locale, ex);
- }
- return convertedPattern;
- }
-
- /**
- *
Converts a Pattern from one character set to another.
- */
- private String convertPattern(final String pattern, final String fromChars, final String toChars) {
-
- final StringBuilder converted = new StringBuilder();
- boolean quoted = false;
-
- for (int i = 0; i < pattern.length(); ++i) {
- char thisChar = pattern.charAt(i);
- if (quoted) {
- if (thisChar == '\'') {
- quoted = false;
- }
- } else {
- if (thisChar == '\'') {
- quoted = true;
- } else if ((thisChar >= 'a' && thisChar <= 'z') ||
- (thisChar >= 'A' && thisChar <= 'Z')) {
- final int index = fromChars.indexOf(thisChar );
- if (index == -1) {
- throw new IllegalArgumentException(
- "Illegal pattern character '" + thisChar + "'");
- }
- thisChar = toChars.charAt(index);
- }
- }
- converted.append(thisChar);
- }
-
- if (quoted) {
- throw new IllegalArgumentException("Unfinished quote in pattern");
- }
-
- return converted.toString();
- }
-
- /**
- * This method is called at class initialization time to define the
- * value for constant member DEFAULT_PATTERN_CHARS. All other methods needing
- * this data should just read that constant.
- */
- private static String initDefaultChars() {
- final DateFormatSymbols defaultSymbols = new DateFormatSymbols(Locale.US);
- return defaultSymbols.getLocalPatternChars();
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/DecimalLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/DecimalLocaleConverter.java
deleted file mode 100644
index c8ee6da3d..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/DecimalLocaleConverter.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.locale.BaseLocaleConverter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.lang.Number} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @since 1.7
- */
-public class DecimalLocaleConverter extends BaseLocaleConverter {
-
- /** All logging goes through this logger */
- private final Log log = LogFactory.getLog(DecimalLocaleConverter.class);
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- */
- public DecimalLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DecimalLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public DecimalLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DecimalLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public DecimalLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DecimalLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public DecimalLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DecimalLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public DecimalLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DecimalLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public DecimalLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DecimalLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
-
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output
- * object of the specified type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion
- * cannot be performed successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
-
- if (value instanceof Number) {
- return value;
- }
-
- // Note that despite the ambiguous "getInstance" name, and despite the
- // fact that objects returned from this method have the same toString
- // representation, each call to getInstance actually returns a new
- // object.
- final DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(locale);
-
- // if some constructors default pattern to null, it makes only sense
- // to handle null pattern gracefully
- if (pattern != null) {
- if (locPattern) {
- formatter.applyLocalizedPattern(pattern);
- } else {
- formatter.applyPattern(pattern);
- }
- } else {
- log.debug("No pattern provided, using default.");
- }
-
- return formatter.parse((String) value);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/DoubleLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/DoubleLocaleConverter.java
deleted file mode 100644
index 0b2420873..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/DoubleLocaleConverter.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.text.ParseException;
-import java.util.Locale;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.lang.Double} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class DoubleLocaleConverter extends DecimalLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- */
- public DoubleLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DoubleLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public DoubleLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DoubleLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public DoubleLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DoubleLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public DoubleLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DoubleLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public DoubleLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DoubleLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public DoubleLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public DoubleLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type. This method will return Double type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion cannot be performed
- * successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
- final Number result = (Number) super.parse(value, pattern);
- if (result instanceof Long) {
- return Double.valueOf(result.doubleValue());
- }
- return result;
- }
-}
-
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/FloatLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/FloatLocaleConverter.java
deleted file mode 100644
index cc026914d..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/FloatLocaleConverter.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.text.ParseException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.math.BigDecimal} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class FloatLocaleConverter extends DecimalLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- */
- public FloatLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public FloatLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public FloatLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public FloatLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public FloatLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public FloatLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public FloatLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public FloatLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public FloatLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public FloatLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public FloatLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public FloatLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type. This method will return Float value or throw exception if value
- * can not be stored in the Float.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
- final Number parsed = (Number) super.parse(value, pattern);
- final double doubleValue = parsed.doubleValue();
- final double posDouble = doubleValue >= 0 ? doubleValue : doubleValue * -1;
- if (posDouble != 0 && (posDouble < Float.MIN_VALUE || posDouble > Float.MAX_VALUE)) {
- throw new ConversionException("Supplied number is not of type Float: "+parsed);
- }
- return Float.valueOf(parsed.floatValue()); // unlike superclass it returns Float type
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/IntegerLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/IntegerLocaleConverter.java
deleted file mode 100644
index 41cd8d508..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/IntegerLocaleConverter.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.text.ParseException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.lang.Integer} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class IntegerLocaleConverter extends DecimalLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- */
- public IntegerLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public IntegerLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public IntegerLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public IntegerLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public IntegerLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public IntegerLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public IntegerLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public IntegerLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public IntegerLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public IntegerLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public IntegerLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public IntegerLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type. This method will return Integer type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
- final Number parsed = (Number) super.parse(value, pattern);
- if (parsed.longValue() != parsed.intValue()) {
- throw new ConversionException("Supplied number is not of type Integer: " + parsed.longValue());
- }
- return Integer.valueOf(parsed.intValue()); // unlike superclass it will return proper Integer
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/LongLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/LongLocaleConverter.java
deleted file mode 100644
index 04282a31c..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/LongLocaleConverter.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.text.ParseException;
-import java.util.Locale;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.lang.Long} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class LongLocaleConverter extends DecimalLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- */
- public LongLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public LongLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public LongLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public LongLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public LongLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public LongLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public LongLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public LongLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public LongLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public LongLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public LongLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public LongLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type. This method will return a Long type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion
- * cannot be performed successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- * @since 1.8.0
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
-
- final Object result = super.parse(value, pattern);
-
- if (result == null || result instanceof Long) {
- return result;
- }
-
- return Long.valueOf(((Number)result).longValue());
-
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/ShortLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/ShortLocaleConverter.java
deleted file mode 100644
index b19c8fce0..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/ShortLocaleConverter.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.text.ParseException;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.lang.Short} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class ShortLocaleConverter extends DecimalLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- */
- public ShortLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ShortLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public ShortLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ShortLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public ShortLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ShortLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public ShortLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ShortLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public ShortLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ShortLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public ShortLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public ShortLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type. This method will return values of type Short.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion cannot be performed
- * successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- * @since 1.8.0
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
-
- final Object result = super.parse(value, pattern);
-
- if (result == null || result instanceof Short) {
- return result;
- }
-
- final Number parsed = (Number)result;
- if (parsed.longValue() != parsed.shortValue()) {
- throw new ConversionException("Supplied number is not of type Short: " + parsed.longValue());
- }
-
- // now returns property Short
- return Short.valueOf(parsed.shortValue());
- }
-
-}
-
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/SqlDateLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/SqlDateLocaleConverter.java
deleted file mode 100644
index e7fd6a427..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/SqlDateLocaleConverter.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.sql.Date;
-import java.text.ParseException;
-import java.util.Locale;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.sql.Date} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class SqlDateLocaleConverter extends DateLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- */
- public SqlDateLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlDateLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public SqlDateLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlDateLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public SqlDateLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlDateLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public SqlDateLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlDateLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public SqlDateLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlDateLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public SqlDateLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlDateLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion
- * cannot be performed successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
- return new Date(((java.util.Date) super.parse(value, pattern)).getTime());
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/SqlTimeLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/SqlTimeLocaleConverter.java
deleted file mode 100644
index e3f8acb98..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/SqlTimeLocaleConverter.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.sql.Time;
-import java.text.ParseException;
-import java.util.Locale;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.sql.Time} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- */
-public class SqlTimeLocaleConverter extends DateLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- */
- public SqlTimeLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimeLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public SqlTimeLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimeLocaleConverter(final Locale locale, final boolean locPattern) {
-
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public SqlTimeLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimeLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public SqlTimeLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimeLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public SqlTimeLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimeLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public SqlTimeLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimeLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion
- * cannot be performed successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
- return new Time(((java.util.Date) super.parse(value, pattern)).getTime());
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/SqlTimestampLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/SqlTimestampLocaleConverter.java
deleted file mode 100644
index ff0991a81..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/SqlTimestampLocaleConverter.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.sql.Timestamp;
-import java.text.ParseException;
-import java.util.Locale;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive String into a {@code java.sql.Timestamp} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class SqlTimestampLocaleConverter extends DateLocaleConverter {
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- */
- public SqlTimestampLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimestampLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public SqlTimestampLocaleConverter(final Locale locale) {
- this(locale, (String) null);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimestampLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public SqlTimestampLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimestampLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public SqlTimestampLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimestampLocaleConverter(final Object defaultValue, final boolean locPattern) {
-
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public SqlTimestampLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimestampLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public SqlTimestampLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public SqlTimestampLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion
- * cannot be performed successfully
- * @throws ParseException if an error occurs parsing a String to a Number
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
- return new Timestamp(((java.util.Date) super.parse(value, pattern)).getTime());
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/StringLocaleConverter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/StringLocaleConverter.java
deleted file mode 100644
index 5aa416a2e..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/StringLocaleConverter.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2.locale.converters;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.ConversionException;
-import org.apache.commons.beanutils2.locale.BaseLocaleConverter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
Standard {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * implementation that converts an incoming
- * locale-sensitive object into a {@code java.lang.String} object,
- * optionally using a default value or throwing a
- * {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- */
-public class StringLocaleConverter extends BaseLocaleConverter {
-
- /** All logging goes through this logger */
- private final Log log = LogFactory.getLog(StringLocaleConverter.class); //msz fix
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- */
- public StringLocaleConverter() {
- this(false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public StringLocaleConverter(final boolean locPattern) {
- this(Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- */
- public StringLocaleConverter(final Locale locale) {
- this(locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public StringLocaleConverter(final Locale locale, final boolean locPattern) {
- this(locale, (String) null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public StringLocaleConverter(final Locale locale, final String pattern) {
- this(locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will throw a {@link org.apache.commons.beanutils2.ConversionException}
- * if a conversion error occurs.
- *
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public StringLocaleConverter(final Locale locale, final String pattern, final boolean locPattern) {
- super(locale, pattern, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine and an unlocalized pattern is used
- * for the conversion.
- *
- * @param defaultValue The default value to be returned
- */
- public StringLocaleConverter(final Object defaultValue) {
- this(defaultValue, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. The locale is the default locale for
- * this instance of the Java Virtual Machine.
- *
- * @param defaultValue The default value to be returned
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public StringLocaleConverter(final Object defaultValue, final boolean locPattern) {
- this(defaultValue, Locale.getDefault(), locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- */
- public StringLocaleConverter(final Object defaultValue, final Locale locale) {
- this(defaultValue, locale, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public StringLocaleConverter(final Object defaultValue, final Locale locale, final boolean locPattern) {
- this(defaultValue, locale, null, locPattern);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs. An unlocalized pattern is used for the conversion.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- */
- public StringLocaleConverter(final Object defaultValue, final Locale locale, final String pattern) {
- this(defaultValue, locale, pattern, false);
- }
-
- /**
- * Create a {@link org.apache.commons.beanutils2.locale.LocaleConverter}
- * that will return the specified default value
- * if a conversion error occurs.
- *
- * @param defaultValue The default value to be returned
- * @param locale The locale
- * @param pattern The conversion pattern
- * @param locPattern Indicate whether the pattern is localized or not
- */
- public StringLocaleConverter(final Object defaultValue, final Locale locale, final String pattern, final boolean locPattern) {
- super(defaultValue, locale, pattern, locPattern);
- }
-
- /**
- * Convert the specified locale-sensitive input object into an output object of the
- * specified type.
- *
- * @param value The input object to be converted
- * @param pattern The pattern is used for the conversion
- * @return The converted value
- *
- * @throws org.apache.commons.beanutils2.ConversionException if conversion
- * cannot be performed successfully
- * @throws ParseException if an error occurs
- */
- @Override
- protected Object parse(final Object value, final String pattern) throws ParseException {
-
- String result = null;
-
- if (value instanceof Integer ||
- value instanceof Long ||
- value instanceof BigInteger ||
- value instanceof Byte ||
- value instanceof Short) {
-
- result = getDecimalFormat(locale, pattern).format(((Number) value).longValue());
- }
- else if (value instanceof Double ||
- value instanceof BigDecimal ||
- value instanceof Float) {
-
- result = getDecimalFormat(locale, pattern).format(((Number) value).doubleValue());
- }
- else if (value instanceof Date) { // java.util.Date, java.sql.Date, java.sql.Time, java.sql.Timestamp
-
- final SimpleDateFormat dateFormat =
- new SimpleDateFormat(pattern, locale);
-
- result = dateFormat.format(value);
- }
- else {
- result = value.toString();
- }
-
- return result;
- }
-
- /**
- * Make an instance of DecimalFormat.
- *
- * @param locale The locale
- * @param pattern The pattern is used for the conversion
- * @return The format for the locale and pattern
- *
- * @throws ConversionException if conversion cannot be performed
- * successfully
- * @throws IllegalArgumentException if an error occurs parsing a String to a Number
- */
- private DecimalFormat getDecimalFormat(final Locale locale, final String pattern) {
-
- final DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale);
-
- // if some constructors default pattern to null, it makes only sense to handle null pattern gracefully
- if (pattern != null) {
- if (locPattern) {
- numberFormat.applyLocalizedPattern(pattern);
- } else {
- numberFormat.applyPattern(pattern);
- }
- } else {
- log.debug("No pattern provided, using default.");
- }
-
- return numberFormat;
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/package-info.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/package-info.java
deleted file mode 100644
index 20785ee29..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/converters/package-info.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Standard implementations of the locale-aware
- * {@link org.apache.commons.beanutils2.locale.LocaleConverter} interface that
- * are pre-registered with locale-aware
- * {@link org.apache.commons.beanutils2.locale.LocaleConvertUtils} at startup
- * time.
- */
-package org.apache.commons.beanutils2.locale.converters;
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/package-info.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/package-info.java
deleted file mode 100644
index 0e554ea0f..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/locale/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Locale-aware extensions of the standard beanutils classes.
- * This package allows locale-dependent population of JavaBeans.
- */
-package org.apache.commons.beanutils2.locale;
diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/package-info.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/package-info.java
deleted file mode 100644
index 5cadc54c9..000000000
--- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/package-info.java
+++ /dev/null
@@ -1,1039 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- *
The Bean Introspection Utilities component of the Apache Commons
- * subproject offers low-level utility classes that assist in getting and setting
- * property values on Java classes that follow the naming design patterns outlined
- * in the JavaBeans Specification, as well as mechanisms for dynamically defining
- * and accessing bean properties.
The JavaBeans name comes from a
- * Java API
- * for a component architecture for the Java language. Writing Java classes that
- * conform to the JavaBeans design patterns makes it easier for Java developers
- * to understand the functionality provided by your class, as well as allowing
- * JavaBeans-aware tools to use Java's introspection capabilities to
- * learn about the properties and operations provided by your class, and present
- * them in a visually appealing manner in development tools.
- *
- *
The JavaBeans
- * Specification describes the complete set of characteristics that makes
- * an arbitrary Java class a JavaBean or not -- and you should consider reading
- * this document to be an important part of developing your Java programming
- * skills. However, the required characteristics of JavaBeans that are
- * important for most development scenarios are listed here:
- *
- *
The class must be public, and provide a
- * public constructor that accepts no arguments. This allows
- * tools and applications to dynamically create new instances of your bean,
- * without necessarily knowing what Java class name will be used ahead of
- * time, like this:
- *
As a necessary consequence of having a no-arguments constructor,
- * configuration of your bean's behavior must be accomplished separately
- * from its instantiation. This is typically done by defining a set of
- * properties of your bean, which can be used to modify its behavior
- * or the data that the bean represents. The normal convention for
- * property names is that they start with a lower case letter, and be
- * comprised only of characters that are legal in a Java identifier.
- *
Typically, each bean property will have a public getter and
- * setter method that are used to retrieve or define the property's
- * value, respectively. The JavaBeans Specification defines a design
- * pattern for these names, using {@code get
or set} as the
- * prefix for the property name with it's first character capitalized. Thus,
- * you a JavaBean representing an employee might have
- * (among others) properties named {@code firstName},
- * {@code lastName, and hireDate}, with method signatures
- * like this:
- *
- * public class Employee {
- * public Employee(); // Zero-arguments constructor
- * public String getFirstName();
- * public void setFirstName(String firstName);
- * public String getLastName();
- * public void setLastName(String lastName);
- * public Date getHireDate();
- * public void setHireDate(Date hireDate);
- * public boolean isManager();
- * public void setManager(boolean manager);
- * public String getFullName();
- * }
- *
- *
As you can see from the above example, there is a special variant allowed
- * for boolean properties -- you can name the getter method with a
- * {@code is
prefix instead of a get} prefix if that makes
- * for a more understandable method name.
- *
If you have both a getter and a setter method for a
- * property, the data type returned by the getter must match the
- * data type accepted by the setter. In addition, it is contrary
- * to the JavaBeans specification to have more than one setter
- * with the same name, but different property types.
- *
It is not required that you provide a getter and a
- * setter for every property. In the example above, the
- * {@code fullName} property is read-only, because there is no
- * setter method. It is also possible, but less common, to provide
- * write-only properties.
- *
It is also possible to create a JavaBean where the getter and
- * setter methods do not match the naming pattern described above.
- * The standard JavaBeans support classes in the Java language, as well as
- * all classes in the BeanUtils package, allow you to describe the actual
- * property method names in a {@code BeanInfo} class associated with
- * your bean class. See the JavaBeans Specification for full details.
- *
The JavaBeans Specification also describes many additional design patterns
- * for event listeners, wiring JavaBeans together into component hierarchies,
- * and other useful features that are beyond the scope of the BeanUtils
- * package.
- *
- *
- *
Using standard Java coding techniques, it is very easy to deal with
- * JavaBeans if you know ahead of time which bean classes you will be using, and
- * which properties you are interested in:
As described above, the standard facilities of the Java programming language
- * make it easy and natural to access the property values of your beans using
- * calls to the appropriate getter methods.
- * But what happens in more sophisticated environments where you do not
- * necessarily know ahead of time which bean class you are going to be using,
- * or which property you want to retrieve or modify? The Java language provides
- * classes like {@code java.beans.Introspector}, which can examine a Java
- * class at runtime and identify for you the names of the property getter and
- * setter methods, plus the Reflection capabilities to dynamically call
- * such a method. However, these APIs can be difficult to use, and expose the
- * application developer to many unnecessary details of the underlying structure
- * of Java classes. The APIs in the BeanUtils package are intended to simplify
- * getting and setting bean properties dynamically, where the objects you are
- * accessing -- and the names of the properties you care about -- are determined
- * at runtime in your application, rather than as you are writing and compiling
- * your application's classes.
- *
- *
This is the set of needs that are satisfied by the static methods of the
- * {@link org.apache.commons.beanutils2.PropertyUtils}
- * class, which are described further in this section. First, however, some
- * further definitions will prove to be useful:
- *
- *
The general set of possible property types supported by a JavaBean can be
- * broken into three categories -- some of which are supported by the standard
- * JavaBeans specification, and some of which are uniquely supported by the
- * BeanUtils package:
- *
- *
Simple - Simple, or scalar, properties have a single
- * value that may be retrieved or modified. The underlying property type
- * might be a Java language primitive (such as {@code int}, a simple
- * object (such as a {@code java.lang.String}), or a more complex
- * object whose class is defined either by the Java language, by the
- * application, or by a class library included with the application.
- *
Indexed - An indexed property stores an ordered collection
- * of objects (all of the same type) that can be individually accessed by an
- * integer-valued, non-negative index (or subscript). Alternatively, the
- * entire set of values may be set or retrieved using an array.
- * As an extension to the JavaBeans specification, the
- * BeanUtils package considers any property whose underlying data
- * type is {@code java.util.List} (or an implementation of List) to be
- * indexed as well.
- *
Mapped - As an extension to standard JavaBeans APIs,
- * the BeanUtils package considers any property whose underlying
- * value is a {@code java.util.Map} to be "mapped". You can set and
- * retrieve individual values via a String-valued key.
- *
- *
- *
A variety of API methods are provided in the
- * {@link org.apache.commons.beanutils2.PropertyUtils} class to get and set
- * property values of all of these types.
- * In the code fragments below, assume that there are two bean classes defined
- * with the following method signatures:
- *
- * public class Employee {
- * public Address getAddress(String type);
- * public void setAddress(String type, Address address);
- * public Employee getSubordinate(int index);
- * public void setSubordinate(int index, Employee subordinate);
- * public String getFirstName();
- * public void setFirstName(String firstName);
- * public String getLastName();
- * public void setLastName(String lastName);
- * }
- *
- *
- *
- *
2.2 Basic Property Access
- *
- *
Getting and setting simple property values is, well,
- * simple :-). Check out the following API signatures in the Javadocs:
For indexed properties, you have two choices - you can
- * either build a subscript into the "property name" string, using square
- * brackets, or you can specify the subscript in a separate argument to the
- * method call:
Only integer constants are allowed when you add a subscript to the property
- * name. If you need to calculate the index of the entry you wish to retrieve,
- * you can use String concatenation to assemble the property name expression.
- * For example, you might do either of the following:
- *
- * Employee employee = ...;
- * int index = ...;
- * String name = "subordinate[" + index + "]";
- * Employee subordinate = (Employee)
- * PropertyUtils.getIndexedProperty(employee, name);
- *
- * Employee employee = ...;
- * int index = ...;
- * Employee subordinate = (Employee)
- * PropertyUtils.getIndexedProperty(employee, "subordinate", index);
- *
- *
- *
In a similar manner, there are two possible method signatures for getting
- * and setting mapped properties. The difference is that the
- * extra argument is surrounded by parentheses ("(" and ")") instead of square
- * brackets, and it is considered to be a String-value key used to get or set
- * the appropriate value from an underlying map.
In all of the examples above, we have assumed that you wished to retrieve
- * the value of a property of the bean being passed as the first argument to a
- * PropertyUtils method. However, what if the property value you retrieve is
- * really a Java object, and you wish to retrieve a property of that
- * object instead?
- *
- *
For example, assume we really wanted the {@code city} property of the
- * employee's home address. Using standard Java programming techniques for direct
- * access to the bean properties, we might write:
- *
- *
- * String city = employee.getAddress("home").getCity();
- *
- *
- *
The equivalent mechanism using the PropertyUtils class is called
- * nested property access. To use this approach, you concatenate
- * together the property names of the access path, using "." separators -- very
- * similar to the way you can perform nested property access in JavaScript.
Finally, for convenience, PropertyUtils provides method signatures that
- * accept any arbitrary combination of simple, indexed, and mapped property
- * access, using any arbitrary level of nesting:
As was pointed out, BeanUtils relies on conventions defined by the
- * JavaBeans specification to determine the properties available for
- * a specific bean class. Thus all classes conforming to these conventions can
- * be used out of the box.
- *
- *
Sometimes an application has to deal with classes using different
- * conventions. For instance, fluent APIs allowing method chaining are not
- * compliant to the JavaBeans specification because here set methods
- * have non-void return values. From version 1.9.0 onwards, BeanUtils supports
- * customization of its introspection mechanism. This allows an application
- * to extend or modify the default discovery of bean properties.
- *
- *
The key to this extension mechanism is the {@link org.apache.commons.beanutils2.BeanIntrospector}
- * interface. The purpose of an object implementing this interface is to
- * process a specific target class and create corresponding
- * {@code PropertyDescriptor} objects for the properties it detects.
- * Per default, BeanUtils uses a {@link org.apache.commons.beanutils2.DefaultBeanIntrospector}
- * object which detects properties compatible with the JavaBeans
- * specification.
- *
- *
In order to extend the property discovery mechanism, {@code PropertyUtils}
- * offers the {@link org.apache.commons.beanutils2.PropertyUtils#addBeanIntrospector(BeanIntrospector)}
- * method. Here a custom {@code BeanIntrospector} implementation can be
- * passed in. During introspection of a class, this custom introspector is
- * then called, and it can add the properties it has detected to the total
- * result. As an example of such a custom {@code BeanIntrospector}
- * implementation, BeanUtils ships with the {@link org.apache.commons.beanutils2.FluentPropertyBeanIntrospector}
- * class. This implementation can detect properties whose set methods have a
- * non-void return type - thus enabling support for typical properties in a
- * fluent API.
- *
- *
- *
2.5 Suppressing Properties
- *
The mechanism of customizing bean introspection described in the previous
- * section can also be used to suppress specific properties. There is a
- * specialized {@code BeanIntrospector} implementation that does exactly
- * this: {@link org.apache.commons.beanutils2.SuppressPropertiesBeanIntrospector}.
- * When creating an instance, a collection with the names of properties that
- * should not be accessible on beans has to be provided. These properties will
- * then be removed if they have been detected by other {@code BeanIntrospector}
- * instances during processing of a bean class.
- *
- *
A good use case for suppressing properties is the special {@code class}
- * property which is per default available for all beans; it is generated from the
- * {@code getClass()
method inherited from Object} which follows the
- * naming conventions for property get methods. Exposing this property in an
- * uncontrolled way can lead to a security vulnerability as it allows access to
- * the class loader. More information can be found at
- *
- * https://issues.apache.org/jira/browse/BEANUTILS-463.
- *
- *
Because the {@code class} property is undesired in many use cases
- * there is already an instance of {@code SuppressPropertiesBeanIntrospector}
- * which is configured to suppress this property. It can be obtained via the
- * {@code SUPPRESS_CLASS} constant of
- * {@code SuppressPropertiesBeanIntrospector}.
- *
- *
- *
3. Dynamic Beans (DynaBeans)
- *
- *
- *
3.1 Background
- *
- *
The {@link org.apache.commons.beanutils2.PropertyUtils} class described in the
- * preceding section is designed to provide dynamic property access on existing
- * JavaBean classes, without modifying them in any way. A different use case for
- * dynamic property access is when you wish to represent a dynamically calculated
- * set of property values as a JavaBean, but without having to actually
- * write a Java class to represent these properties. Besides the effort savings
- * in not having to create and maintain a separate Java class, this ability also
- * means you can deal with situations where the set of properties you care about
- * is determined dynamically (think of representing the result set of an SQL
- * select as a set of JavaBeans ...).
- *
- *
To support this use case, the BeanUtils package provides the
- * {@link org.apache.commons.beanutils2.DynaBean} interface, which must be implemented by a
- * bean class actually implementing the interface's methods, and the associated
- * {@link org.apache.commons.beanutils2.DynaClass} interface that defines the set of
- * properties supported by a particular group of DynaBeans, in much the same way
- * that {@code java.lang.Class} defines the set of properties supported by
- * all instances of a particular JavaBean class.
- *
- *
For example, the {@code Employee} class used in the examples above
- * might be implemented as a DynaBean, rather than as a standard JavaBean. You
- * can access its properties like this:
One very important convenience feature should be noted: the
- * PropertyUtils property getter and setter methods understand how to access
- * properties in DynaBeans. Therefore, if the bean you pass as the first
- * argument to, say, {@code PropertyUtils.getSimpleProperty()} is really a
- * DynaBean implementation, the call will get converted to the appropriate
- * DynaBean getter method transparently. Thus, you can base your application's
- * dynamic property access totally on the PropertyUtils APIs, if you wish, and
- * use them to access either standard JavaBeans or DynaBeans without having to
- * care ahead of time how a particular bean is implemented.
- *
- *
Because DynaBean and DynaClass are interfaces, they may be implemented
- * multiple times, in different ways, to address different usage scenarios. The
- * following subsections describe the implementations that are provided as a part
- * of the standard BeanUtils package, although you are encouraged to
- * provide your own custom implementations for cases where the standard
- * implementations are not sufficient.
- *
- *
- *
3.2 {@code BasicDynaBean
and BasicDynaClass}
- *
- *
The {@link org.apache.commons.beanutils2.BasicDynaBean} and
- * {@link org.apache.commons.beanutils2.BasicDynaClass} implementation provides a
- * basic set of
- * dynamic property capabilities where you want to dynamically define the
- * set of properties (described by instances of {@link org.apache.commons.beanutils2.DynaProperty}).
- * You start by defining the DynaClass that establishes
- * the set of properties you care about:
- *
- *
- * DynaProperty[] props = new DynaProperty[]{
- * new DynaProperty("address", java.util.Map.class),
- * new DynaProperty("subordinate", mypackage.Employee[].class),
- * new DynaProperty("firstName", String.class),
- * new DynaProperty("lastName", String.class)
- * };
- * BasicDynaClass dynaClass = new BasicDynaClass("employee", null, props);
- *
- *
- *
Note that the 'dynaBeanClass' argument (in the constructor of
- * {@code BasicDynaClass
) can have the value of null}. In this
- * case, the value of {@code dynaClass.getDynaBeanClass} will just be the
- * {@code Class} for BasicDynaBean.
- *
- *
Next, you use the {@code newInstance()} method of this DynaClass to
- * create new DynaBean instances that conform to this DynaClass, and populate
- * its initial property values (much as you would instantiate a new standard
- * JavaBean and then call its property setters):
Note that the DynaBean class was declared to be
- * {@code DynaBean
instead of BasicDynaBean}. In
- * general, if you are using DynaBeans, you will not want to care about the
- * actual implementation class that is being used -- you only care about
- * declaring that it is a {@code DynaBean} so that you can use the
- * DynaBean APIs.
- *
- *
As stated above, you can pass a DynaBean instance as the first argument
- * to a {@code PropertyUtils} method that gets and sets properties, and it
- * will be interpreted as you expect -- the dynamic properties of the DynaBean
- * will be retrieved or modified, instead of underlying properties on the
- * actual BasicDynaBean implementation class.
- *
- *
- *
3.3 {@code ResultSetDynaClass} (Wraps ResultSet in DynaBeans)
- *
- *
A very common use case for DynaBean APIs is to wrap other collections of
- * "stuff" that do not normally present themselves as JavaBeans. One of the most
- * common collections that would be nice to wrap is the
- * {@code java.sql.ResultSet} that is returned when you ask a JDBC driver
- * to perform a SQL SELECT statement. Commons BeanUtils offers a standard
- * mechanism for making each row of the result set visible as a DynaBean,
- * which you can utilize as shown in this example:
- *
- * Connection conn = ...;
- * Statement stmt = conn.createStatement();
- * ResultSet rs = stmt.executeQuery
- * ("select account_id, name from customers");
- * Iterator rows = (new ResultSetDynaClass(rs)).iterator();
- * while (rows.hasNext()) {
- * DynaBean row = (DynaBean) rows.next();
- * System.out.println("Account number is " +
- * row.get("account_id") +
- * " and name is " + row.get("name"));
- * }
- * rs.close();
- * stmt.close();
- *
- *
- *
- *
- *
3.4 {@code RowSetDynaClass} (Disconnected ResultSet as DynaBeans)
- *
Although {@code ResultSetDynaClass} is
- * a very useful technique for representing the results of an SQL query as a
- * series of DynaBeans, an important problem is that the underlying
- * {@code ResultSet} must remain open throughout the period of time that the
- * rows are being processed by your application. This hinders the ability to use
- * {@code ResultSetDynaClass} as a means of communicating information from
- * the model layer to the view layer in a model-view-controller architecture
- * such as that provided by the Struts
- * Framework, because there is no easy mechanism to assure that the result set
- * is finally closed (and the underlying {@code Connection} returned to its
- * connection pool, if you are using one).
- *
- *
The {@code RowSetDynaClass} class represents a different approach to
- * this problem. When you construct such an instance, the underlying data is
- * copied into a set of in-memory DynaBeans that represent the result.
- * The advantage of this technique, of course, is that you can immediately close
- * the ResultSet (and the corresponding Statement), normally before you even
- * process the actual data that was returned. The disadvantage, of course, is
- * that you must pay the performance and memory costs of copying the result data,
- * and the result data must fit entirely into available heap memory. For many
- * environments (particularly in web applications), this tradeoff is usually
- * quite beneficial.
- *
- *
As an additional benefit, the {@code RowSetDynaClass} class is defined
- * to implement {@code java.io.Serializable}, so that it (and the
- * DynaBeans that correspond to each row of the result) can be conveniently
- * serialized and deserialized (as long as the underlying column values are
- * also Serializable). Thus, {@code RowSetDynaClass} represents a very
- * convenient way to transmit the results of an SQL query to a remote Java-based
- * client application (such as an applet).
- *
- *
The normal usage pattern for a {@code RowSetDynaClass} will look
- * something like this:
- *
- * Connection conn = ...; // Acquire connection from pool
- * Statement stmt = conn.createStatement();
- * ResultSet rs = stmt.executeQuery("SELECT ...");
- * RowSetDynaClass rsdc = new RowSetDynaClass(rs);
- * rs.close();
- * stmt.close();
- * ...; // Return connection to pool
- * List rows = rsdc.getRows();
- * ...; // Process the rows as desired
- *
- *
- *
- *
- *
3.5 {@code WrapDynaBean
and WrapDynaClass}
- *
- *
OK, you've tried the DynaBeans APIs and they are cool -- very simple
- * {@code get()
and set()} methods provide easy access to all
- * of the dynamically defined simple, indexed, and mapped properties of your
- * DynaBeans. You'd like to use the DynaBean APIs to access all
- * of your beans, but you've got a bunch of existing standard JavaBeans classes
- * to deal with as well. This is where the
- * {@link org.apache.commons.beanutils2.WrapDynaBean} (and its associated
- * {@link org.apache.commons.beanutils2.WrapDynaClass}) come into play. As the name
- * implies, a WrapDynaBean is used to "wrap" the DynaBean APIs around an
- * existing standard JavaBean class. To use it, simply create the wrapper
- * like this:
- *
- *
Note that, although appropriate {@code WrapDynaClass} instances are
- * created internally, you never need to deal with them.
- *
- *
- *
3.6 Lazy DynaBeans
- *
- *
- *
1. LazyDynaBean - A Lazy
- * {@link org.apache.commons.beanutils2.DynaBean}
- *
2. LazyDynaMap - A light weight
- * {@link org.apache.commons.beanutils2.DynaBean} facade to a Map
- * with lazy map/list processing
- *
3. LazyDynaList - A lazy list
- * for {@link org.apache.commons.beanutils2.DynaBean DynaBean's},
- * {@code java.util.Map}'s or POJO beans.
- *
4. LazyDynaClass - A
- * {@link org.apache.commons.beanutils2.MutableDynaClass} implementation.
- *
- *
- *
You bought into the DynaBeans because it saves coding all those POJO JavaBeans but
- * you're here because lazy caught your eye and wondered whats that about?
- * What makes these flavors of DynaBean lazy are the following features:
- *
- *
Lazy property addition - lazy beans use a
- * {@link org.apache.commons.beanutils2.DynaClass} which implements
- * the {@link org.apache.commons.beanutils2.MutableDynaClass}
- * interface. This provides the ability to add and remove a DynaClass's
- * properties. Lazy beans use this feature to automatically add
- * a property which doesn't exist to the DynaClass when
- * the {@code set(name, value)} method is called.
- *
Lazy List/Array growth - If an indexed property is not large
- * enough to accomodate the {@code index
being set then the List} or
- * {@code Array} is automatically grown so that it is.
- *
Lazy List/Array instantiation - if an indexed
- * property doesn't exist then calling the {@link org.apache.commons.beanutils2.DynaBean DynaBean's}
- * indexed property getter/setter methods (i.e. {@code get(name, index)} or
- * {@code set(name, index, value)
) results in either a new List}
- * or {@code Array} being instantiated. If the indexed property has not been
- * defined in the DynaClass then it is automatically added and a default {@code List}
- * implementation instantiated.
- *
Lazy Map instantiation - if a mapped
- * property doesn't exist then calling the {@link org.apache.commons.beanutils2.DynaBean DynaBean's}
- * mapped property getter/setter methods (i.e. {@code get(name, key)} or
- * {@code set(name, key, value)
) results in a new Map}
- * being instantiated. If the mapped property has not been defined in the DynaClass
- * then it is automatically added and a default {@code Map} implementation
- * instantiated.
- *
Lazy Bean instantiation - if a property is defined in
- * the {@code DynaClass
as a DynaBean} or regular bean and
- * doesn't exist in the {@code DynaBean then LazyDynaBean} wiill
- * try to instantiate the bean using a default empty constructor.
- *
- *
- *
1. {@link org.apache.commons.beanutils2.LazyDynaBean} is the standard lazy bean
- * implementation. By default it is associated with a {@link org.apache.commons.beanutils2.LazyDynaClass}
- * which implements the {@link org.apache.commons.beanutils2.MutableDynaClass} interface - however
- * it can be used with any {@code MutableDynaClass} implementation. The question is how do
- * I use it? - well it can be as simple as creating a new bean and then calling the getters/setters...
2. {@link org.apache.commons.beanutils2.LazyDynaMap} is a light weight
- * {@code DynaBean
facade to a Map} with all the usual lazy features. Its
- * light weight because it doesn't have an associated {@code DynaClass} containing all the properties.
- * In fact it actually implements the {@code DynaClass interface itself (and MutableDynaClass})
- * and derives all the DynaClass information from the actual contents of the {@code Map}. A
- * {@code LazyDynaMap can be created around an existing Map} or can instantiate its own
- * {@code Map. After any DynaBean processing has finished the Map} can be retrieved
- * and the DynaBean facade discarded.
- *
- *
- * Map myMap = .... // exisitng Map
- * DynaBean dynaBean = new LazyDynaMap(myMap); // wrap Map in DynaBean
- * dynaBean.set("foo", "bar"); // set properties
- *
- *
- *
3. {@link org.apache.commons.beanutils2.LazyDynaList}
- * is lazy list for {@link org.apache.commons.beanutils2.DynaBean DynaBeans}
- * {@code java.util.Map}'s or POJO beans. See the Javadoc
- * for more details and example usage.
- *
- *
4. {@link org.apache.commons.beanutils2.LazyDynaClass}
- * extends {@link org.apache.commons.beanutils2.BasicDynaClass} and implements
- * the MutableDynaClass interface.
- * It can be used with other {@code DynaBean} implementations, but it
- * is the default {@code DynaClass
used by LazyDynaBean}.
- * When using the {@code LazyDynaBean} there may be no need to have
- * anything to do with the {@code DynaClass}. However sometimes there
- * is a requirement to set up the {@code DynaClass} first - perhaps to
- * define the type of array for an indexed property, or if using the DynaBean
- * in restricted mode (see note below) is required. Doing so is
- * straight forward...
- *
- *
Either create a {@code LazyDynaClass} first...
- *
- *
NOTE: One feature of {@link org.apache.commons.beanutils2.MutableDynaClass} is that it
- * has a Restricted property. When the DynaClass is restricted no properties can be added
- * or removed from the {@code DynaClass
. Neither the LazyDynaBean or LazyDynaMap}
- * will add properties automatically if the {@code DynaClass} is restricted.
- *
- *
- *
- *
4. Data Type Conversions
- *
- *
- *
4.1 Background
- *
- *
So far, we've only considered the cases where the data types of the
- * dynamically accessed properties are known, and where we can use Java casts
- * to perform type conversions. What happens if you want to automatically
- * perform type conversions when casting is not possible? The
- * BeanUtils package provides a variety of APIs and design patterns
- * for performing this task as well.
- *
- *
- *
4.2 {@code BeanUtils
and ConvertUtils} Conversions
- *
- *
A very common use case (and the situation that caused the initial creation
- * of the BeanUtils package) was the desire to convert the set of request
- * parameters that were included in a
- * {@code javax.servlet.HttpServletRequest} received by a web application
- * into a set of corresponding property setter calls on an arbitrary JavaBean.
- * (This is one of the fundamental services provided by the
- * Struts Framework, which uses
- * BeanUtils internally to implement this functionality.)
- *
- *
In an HTTP request, the set of included parameters is made available as a
- * series of String (or String array, if there is more than one value for the
- * same parameter name) instances, which need to be converted to the underlying
- * data type. The {@link org.apache.commons.beanutils2.BeanUtils} class provides
- * property setter methods that accept String values, and automatically convert
- * them to appropriate property types for Java primitives (such as
- * {@code int
or boolean}), and property getter methods that
- * perform the reverse conversion. Finally, a {@code populate()} method
- * is provided that accepts a {@code java.util.Map} containing a set of
- * property values (keyed by property name), and calls all of the appropriate
- * setters whenever the underlying bean has a property with the same name as
- * one of the request parameters. So, you can perform the all-in-one property
- * setting operation like this:
- *
- *
The {@code BeanUtils} class relies on conversion methods defined in
- * the {@link org.apache.commons.beanutils2.ConvertUtils} class to perform the actual
- * conversions, and these methods are availablve for direct use as well.
- * WARNING - It is likely that the hard coded use of
- * {@code ConvertUtils} methods will be deprecated in the future, and
- * replaced with a mechanism that allows you to plug in your own implementations
- * of the {@link org.apache.commons.beanutils2.Converter} interface instead. Therefore,
- * new code should not be written with reliance on ConvertUtils.
- *
- *
- *
4.3 Defining Your Own Converters
- *
- *
The {@code ConvertUtils} class supports the ability to define and
- * register your own String --> Object conversions for any given Java class.
- * Once registered, such converters will be used transparently by all of the
- * {@code BeanUtils
methods (including populate()}). To
- * create and register your own converter, follow these steps:
- *
- *
Write a class that implements the {@link org.apache.commons.beanutils2.Converter}
- * interface. The {@code convert()} method should accept the
- * {@code java.lang.Class} object of your application class (i.e.
- * the class that you want to convert to, and a String representing the
- * incoming value to be converted.
- *
At application startup time, register an instance of your converter class
- * by calling the {@code ConvertUtils.register()} method.
- *
- *
- *
- *
4.4 Locale Aware Conversions
- *
The standard classes in {@code org.apache.commons.beanutils2} are not
- * locale aware. This gives them a cleaner interface and makes then easier to use
- * in situations where the locale is not important.
- *
Extended, locale-aware analogues can be found in
- * org.apache.commons.beanutils2.locale
- * . These are built along the same
- * lines as the basic classes but support localization.
- *
- *
- *
- *
5. Utility Objects And Static Utility Classes
- *
- *
Background
- *
- * So far, the examples have covered the static utility classes ({@code BeanUtils},
- * {@code ConvertUtils
and PropertyUtils}). These are easy to use but are
- * somewhat inflexible. These all share the same registered converters and the same caches.
- *
- *
- * This functionality can also be accessed through utility objects (in fact, the static utility
- * class use worker instances of these classes). For each static utility class, there is a corresponding
- * class with the same functionality that can be instantiated:
- *
- *
- *
- *
Utility Objects And Static Utility Classes
- *
Static Utility Class
Utility Object
- *
BeanUtils
BeanUtilsBean
- *
ConvertUtils
ConvertUtilsBean
- *
PropertyUtils
PropertyUtilsBean
- *
- *
- *
- * Creating an instances allow gives guarenteed control of the caching and registration
- * to the code that creates it.
- *
is a Comparator} implementation
- * that compares beans based on a shared property value.
- *
- *
- *
6.2 Operating On Collections Of Beans
- *
- * The {@code Closure
interface in commons-collections} encapsulates a block of code that
- * executes on an arbitrary input Object. {@code Commons-collections} contains code that allows
- * {@code Closures} to be applied to the contents of a Collection. For more details, see the
- * commons-collections
- * documentation.
- *
- *
- * {@code BeanPropertyValueChangeClosure
is a Closure} that sets a specified property
- * to a particular value. A typical usage is to combine this with {@code commons-collections}
- * so that all the beans in a collection can have a particular property set to a particular value.
- *
- *
For example, set the activeEmployee property to TRUE for an entire collection:
interface in commons-collections} encapsulates an evaluation
- * of an input Object that returns either true or false. {@code Commons-collections} contains code
- * that allows
- * {@code Predicates} to be applied to be used to filter collections. For more details, see the
- * commons-collections
- * documentation.
- *
- *
- * {@code BeanPropertyValueEqualsPredicate
is a Predicate} that evaluates a
- * set property value against a given value. A typical usage is
- * (in combination with {@code commons-collections})
- * to filter collections on the basis of a property value.
- *
- *
For example, to filter a collection to find all beans where active employee is false use:
interface in commons-collections} encapsulates the transformation
- * of an input Object into an output object. {@code Commons-collections} contains code
- * that allows
- * {@code Transformers} to be applied produce a collection of outputs from a collection of inputs.
- * For more details, see the
- * commons-collections
- * documentation.
- *
- *
- * {@code BeanToPropertyTransformer
is a Transformer} implementation
- * that transforms a bean into it's property value.
- *
- *
- * For example, to find all cities that are contained in the address of each person property of each bean in
- * a collection:
- *
The BeanUtils package relies on introspection rather than
- * reflection. This means that it will find only
- * JavaBean
- * compliant properties.
- *
There are some subtleties of this specification that can catch out the unwary:
- *
- *
A property can have only one set and one get method. Overloading is not allowed.
- *
The {@code java.beans.Introspector} searches widely for a custom BeanInfo
- * class. If your class has the same name as another with a custom BeanInfo
- * (typically a java API class) then the {@code Introspector} may use that instead of
- * creating via reflection based on your class. If this happens, the only solution is to
- * create your own BeanInfo.
- *
- *
- *
- *
How Do I Set The BeanComparator Order To Be Ascending/Descending?
- *
- * BeanComparator relies on an internal Comparator to perform the actual
- * comparisions. By default, a natural ordering comparator
- * is used which imposes a natural order. If you want to change the order,
- * then a custom Comparator should be created and passed into the
- * appropriate constructor.
- *
The Bean Introspection Utilities component of the Apache Commons
-subproject offers low-level utility classes that assist in getting and setting
-property values on Java classes that follow the naming design patterns outlined
-in the JavaBeans Specification, as well as mechanisms for dynamically defining
-and accessing bean properties.
-
-
See the
-
-Package Description for the org.apache.commons.beanutils2
-package for more information.
-This is actually pretty useful when it comes to collections of beans. It's a common
-problem to want to extract information from a collection of beans or to change all properties
-to a particular value. Functors can be a particularly elegant way to do this. So try them!
-You might just like them!
-
-
-For more information about functors, please read the introduction to the
-Commons Functor component.
-
-
-
-
-
-BeanUtils Bean-Collections is distributed as an optional jar within the main
-beanutils distribution. For details, see the
-main BeanUtils website
-
- Build using
- Maven 3
- is the preferred build method.
- The compiled BeanUtils JAR should work with Java 6 or later.
-
-
-
-
- To build
- target/commons-beanutils-*.jar
-
-
-
- mvn clean package
-
-
-
- or to install into your
- ~/.m2/repository
-
-
-
- mvn clean install
-
-
-
-
- You can skip the unit tests by adding the parameter
- -DskipTests=true
-
-
-
- To regenerate the web site
- (corresponding to
- https://commons.apache.org/proper/commons-beanutils/)
-
-
-
- mvn clean site
-
-
-
- Note: the Apache Commons BeanUtils site should include a
- japicmp report
- for the
- purpose of checking API version compatibility; to enable this, use Java 7
- or later and run instead:
-
- We recommend you use a mirror to download our release
- builds, but you mustverify the integrity of
- the downloaded files using signatures downloaded from our main
- distribution directories. Recent releases (48 hours) may not yet
- be available from all the mirrors.
-
-
-
- You are currently using [preferred]. If you
- encounter a problem with this mirror, please select another
- mirror. If all mirrors are failing, there are backup
- mirrors (at the end of the mirrors list) that should be
- available.
-
- [if-any logo][end]
-
-
-
-
-
- It is essential that you
- verify the integrity
- of downloaded files, preferably using the PGP signature (*.asc files);
- failing that using the SHA1 hash (*.sha1 checksum files).
-
-
- The KEYS
- file contains the public PGP keys used by Apache Commons developers
- to sign releases.
-
-Most Java developers are used to creating Java classes that conform to the
-JavaBeans naming patterns for property getters and setters. It is natural to
-then access these methods directly, using calls to the corresponding
-getXxx and setXxx methods. However, there are some
-occasions where dynamic access to Java object properties (without compiled-in
-knowledge of the property getter and setter methods to be called) is needed.
-Example use cases include:
-
-
Building scripting languages that interact with the Java object model
- (such as the Bean Scripting Framework).
-
Building template language processors for web presentation and similar
- uses (such as JSP or Velocity).
-
Building custom tag libraries for JSP and XSP environments (such as Jakarta
- Taglibs, Struts, Cocoon).
-
Consuming XML-based configuration resources (such as Ant build scripts, web
- application deployment descriptors, Tomcat's server.xml
- file).
-
-
-
-The Java language provides Reflection and Introspection
-APIs (see the java.lang.reflect and java.beans
-packages in the JDK Javadocs). However, these APIs can be quite complex to
-understand and utilize. The BeanUtils component provides
-easy-to-use wrappers around these capabilities.
-
-
-
-
-The 1.7.x and 1.8.x releases of BeanUtils distributed three jars:
-
commons-beanutils-bean-collections.jar - only Bean Collections classes
-
-The main commons-beanutils.jar has an optional dependency on
-Commons Collections
-
-
-Version 1.9.0 reverts this split for reasons outlined at
-BEANUTILS-379.
-There is now only one jar for the BeanUtils library.
-
-
-Version 2.0.0 updates the dependencies for Apache Commons Collection from version 3 to 4.
-Apache Commons Collection 4 changes packages from org.apache.commons.collections
-to org.apache.commons.collections4.
-Since some Commons BeanUtils APIs surface Commons Collection types, Commons BeanUtils 2 changes packages from org.apache.commons.beanutils
-to org.apache.commons.beanutils2.
-
-
-
-
-Bean collections is a library combining BeanUtils with
-Commons Collections
-to provide services for collections of beans. One class (BeanComparator)
-was previously released, the rest are new. This new distribution strategy should allow
-this sub-component to evolve naturally without the concerns about size and scope
-that might otherwise happen.
-
- CVE-2019-10086. Apache Commons Beanutils does not suppresses
- the class property in bean introspection by default.
- Severity. Medium
- Vendor. The Apache Software Foundation
- Versions Affected. All versions commons-beanutils-1.9.3 and before.
- Description. In version 1.9.2, a special BeanIntrospector class was added which allows suppressing the ability for
- an attacker to access the classloader via the class property available on all Java objects. We, however were not
- using this by default characteristic of the PropertyUtilsBean.
- Mitigation. Upgrade to commons-beanutils-1.9.4
- Credit. This was discovered by Melloware (https://melloware.com/).
- Example.
-
-
-
- BeanUtils 1.9.x releases are binary compatible (with a minor exception
- described in the release notes) with version 1.8.3 and require a minimum of
- JDK 1.5.
-
-
- The latest BeanUtils release is available to download
- here.
-
-BeanUtils 1.7.0 is a service release which removes the dependency
-upon a specific commons-collection library version. It may be safely used together
-with either the 2.x or 3.x series of commons-collections releases.
-It also introduces a number of important enhancements. It is backward compatible
-with the 1.6 release.
-
-
-This important service release is intended to help downstream applications solve
-dependency issues. The dependency on commons collections (which has become problematic
-now that there are two incompatible series of commons collections releases)
-has been factored into a separate optional sub-component plus a small number of
-stable and mature org.apache.commons.collections packaged classes
-(which are distributed with the BeanUtils core). This arrangement means that the
-BeanUtils core sub-component (which is the primary dependency for most downsteam
-applications) can now be safely included on the same classpath as commons collections
-2.x, 3.x or indeed neither.
-
-
-The distribution now contains alternative jar sets. The all-in-one
-jar contains all classes. The modular jar set consists of a core jar dependent only
-on commons logging and an optional bean collections jar (containing classes that
-provide easy and efficient ways to manage collections of beans) which depends on
-commons collections 3.
-
- The commons mailing lists act as the main support forum.
- The user list is suitable for most library usage queries.
- The dev list is intended for the development discussion.
- Please remember that the lists are shared between all commons components,
- so prefix your email by [beanutils].
-
- To use JIRA you may need to create an account
- (if you have previously created/updated Commons issues using Bugzilla an account will have been automatically
- created and you can use the Forgot Password
- page to get a new password).
-
-
-
- If you would like to report a bug, or raise an enhancement request with
- Apache Commons BeanUtils please do the following:
-
-
Search existing open bugs.
- If you find your issue listed then please add a comment with your details.
- Apache Commons BeanUtils shares mailing lists with all the other
- Commons Components.
- To make it easier for people to only read messages related to components they are interested in,
- the convention in Commons is to prefix the subject line of messages with the component's name,
- for example:
-
-
[beanutils] Problem with the ...
-
-
-
- Questions related to the usage of Apache Commons BeanUtils should be posted to the
- User List.
-
- The Developer List
- is for questions and discussion related to the development of Apache Commons BeanUtils.
-
- Please do not cross-post; developers are also subscribed to the user list.
-
- You must be subscribed to post to the mailing lists. Follow the Subscribe links below
- to subscribe.
-
-
- Note: please don't send patches or attachments to any of the mailing lists.
- Patches are best handled via the Issue Tracking system.
- Otherwise, please upload the file to a public server and include the URL in the mail.
-
-
-
-
-
- Please prefix the subject line of any messages for Apache Commons BeanUtils
- with [beanutils] - thanks!
-
-
-
Most Java developers are used to creating Java classes that conform to the
-JavaBeans naming patterns for property getters and setters. It is natural to
-then access these methods directly, using calls to the corresponding
-getXxx and setXxx methods. However, there are some
-occasions where dynamic access to Java object properties (without compiled-in
-knowledge of the property getter and setter methods to be called) is needed.
-Example use cases include:
-
-
Building scripting languages that interact with the Java object model
- (such as the Bean Scripting Framework).
-
Building template language processors for web presentation and similar
- uses (such as JSP or Velocity).
-
Building custom tag libraries for JSP and XSP environments (such as Jakarta
- Taglibs, Struts, Cocoon).
-
Consuming XML-based configuration resources (such as Ant build scripts, web
- application deployment descriptors, Tomcat's server.xml
- file).
-
-
-
The Java language provides Reflection and Introspection
-APIs (see the java.lang.reflect and java.beans
-packages in the JDK Javadocs). However, these APIs can be quite complex to
-understand and utilize. The proposed BeanUtils component provides
-easy-to-use wrappers around these capabilities.
-
-
-
-
-
-
This proposal is to create a package of Java utility methods for accessing
-and modifying the properties of arbitrary JavaBeans. No dependencies outside
-of the JDK are required, so the use of this package is very lightweight.
-
-
In addition to wrapping the reflection and introspection APIs of the
-standard JDK, BeanUtils components shall support a syntax for directly
-accessing nested and indexed properties, in a
-manner that will be familar to users of scripting languages like JavaScript.
-For example, the following property accessor expressions are supported:
-
-
customer - Equivalent to getCustomer().
-
customer.address - Equivalent to
- getCustomer().getAddress().
-
customer.address[2].street - Equivalent to
- getCustomer().getAddress(2).getStreet() (access to indexed
- properties also works if the underlying property is an array rather than
- providing indexed getter and setter methods).
-
-
-
-
-
-
-
BeanUtils relies only on standard JDK 1.2 (or later) APIs for
-production deployment. It utilizes the JUnit unit testing framework for
-developing and executing unit tests, but this is of interest only to
-developers of the component. BeanUtils will also be a dependency for
-several future proposed components for the Jakarta Commons subproject.
-
-
No external configuration files are utilized.
-
-
-
-
-
-
The three original Java classes (BeanUtils,
-ConvertUtils, and PropertyUtils) are an integral
-part of the Struts Framework.
-However, they have very few dependencies on other aspects of Struts, and
-those dependencies have been removed in the proposed code base.
-Once accepted and released as a Jakarta Commons component, Struts will
-be modified to use the Commons version of these classes, and its internal
-versions will be deprecated.
-
-
The proposed package name for the new component is
-org.apache.commons.beanutils.
-
-
-
-
-
-
-
CVS Repository - New directory beanutils in the
- jakarta-commons CVS repository. All initial committers
- are already committers on jakarta-commons, so no
- additional user setups are required.
-
Mailing List - Discussions will take place on the general
- jakarta-commons@jakarta.apache.org mailing list. To help
- list subscribers identify messages of interest, it is suggested that
- the message subject of messages about this component be prefixed with
- [BeanUtils].
-
Bugzilla - New component "BeanUtils" under the "Commons" product
- category, with appropriate version identifiers as needed.
-
Jyve FAQ - New category "commons-beanutils" (when available).
-
-
-
-
-
-
-
The initial committers on the BeanUtils component shall be Craig
-McClanahan and Geir Magnusson Jr.
-
-
-
-
-
-
-
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/A.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/A.java
deleted file mode 100644
index 627609935..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/A.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.io.OutputStream;
-
-/**
- *
Class used in MethodUtils test
- *
- */
-public class A {
-
- boolean called = false;
-
- public void foo(final OutputStream os)
- {
- called = true;
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/AbstractChild.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/AbstractChild.java
deleted file mode 100644
index b7b9fc428..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/AbstractChild.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- */
-public class AbstractChild implements Child {
-
- private String name;
-
- protected void setName(final String name)
- {
- this.name = name;
- }
-
- @Override
- public String getName()
- {
- return name;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/AbstractParent.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/AbstractParent.java
deleted file mode 100644
index 984d36426..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/AbstractParent.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- */
-public abstract class AbstractParent {
-
- private Child child;
-
- public Child getChild()
- {
- return child;
- }
-
- /**
- * Method which matches signature but which has wrong parameters
- */
- public String testAddChild(final String badParameter) {
- return null;
- }
-
- /**
- * Method which matches signature but which has wrong parameters
- */
- public String testAddChild2(final String ignore, final String badParameter) {
- return null;
- }
-
- public String testAddChild(final Child child) {
- this.child = child;
- return child.getName();
- }
-
- public String testAddChild2(final String ignore, final Child child) {
- this.child = child;
- return child.getName();
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/AlphaBean.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/AlphaBean.java
deleted file mode 100644
index c4da8a43b..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/AlphaBean.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- */
-public class AlphaBean extends AbstractParent implements Child {
-
- private String name;
-
- public AlphaBean() {
- }
-
- public AlphaBean(final String name) {
- setName(name);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- /**
- * Used for testing that correct exception is thrown.
- */
- public void bogus(final String badParameter) {
- // noop
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BasicDynaBeanTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BasicDynaBeanTestCase.java
deleted file mode 100644
index c20bc3954..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BasicDynaBeanTestCase.java
+++ /dev/null
@@ -1,971 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
Test Case for the {@code BasicDynaBean} implementation class.
- * These tests were based on the ones in {@code PropertyUtilsTestCase}
- * because the two classes provide similar levels of functionality.
- *
- */
-
-public class BasicDynaBeanTestCase extends TestCase {
-
-
-
- /**
- * The basic test bean for each test.
- */
- protected DynaBean bean = null;
-
- /**
- * The set of property names we expect to have returned when calling
- * {@code getDynaProperties()}. You should update this list
- * when new properties are added to TestBean.
- */
- protected final static String[] properties = {
- "booleanProperty",
- "booleanSecond",
- "doubleProperty",
- "floatProperty",
- "intArray",
- "intIndexed",
- "intProperty",
- "listIndexed",
- "longProperty",
- "mappedProperty",
- "mappedIntProperty",
- "nullProperty",
- "shortProperty",
- "stringArray",
- "stringIndexed",
- "stringProperty",
- };
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public BasicDynaBeanTestCase(final String name) {
-
- super(name);
-
- }
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
-
- // Instantiate a new DynaBean instance
- final DynaClass dynaClass = createDynaClass();
- bean = dynaClass.newInstance();
-
- // Initialize the DynaBean's property values (like TestBean)
- bean.set("booleanProperty", new Boolean(true));
- bean.set("booleanSecond", new Boolean(true));
- bean.set("doubleProperty", new Double(321.0));
- bean.set("floatProperty", new Float((float) 123.0));
- final int[] intArray = { 0, 10, 20, 30, 40 };
- bean.set("intArray", intArray);
- final int[] intIndexed = { 0, 10, 20, 30, 40 };
- bean.set("intIndexed", intIndexed);
- bean.set("intProperty", new Integer(123));
- final List listIndexed = new ArrayList<>();
- listIndexed.add("String 0");
- listIndexed.add("String 1");
- listIndexed.add("String 2");
- listIndexed.add("String 3");
- listIndexed.add("String 4");
- bean.set("listIndexed", listIndexed);
- bean.set("longProperty", new Long(321));
- final HashMap mappedProperty = new HashMap<>();
- mappedProperty.put("First Key", "First Value");
- mappedProperty.put("Second Key", "Second Value");
- bean.set("mappedProperty", mappedProperty);
- final HashMap mappedIntProperty = new HashMap<>();
- mappedIntProperty.put("One", new Integer(1));
- mappedIntProperty.put("Two", new Integer(2));
- bean.set("mappedIntProperty", mappedIntProperty);
- // Property "nullProperty" is not initialized, so it should return null
- bean.set("shortProperty", new Short((short) 987));
- final String[] stringArray =
- { "String 0", "String 1", "String 2", "String 3", "String 4" };
- bean.set("stringArray", stringArray);
- final String[] stringIndexed =
- { "String 0", "String 1", "String 2", "String 3", "String 4" };
- bean.set("stringIndexed", stringIndexed);
- bean.set("stringProperty", "This is a string");
-
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
-
- return new TestSuite(BasicDynaBeanTestCase.class);
-
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
-
- bean = null;
-
- }
-
-
-
- /**
- * Corner cases on getDynaProperty invalid arguments.
- */
- public void testGetDescriptorArguments() {
-
- try {
- final DynaProperty descriptor =
- bean.getDynaClass().getDynaProperty("unknown");
- assertNull("Unknown property descriptor should be null",
- descriptor);
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of returning null");
- }
-
- try {
- bean.getDynaClass().getDynaProperty(null);
- fail("Should throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException");
- }
-
- }
-
- /**
- * Positive getDynaProperty on property {@code booleanProperty}.
- */
- public void testGetDescriptorBoolean() {
-
- testGetDescriptorBase("booleanProperty", Boolean.TYPE);
-
- }
-
- /**
- * Positive getDynaProperty on property {@code doubleProperty}.
- */
- public void testGetDescriptorDouble() {
-
- testGetDescriptorBase("doubleProperty", Double.TYPE);
-
- }
-
- /**
- * Positive getDynaProperty on property {@code floatProperty}.
- */
- public void testGetDescriptorFloat() {
-
- testGetDescriptorBase("floatProperty", Float.TYPE);
-
- }
-
- /**
- * Positive getDynaProperty on property {@code intProperty}.
- */
- public void testGetDescriptorInt() {
-
- testGetDescriptorBase("intProperty", Integer.TYPE);
-
- }
-
- /**
- * Positive getDynaProperty on property {@code longProperty}.
- */
- public void testGetDescriptorLong() {
-
- testGetDescriptorBase("longProperty", Long.TYPE);
-
- }
-
- /**
- * Positive getDynaProperty on property {@code booleanSecond}
- * that uses an "is" method as the getter.
- */
- public void testGetDescriptorSecond() {
-
- testGetDescriptorBase("booleanSecond", Boolean.TYPE);
-
- }
-
- /**
- * Positive getDynaProperty on property {@code shortProperty}.
- */
- public void testGetDescriptorShort() {
-
- testGetDescriptorBase("shortProperty", Short.TYPE);
-
- }
-
- /**
- * Positive getDynaProperty on property {@code stringProperty}.
- */
- public void testGetDescriptorString() {
-
- testGetDescriptorBase("stringProperty", String.class);
-
- }
-
- /**
- * Positive test for getDynaProperties(). Each property name
- * listed in {@code properties} should be returned exactly once.
- */
- public void testGetDescriptors() {
-
- final DynaProperty[] pd = bean.getDynaClass().getDynaProperties();
- assertNotNull("Got descriptors", pd);
- final int[] count = new int[properties.length];
- for (final DynaProperty element : pd) {
- final String name = element.getName();
- for (int j = 0; j < properties.length; j++) {
- if (name.equals(properties[j])) {
- count[j]++;
- }
- }
- }
- for (int j = 0; j < properties.length; j++) {
- if (count[j] < 0) {
- fail("Missing property " + properties[j]);
- } else if (count[j] > 1) {
- fail("Duplicate property " + properties[j]);
- }
- }
-
- }
-
- /**
- * Corner cases on getIndexedProperty invalid arguments.
- */
- public void testGetIndexedArguments() {
-
- try {
- bean.get("intArray", -1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (final IndexOutOfBoundsException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IndexOutOfBoundsException");
- }
-
- }
-
- /**
- * Positive and negative tests on getIndexedProperty valid arguments.
- */
- public void testGetIndexedValues() {
-
- Object value = null;
-
- for (int i = 0; i < 5; i++) {
-
- try {
- value = bean.get("intArray", i);
- assertNotNull("intArray returned value " + i, value);
- assertTrue("intArray returned Integer " + i,
- value instanceof Integer);
- assertEquals("intArray returned correct " + i, i * 10,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("intArray " + i + " threw " + t);
- }
-
- try {
- value = bean.get("intIndexed", i);
- assertNotNull("intIndexed returned value " + i, value);
- assertTrue("intIndexed returned Integer " + i,
- value instanceof Integer);
- assertEquals("intIndexed returned correct " + i, i * 10,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("intIndexed " + i + " threw " + t);
- }
-
- try {
- value = bean.get("listIndexed", i);
- assertNotNull("listIndexed returned value " + i, value);
- assertTrue("list returned String " + i,
- value instanceof String);
- assertEquals("listIndexed returned correct " + i,
- "String " + i, (String) value);
- } catch (final Throwable t) {
- fail("listIndexed " + i + " threw " + t);
- }
-
- try {
- value = bean.get("stringArray", i);
- assertNotNull("stringArray returned value " + i, value);
- assertTrue("stringArray returned String " + i,
- value instanceof String);
- assertEquals("stringArray returned correct " + i,
- "String " + i, (String) value);
- } catch (final Throwable t) {
- fail("stringArray " + i + " threw " + t);
- }
-
- try {
- value = bean.get("stringIndexed", i);
- assertNotNull("stringIndexed returned value " + i, value);
- assertTrue("stringIndexed returned String " + i,
- value instanceof String);
- assertEquals("stringIndexed returned correct " + i,
- "String " + i, (String) value);
- } catch (final Throwable t) {
- fail("stringIndexed " + i + " threw " + t);
- }
-
- }
-
- }
-
- /**
- * Corner cases on getMappedProperty invalid arguments.
- */
- public void testGetMappedArguments() {
-
- try {
- final Object value = bean.get("mappedProperty", "unknown");
- assertNull("Should not return a value", value);
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of returning null");
- }
-
- }
-
- /**
- * Positive and negative tests on getMappedProperty valid arguments.
- */
- public void testGetMappedValues() {
-
- Object value = null;
-
- try {
- value = bean.get("mappedProperty", "First Key");
- assertEquals("Can find first value", "First Value", value);
- } catch (final Throwable t) {
- fail("Finding first value threw " + t);
- }
-
- try {
- value = bean.get("mappedProperty", "Second Key");
- assertEquals("Can find second value", "Second Value", value);
- } catch (final Throwable t) {
- fail("Finding second value threw " + t);
- }
-
- try {
- value = bean.get("mappedProperty", "Third Key");
- assertNull("Can not find third value", value);
- } catch (final Throwable t) {
- fail("Finding third value threw " + t);
- }
-
- }
-
- /**
- * Corner cases on getSimpleProperty invalid arguments.
- */
- public void testGetSimpleArguments() {
-
- try {
- bean.get(null);
- fail("Should throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException");
- }
-
- }
-
- /**
- * Test getSimpleProperty on a boolean property.
- */
- public void testGetSimpleBoolean() {
-
- try {
- final Object value = bean.get("booleanProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Boolean);
- assertTrue("Got correct value",
- (Boolean) value);
- } catch (final Throwable e) {
- fail("Exception: " + e);
- }
-
- }
-
- /**
- * Test getSimpleProperty on a double property.
- */
- public void testGetSimpleDouble() {
-
- try {
- final Object value = bean.get("doubleProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Double);
- assertEquals("Got correct value",
- ((Double) value).doubleValue(),
- 321.0, 0.005);
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- }
-
- /**
- * Test getSimpleProperty on a float property.
- */
- public void testGetSimpleFloat() {
-
- try {
- final Object value = bean.get("floatProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Float);
- assertEquals("Got correct value",
- ((Float) value).floatValue(),
- (float) 123.0,
- (float) 0.005);
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- }
-
- /**
- * Test getSimpleProperty on a int property.
- */
- public void testGetSimpleInt() {
-
- try {
- final Object value = bean.get("intProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Integer);
- assertEquals("Got correct value",
- ((Integer) value).intValue(),
- 123);
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- }
-
- /**
- * Test getSimpleProperty on a long property.
- */
- public void testGetSimpleLong() {
-
- try {
- final Object value = bean.get("longProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Long);
- assertEquals("Got correct value",
- ((Long) value).longValue(),
- 321);
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- }
-
- /**
- * Test getSimpleProperty on a short property.
- */
- public void testGetSimpleShort() {
-
- try {
- final Object value = bean.get("shortProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Short);
- assertEquals("Got correct value",
- ((Short) value).shortValue(),
- (short) 987);
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- }
-
- /**
- * Test getSimpleProperty on a String property.
- */
- public void testGetSimpleString() {
-
- try {
- final Object value = bean.get("stringProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof String);
- assertEquals("Got correct value",
- (String) value,
- "This is a string");
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- }
-
- /**
- * Test {@code contains()} method for mapped properties.
- */
- public void testMappedContains() {
-
- try {
- assertTrue("Can see first key",
- bean.contains("mappedProperty", "First Key"));
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- try {
- assertTrue("Can not see unknown key",
- !bean.contains("mappedProperty", "Unknown Key"));
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- }
-
- /**
- * Test {@code remove()} method for mapped properties.
- */
- public void testMappedRemove() {
-
- try {
- assertTrue("Can see first key",
- bean.contains("mappedProperty", "First Key"));
- bean.remove("mappedProperty", "First Key");
- assertTrue("Can not see first key",
- !bean.contains("mappedProperty", "First Key"));
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- try {
- assertTrue("Can not see unknown key",
- !bean.contains("mappedProperty", "Unknown Key"));
- bean.remove("mappedProperty", "Unknown Key");
- assertTrue("Can not see unknown key",
- !bean.contains("mappedProperty", "Unknown Key"));
- } catch (final Throwable t) {
- fail("Exception: " + t);
- }
-
- }
-
- /**
- * Test serialization and deserialization.
- */
- public void testSerialization() {
-
- // Serialize the test bean
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- final ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(bean);
- oos.flush();
- oos.close();
- } catch (final Exception e) {
- fail("Exception during serialization: " + e);
- }
-
- // Deserialize the test bean
- try {
- bean = null;
- final ByteArrayInputStream bais =
- new ByteArrayInputStream(baos.toByteArray());
- final ObjectInputStream ois = new ObjectInputStream(bais);
- bean = (DynaBean) ois.readObject();
- bais.close();
- } catch (final Exception e) {
- fail("Exception during deserialization: " + e);
- }
-
- // Confirm property values
- testGetDescriptorArguments();
- testGetDescriptorBoolean();
- testGetDescriptorDouble();
- testGetDescriptorFloat();
- testGetDescriptorInt();
- testGetDescriptorLong();
- testGetDescriptorSecond();
- testGetDescriptorShort();
- testGetDescriptorString();
- testGetDescriptors();
- testGetIndexedArguments();
- testGetIndexedValues();
- testGetMappedArguments();
- testGetMappedValues();
- testGetSimpleArguments();
- testGetSimpleBoolean();
- testGetSimpleDouble();
- testGetSimpleFloat();
- testGetSimpleInt();
- testGetSimpleLong();
- testGetSimpleShort();
- testGetSimpleString();
- testMappedContains();
- testMappedRemove();
-
- // Ensure that we can create a new instance of the same DynaClass
- try {
- bean = bean.getDynaClass().newInstance();
- } catch (final Exception e) {
- fail("Exception creating new instance: " + e);
- }
- testGetDescriptorArguments();
- testGetDescriptorBoolean();
- testGetDescriptorDouble();
- testGetDescriptorFloat();
- testGetDescriptorInt();
- testGetDescriptorLong();
- testGetDescriptorSecond();
- testGetDescriptorShort();
- testGetDescriptorString();
- testGetDescriptors();
-
- }
-
- /**
- * Corner cases on setIndexedProperty invalid arguments.
- */
- public void testSetIndexedArguments() {
-
- try {
- bean.set("intArray", -1, new Integer(0));
- fail("Should throw IndexOutOfBoundsException");
- } catch (final IndexOutOfBoundsException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IndexOutOfBoundsException");
- }
-
- }
-
- /**
- * Positive and negative tests on setIndexedProperty valid arguments.
- */
- public void testSetIndexedValues() {
-
- Object value = null;
-
- try {
- bean.set("intArray", 0, new Integer(1));
- value = bean.get("intArray", 0);
- assertNotNull("Returned new value 0", value);
- assertTrue("Returned Integer new value 0",
- value instanceof Integer);
- assertEquals("Returned correct new value 0", 1,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- bean.set("intIndexed", 1, new Integer(11));
- value = bean.get("intIndexed", 1);
- assertNotNull("Returned new value 1", value);
- assertTrue("Returned Integer new value 1",
- value instanceof Integer);
- assertEquals("Returned correct new value 1", 11,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- bean.set("listIndexed", 2, "New Value 2");
- value = bean.get("listIndexed", 2);
- assertNotNull("Returned new value 2", value);
- assertTrue("Returned String new value 2",
- value instanceof String);
- assertEquals("Returned correct new value 2", "New Value 2",
- (String) value);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- bean.set("stringArray", 3, "New Value 3");
- value = bean.get("stringArray", 3);
- assertNotNull("Returned new value 3", value);
- assertTrue("Returned String new value 3",
- value instanceof String);
- assertEquals("Returned correct new value 3", "New Value 3",
- (String) value);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- bean.set("stringIndexed", 4, "New Value 4");
- value = bean.get("stringIndexed", 4);
- assertNotNull("Returned new value 4", value);
- assertTrue("Returned String new value 4",
- value instanceof String);
- assertEquals("Returned correct new value 4", "New Value 4",
- (String) value);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- }
-
- /**
- * Positive and negative tests on setMappedProperty valid arguments.
- */
- public void testSetMappedValues() {
-
- try {
- bean.set("mappedProperty", "First Key", "New First Value");
- assertEquals("Can replace old value",
- "New First Value",
- (String) bean.get("mappedProperty", "First Key"));
- } catch (final Throwable t) {
- fail("Finding fourth value threw " + t);
- }
-
- try {
- bean.set("mappedProperty", "Fourth Key", "Fourth Value");
- assertEquals("Can set new value",
- "Fourth Value",
- (String) bean.get("mappedProperty", "Fourth Key"));
- } catch (final Throwable t) {
- fail("Finding fourth value threw " + t);
- }
-
- }
-
- /**
- * Test setSimpleProperty on a boolean property.
- */
- public void testSetSimpleBoolean() {
-
- try {
- final boolean oldValue =
- ((Boolean) bean.get("booleanProperty")).booleanValue();
- final boolean newValue = !oldValue;
- bean.set("booleanProperty", new Boolean(newValue));
- assertTrue("Matched new value",
- newValue ==
- ((Boolean) bean.get("booleanProperty")).booleanValue());
- } catch (final Throwable e) {
- fail("Exception: " + e);
- }
-
- }
-
- /**
- * Test setSimpleProperty on a double property.
- */
- public void testSetSimpleDouble() {
-
- try {
- final double oldValue =
- ((Double) bean.get("doubleProperty")).doubleValue();
- final double newValue = oldValue + 1.0;
- bean.set("doubleProperty", new Double(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Double) bean.get("doubleProperty")).doubleValue(),
- 0.005);
- } catch (final Throwable e) {
- fail("Exception: " + e);
- }
-
- }
-
- /**
- * Test setSimpleProperty on a float property.
- */
- public void testSetSimpleFloat() {
-
- try {
- final float oldValue =
- ((Float) bean.get("floatProperty")).floatValue();
- final float newValue = oldValue + (float) 1.0;
- bean.set("floatProperty", new Float(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Float) bean.get("floatProperty")).floatValue(),
- (float) 0.005);
- } catch (final Throwable e) {
- fail("Exception: " + e);
- }
-
- }
-
- /**
- * Test setSimpleProperty on a int property.
- */
- public void testSetSimpleInt() {
-
- try {
- final int oldValue =
- ((Integer) bean.get("intProperty")).intValue();
- final int newValue = oldValue + 1;
- bean.set("intProperty", new Integer(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Integer) bean.get("intProperty")).intValue());
- } catch (final Throwable e) {
- fail("Exception: " + e);
- }
-
- }
-
- /**
- * Test setSimpleProperty on a long property.
- */
- public void testSetSimpleLong() {
-
- try {
- final long oldValue =
- ((Long) bean.get("longProperty")).longValue();
- final long newValue = oldValue + 1;
- bean.set("longProperty", new Long(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Long) bean.get("longProperty")).longValue());
- } catch (final Throwable e) {
- fail("Exception: " + e);
- }
-
- }
-
- /**
- * Test setSimpleProperty on a short property.
- */
- public void testSetSimpleShort() {
-
- try {
- final short oldValue =
- ((Short) bean.get("shortProperty")).shortValue();
- final short newValue = (short) (oldValue + 1);
- bean.set("shortProperty", new Short(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Short) bean.get("shortProperty")).shortValue());
- } catch (final Throwable e) {
- fail("Exception: " + e);
- }
-
- }
-
- /**
- * Test setSimpleProperty on a String property.
- */
- public void testSetSimpleString() {
-
- try {
- final String oldValue = (String) bean.get("stringProperty");
- final String newValue = oldValue + " Extra Value";
- bean.set("stringProperty", newValue);
- assertEquals("Matched new value",
- newValue,
- (String) bean.get("stringProperty"));
- } catch (final Throwable e) {
- fail("Exception: " + e);
- }
-
- }
-
-
-
- /**
- * Create and return a {@code DynaClass} instance for our test
- * {@code DynaBean}.
- */
- protected DynaClass createDynaClass() {
-
- final int[] intArray = new int[0];
- final String[] stringArray = new String[0];
-
- final DynaClass dynaClass = new BasicDynaClass
- ("TestDynaClass", null,
- new DynaProperty[]{
- new DynaProperty("booleanProperty", Boolean.TYPE),
- new DynaProperty("booleanSecond", Boolean.TYPE),
- new DynaProperty("doubleProperty", Double.TYPE),
- new DynaProperty("floatProperty", Float.TYPE),
- new DynaProperty("intArray", intArray.getClass()),
- new DynaProperty("intIndexed", intArray.getClass()),
- new DynaProperty("intProperty", Integer.TYPE),
- new DynaProperty("listIndexed", List.class),
- new DynaProperty("longProperty", Long.TYPE),
- new DynaProperty("mappedProperty", Map.class),
- new DynaProperty("mappedIntProperty", Map.class),
- new DynaProperty("nullProperty", String.class),
- new DynaProperty("shortProperty", Short.TYPE),
- new DynaProperty("stringArray", stringArray.getClass()),
- new DynaProperty("stringIndexed", stringArray.getClass()),
- new DynaProperty("stringProperty", String.class),
- });
- return dynaClass;
-
- }
-
- /**
- * Base for testGetDescriptorXxxxx() series of tests.
- *
- * @param name Name of the property to be retrieved
- * @param type Expected class type of this property
- */
- protected void testGetDescriptorBase(final String name, final Class> type) {
-
- try {
- final DynaProperty descriptor =
- bean.getDynaClass().getDynaProperty(name);
- assertNotNull("Got descriptor", descriptor);
- assertEquals("Got correct type", type, descriptor.getType());
- } catch (final Throwable t) {
- fail("Threw an exception: " + t);
- }
-
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanComparatorTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanComparatorTestCase.java
deleted file mode 100644
index edf702d8d..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanComparatorTestCase.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-
-/**
- * Test Case for the BeanComparator class.
- */
-public class BeanComparatorTestCase extends TestCase {
-
-
-
- /**
- * The test beans for each test.
- */
- protected TestBean bean = null;
- protected AlphaBean alphaBean1 = null;
- protected AlphaBean alphaBean2 = null;
-
-
-
- /**
- * Constructs a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public BeanComparatorTestCase(final String name) {
- super(name);
- }
-
-
-
- /**
- * Sets up instance variables required by this test case.
- */
- @Override
- public void setUp() {
- bean = new TestBean();
- alphaBean1 = new AlphaBean("alphaBean1");
- alphaBean2 = new AlphaBean("alphaBean2");
- }
-
-
- /**
- * Returns the tests included in this test suite.
- */
- public static Test suite() {
- return new TestSuite(BeanComparatorTestCase.class);
- }
-
- /**
- * Tears down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- bean = null;
- alphaBean1 = null;
- alphaBean2 = null;
- }
-
-
-
- /**
- * Tests comparing two beans via their name using the default Comparator
- */
- public void testSimpleCompare() {
- final BeanComparator beanComparator = new BeanComparator<>(
- "name");
- final int result = beanComparator.compare(alphaBean1, alphaBean2);
- assertTrue("Comparator did not sort properly. Result:" + result,
- result == -1);
- }
-
- /**
- * Tests comparing two beans via their name using the default Comparator, but the inverse
- */
- public void testSimpleCompareInverse() {
- final BeanComparator beanComparator = new BeanComparator<>(
- "name");
- final int result = beanComparator.compare(alphaBean2, alphaBean1);
- assertTrue("Comparator did not sort properly. Result:" + result,
- result == 1);
- }
-
- /**
- * Tests comparing two beans via their name using the default Comparator where they have the same value.
- */
- public void testCompareIdentical() {
- alphaBean1 = new AlphaBean("alphabean");
- alphaBean2 = new AlphaBean("alphabean");
- final BeanComparator beanComparator = new BeanComparator<>(
- "name");
- final int result = beanComparator.compare(alphaBean1, alphaBean2);
- assertTrue("Comparator did not sort properly. Result:" + result,
- result == 0);
- }
-
- /**
- * Tests comparing one bean against itself.
- */
- public void testCompareBeanAgainstSelf() {
- final BeanComparator beanComparator = new BeanComparator<>(
- "name");
- final int result = beanComparator.compare(alphaBean1, alphaBean1);
- assertTrue("Comparator did not sort properly. Result:" + result,
- result == 0);
- }
-
- /**
- * Tests comparing two beans via their name using the default Comparator, but with one of the beans
- * being null.
- */
- public void testCompareWithNulls() {
- try {
- final BeanComparator beanComparator = new BeanComparator<>("name");
- beanComparator.compare(alphaBean2, null);
-
- fail("Should not be able to compare a null value.");
- }
- catch (final Exception e) {
- // expected result
- }
- }
-
- /**
- * Tests comparing two beans who don't have a property
- */
- public void testCompareOnMissingProperty() {
- try {
- final BeanComparator beanComparator = new BeanComparator<>("bogusName");
- beanComparator.compare(alphaBean2, alphaBean1);
- fail("should not be able to compare");
-
-
- }
- catch (final Exception e) {
- assertTrue("Wrong exception was thrown: " + e, e.toString().contains("Unknown property"));
- }
- }
-
- /**
- * Tests comparing two beans on a boolean property, which is not possible.
- */
- public void testCompareOnBooleanProperty() {
- try {
- final TestBean testBeanA = new TestBean();
- final TestBean testBeanB = new TestBean();
-
- testBeanA.setBooleanProperty(true);
- testBeanB.setBooleanProperty(false);
-
- final BeanComparator beanComparator = new BeanComparator<>("booleanProperty");
- beanComparator.compare(testBeanA, testBeanB);
-
- // **** java.lang.Boolean implements Comparable from JDK 1.5 onwards
- // so this test no longer fails
- // fail("BeanComparator should throw an exception when comparing two booleans.");
-
- }
- catch (final ClassCastException cce){
- // Expected result
- }
- }
-
- /**
- * Tests comparing two beans on a boolean property, then changing the property and testing/
- */
- public void testSetProperty() {
- final TestBean testBeanA = new TestBean();
- final TestBean testBeanB = new TestBean();
-
- testBeanA.setDoubleProperty(5.5);
- testBeanB.setDoubleProperty(1.0);
-
- final BeanComparator beanComparator = new BeanComparator<>(
- "doubleProperty");
- int result = beanComparator.compare(testBeanA, testBeanB);
-
- assertTrue("Comparator did not sort properly. Result:" + result,
- result == 1);
-
- testBeanA.setStringProperty("string 1");
- testBeanB.setStringProperty("string 2");
-
- beanComparator.setProperty("stringProperty");
-
- result = beanComparator.compare(testBeanA, testBeanB);
-
- assertTrue("Comparator did not sort properly. Result:" + result,
- result == -1);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanIntrospectionDataTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanIntrospectionDataTestCase.java
deleted file mode 100644
index e3746f54a..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanIntrospectionDataTestCase.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-/**
- * Test class for {@code BeanIntrospectionData}.
- *
- */
-public class BeanIntrospectionDataTestCase extends TestCase {
- /** Constant for the test bean class. */
- private static final Class> BEAN_CLASS = FluentIntrospectionTestBean.class;
-
- /** Constant for the name of the test property. */
- private static final String TEST_PROP = "fluentGetProperty";
-
- /**
- * Creates an array with property descriptors for the test bean class.
- *
- * @return the array with property descriptors
- */
- private static PropertyDescriptor[] fetchDescriptors() {
- final PropertyUtilsBean pub = new PropertyUtilsBean();
- pub.removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
- pub.addBeanIntrospector(new FluentPropertyBeanIntrospector());
- return pub.getPropertyDescriptors(BEAN_CLASS);
- }
-
- /**
- * Creates a test instance which is initialized with default property descriptors.
- *
- * @return the test instance
- */
- private static BeanIntrospectionData setUpData() {
- return new BeanIntrospectionData(fetchDescriptors());
- }
-
- /**
- * Returns the property descriptor for the test property.
- *
- * @param bid the data object
- * @return the test property descriptor
- */
- private static PropertyDescriptor fetchTestDescriptor(final BeanIntrospectionData bid) {
- return bid.getDescriptor(TEST_PROP);
- }
-
- /**
- * Tests whether a write method can be queried if it is defined in the descriptor.
- */
- public void testGetWriteMethodDefined() {
- final BeanIntrospectionData data = setUpData();
- final PropertyDescriptor pd = fetchTestDescriptor(data);
- assertNotNull("No write method", pd.getWriteMethod());
- assertEquals("Wrong write method", pd.getWriteMethod(),
- data.getWriteMethod(BEAN_CLASS, pd));
- }
-
- /**
- * Tests whether a write method can be queried that is currently not available in the
- * property descriptor.
- */
- public void testGetWriteMethodUndefined() throws Exception {
- final BeanIntrospectionData data = setUpData();
- final PropertyDescriptor pd = fetchTestDescriptor(data);
- final Method writeMethod = pd.getWriteMethod();
- pd.setWriteMethod(null);
- assertEquals("Wrong write method", writeMethod,
- data.getWriteMethod(BEAN_CLASS, pd));
- assertEquals("Method not set in descriptor", writeMethod, pd.getWriteMethod());
- }
-
- /**
- * Tests getWriteMethod() if the method cannot be resolved. (This is a corner case
- * which should normally not happen in practice.)
- */
- public void testGetWriteMethodNonExisting() throws Exception {
- final PropertyDescriptor pd = new PropertyDescriptor(TEST_PROP,
- BEAN_CLASS.getMethod("getFluentGetProperty"), BEAN_CLASS.getMethod(
- "setFluentGetProperty", String.class));
- final Map methods = new HashMap<>();
- methods.put(TEST_PROP, "hashCode");
- final BeanIntrospectionData data = new BeanIntrospectionData(
- new PropertyDescriptor[] { pd }, methods);
- pd.setWriteMethod(null);
- assertNull("Got a write method", data.getWriteMethod(BEAN_CLASS, pd));
- }
-
- /**
- * Tests getWriteMethod() for a property for which no write method is known.
- */
- public void testGetWriteMethodUnknown() {
- final BeanIntrospectionData data = setUpData();
- final PropertyDescriptor pd = data.getDescriptor("class");
- assertNull("Got a write method", data.getWriteMethod(BEAN_CLASS, pd));
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java
deleted file mode 100644
index 09e6af2ed..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanMapTestCase.java
+++ /dev/null
@@ -1,487 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Map;
-
-import org.apache.commons.beanutils2.bugs.other.Jira87BeanFactory;
-import org.apache.commons.collections.BulkTest;
-import org.apache.commons.collections.map.AbstractTestMap;
-
-import junit.framework.Test;
-import junit.textui.TestRunner;
-
-/**
- * Test cases for BeanMap
- *
- */
-@SuppressWarnings("deprecation")
-public class BeanMapTestCase extends AbstractTestMap {
-
- public BeanMapTestCase(final String testName) {
- super(testName);
- }
-
- public static void main(final String[] args) {
- TestRunner.run(suite());
- }
-
- public static Test suite() {
- return BulkTest.makeSuite(BeanMapTestCase.class);
- }
-
-/*
- note to self. The getter and setter methods were generated by copying the
- field declarations and using the following regular expression search and
- replace:
-
- From:
- private \(.*\) some\(.*\);
- To:
- public \1 getSome\2Value() {
- return some\2;
- }
- public void setSome\2Value(\1 value) {
- some\2 = value;
- }
-
- Also note: The sample keys and mappings were generated manually.
-*/
-
-
- public static class BeanWithProperties implements Serializable {
- private int someInt;
- private long someLong;
- private double someDouble;
- private float someFloat;
- private short someShort;
- private byte someByte;
- private char someChar;
- private Integer someInteger;
- private String someString;
- private Object someObject;
-
- public int getSomeIntValue() {
- return someInt;
- }
- public void setSomeIntValue(final int value) {
- someInt = value;
- }
-
- public long getSomeLongValue() {
- return someLong;
- }
- public void setSomeLongValue(final long value) {
- someLong = value;
- }
-
- public double getSomeDoubleValue() {
- return someDouble;
- }
- public void setSomeDoubleValue(final double value) {
- someDouble = value;
- }
-
- public float getSomeFloatValue() {
- return someFloat;
- }
- public void setSomeFloatValue(final float value) {
- someFloat = value;
- }
-
- public short getSomeShortValue() {
- return someShort;
- }
- public void setSomeShortValue(final short value) {
- someShort = value;
- }
-
- public byte getSomeByteValue() {
- return someByte;
- }
- public void setSomeByteValue(final byte value) {
- someByte = value;
- }
-
- public char getSomeCharValue() {
- return someChar;
- }
- public void setSomeCharValue(final char value) {
- someChar = value;
- }
-
- public String getSomeStringValue() {
- return someString;
- }
- public void setSomeStringValue(final String value) {
- someString = value;
- }
-
- public Integer getSomeIntegerValue() {
- return someInteger;
- }
- public void setSomeIntegerValue(final Integer value) {
- someInteger = value;
- }
-
- public Object getSomeObjectValue() {
- return someObject;
- }
- public void setSomeObjectValue(final Object value) {
- someObject = value;
- }
- }
-
- public static class BeanThrowingExceptions extends BeanWithProperties {
- private static final long serialVersionUID = 1L;
- public void setValueThrowingException(final String value) {
- throw new TestException();
- }
- public String getValueThrowingException() {
- throw new TestException();
- }
- }
-
- /**
- * Exception for testing exception handling.
- */
- public static class TestException extends RuntimeException {
- private static final long serialVersionUID = 1L;
- }
-
- // note to self. The Sample keys were generated by copying the field
- // declarations and using the following regular expression search and replace:
- //
- // From:
- // private \(.*\) some\(.*\);
- // To:
- // "some\2Value",
- //
- // Then, I manually added the "class" key, which is a property that exists for
- // all beans (and all objects for that matter.
- @Override
- public Object[] getSampleKeys() {
- final Object[] keys = new Object[] {
- "someIntValue",
- "someLongValue",
- "someDoubleValue",
- "someFloatValue",
- "someShortValue",
- "someByteValue",
- "someCharValue",
- "someIntegerValue",
- "someStringValue",
- "someObjectValue",
- "class",
- };
- return keys;
- }
-
- /**
- * An object value that will be stored in the bean map as a value. Need
- * to save this externally so that we can make sure the object instances
- * are equivalent since getSampleValues() would otherwise construct a new
- * and different Object each time.
- **/
- private final Object objectInFullMap = new Object();
-
- // note to self: the sample values were created manually
- @Override
- public Object[] getSampleValues() {
- final Object[] values = new Object[] {
- new Integer(1234),
- new Long(1298341928234L),
- new Double(123423.34),
- new Float(1213332.12f),
- new Short((short)134),
- new Byte((byte)10),
- new Character('a'),
- new Integer(1432),
- "SomeStringValue",
- objectInFullMap,
- BeanWithProperties.class,
- };
- return values;
- }
-
- @Override
- public Object[] getNewSampleValues() {
- final Object[] values = new Object[] {
- new Integer(223),
- new Long(23341928234L),
- new Double(23423.34),
- new Float(213332.12f),
- new Short((short)234),
- new Byte((byte)20),
- new Character('b'),
- new Integer(232),
- "SomeNewStringValue",
- new Object(),
- null,
- };
- return values;
- }
-
- /**
- * Values is a dead copy in BeanMap, so refresh each time.
- */
- @Override
- public void verifyValues() {
- values = map.values();
- super.verifyValues();
- }
-
- /**
- * The mappings in a BeanMap are fixed on the properties the underlying
- * bean has. Adding and removing mappings is not possible, thus this
- * method is overridden to return false.
- */
- @Override
- public boolean isPutAddSupported() {
- return false;
- }
-
- /**
- * The mappings in a BeanMap are fixed on the properties the underlying
- * bean has. Adding and removing mappings is not possible, thus this
- * method is overridden to return false.
- */
- @Override
- public boolean isRemoveSupported() {
- return false;
- }
-
- @Override
- public Map makeFullMap() {
- // note: These values must match (i.e. .equals() must return true)
- // those returned from getSampleValues().
- final BeanWithProperties bean = new BeanWithProperties();
- bean.setSomeIntValue(1234);
- bean.setSomeLongValue(1298341928234L);
- bean.setSomeDoubleValue(123423.34);
- bean.setSomeFloatValue(1213332.12f);
- bean.setSomeShortValue((short)134);
- bean.setSomeByteValue((byte)10);
- bean.setSomeCharValue('a');
- bean.setSomeIntegerValue(new Integer(1432));
- bean.setSomeStringValue("SomeStringValue");
- bean.setSomeObjectValue(objectInFullMap);
- return new BeanMap(bean);
- }
-
- @Override
- public Map makeEmptyMap() {
- return new BeanMap();
- }
-
- @Override
- public String[] ignoredTests() {
- // Ignore the serialization tests on collection views.
- return new String[] {
- "TestBeanMap.bulkTestMapEntrySet.testCanonicalEmptyCollectionExists",
- "TestBeanMap.bulkTestMapEntrySet.testCanonicalFullCollectionExists",
- "TestBeanMap.bulkTestMapKeySet.testCanonicalEmptyCollectionExists",
- "TestBeanMap.bulkTestMapKeySet.testCanonicalFullCollectionExists",
- "TestBeanMap.bulkTestMapValues.testCanonicalEmptyCollectionExists",
- "TestBeanMap.bulkTestMapValues.testCanonicalFullCollectionExists",
- "TestBeanMap.bulkTestMapEntrySet.testSimpleSerialization",
- "TestBeanMap.bulkTestMapKeySet.testSimpleSerialization",
- "TestBeanMap.bulkTestMapEntrySet.testSerializeDeserializeThenCompare",
- "TestBeanMap.bulkTestMapKeySet.testSerializeDeserializeThenCompare"
- };
- }
-
- /**
- * Need to override this method because the "clear()" method on the bean
- * map just returns the bean properties to their default states. It does
- * not actually remove the mappings as per the map contract. The default
- * testClear() methods checks that the clear method throws an
- * UnsupportedOperationException since this class is not add/remove
- * modifiable. In our case though, we do not always throw that exception.
- */
- @Override
- public void testMapClear() {
- //TODO: make sure a call to BeanMap.clear returns the bean to its
- //default initialization values.
- }
-
- /**
- * Need to override this method because the "put()" method on the bean
- * doesn't work for this type of Map.
- */
- @Override
- public void testMapPut() {
- // see testBeanMapPutAllWriteable
- }
-
- public void testBeanMapClone() {
- final BeanMap map = (BeanMap)makeFullMap();
- try {
- final BeanMap map2 = (BeanMap)map.clone();
-
- // make sure containsKey is working to verify the bean was cloned
- // ok, and the read methods were properly initialized
- final Object[] keys = getSampleKeys();
- for (final Object key : keys) {
- assertTrue("Cloned BeanMap should contain the same keys",
- map2.containsKey(key));
- }
- } catch (final CloneNotSupportedException exception) {
- fail("BeanMap.clone() should not throw a " +
- "CloneNotSupportedException when clone should succeed.");
- }
- }
-
- public void testBeanMapPutAllWriteable() {
- final BeanMap map1 = (BeanMap)makeFullMap();
- final BeanMap map2 = (BeanMap)makeFullMap();
- map2.put("someIntValue", new Integer(0));
- map1.putAllWriteable(map2);
- assertEquals(map1.get("someIntValue"), new Integer(0));
- }
-
- public void testMethodAccessor() throws Exception {
- final BeanMap map = (BeanMap) makeFullMap();
- final Method method = BeanWithProperties.class.getDeclaredMethod("getSomeIntegerValue");
- assertEquals(method, map.getReadMethod("someIntegerValue"));
- }
-
- public void testMethodMutator() throws Exception {
- final BeanMap map = (BeanMap) makeFullMap();
- final Method method = BeanWithProperties.class.getDeclaredMethod("setSomeIntegerValue", Integer.class);
- assertEquals(method, map.getWriteMethod("someIntegerValue"));
- }
-
- /**
- * Test the default transformers using the getTypeTransformer() method
- */
- public void testGetTypeTransformerMethod() {
- final BeanMap beanMap = new BeanMap();
- assertEquals("Boolean.TYPE", Boolean.TRUE, beanMap.getTypeTransformer(Boolean.TYPE).apply("true"));
- assertEquals("Character.TYPE", new Character('B'), beanMap.getTypeTransformer(Character.TYPE).apply("BCD"));
- assertEquals("Byte.TYPE", new Byte((byte)1), beanMap.getTypeTransformer(Byte.TYPE).apply("1"));
- assertEquals("Short.TYPE", new Short((short)2), beanMap.getTypeTransformer(Short.TYPE).apply("2"));
- assertEquals("Integer.TYPE", new Integer(3), beanMap.getTypeTransformer(Integer.TYPE).apply("3"));
- assertEquals("Long.TYPE", new Long(4), beanMap.getTypeTransformer(Long.TYPE).apply("4"));
- assertEquals("Float.TYPE", new Float("5"), beanMap.getTypeTransformer(Float.TYPE).apply("5"));
- assertEquals("Double.TYPE", new Double("6"), beanMap.getTypeTransformer(Double.TYPE).apply("6"));
- }
-
- /**
- * Test that the cause of exception thrown by a clone() is initialised.
- */
- public void testExceptionThrowFromClone() {
-
- if (BeanUtilsTestCase.isPre14JVM()) {
- System.out.println("testExceptionThrowFromClone() skipped on pre 1.4 JVM");
- return;
- }
-
- // Test cloning a non-public bean (instantiation exception)
- try {
- final Object bean = Jira87BeanFactory.createMappedPropertyBean();
- final BeanMap map = new BeanMap(bean);
- map.clone();
- fail("Non-public bean clone() - expected CloneNotSupportedException");
- } catch (final CloneNotSupportedException e) {
- Throwable cause = null;
- try {
- cause = (Throwable)PropertyUtils.getProperty(e, "cause");
- } catch (final Exception e2) {
- fail("Non-public bean - retrieving the cause threw " + e2);
- }
- assertNotNull("Non-public bean cause null", cause);
- assertEquals("Non-public bean cause", IllegalAccessException.class, cause.getClass());
- }
-
- // Test cloning a bean that throws exception
- try {
- final BeanMap map = new BeanMap(new BeanThrowingExceptions());
- map.clone();
- fail("Setter Exception clone() - expected CloneNotSupportedException");
- } catch (final CloneNotSupportedException e) {
- Throwable cause = null;
- try {
- cause = (Throwable)PropertyUtils.getProperty(e, "cause");
- } catch (final Exception e2) {
- fail("Setter Exception - retrieving the cause threw " + e2);
- }
- assertNotNull("Setter Exception cause null", cause);
- assertEquals("Setter Exception cause", IllegalArgumentException.class, cause.getClass());
- }
- }
-
- /**
- * Test that the cause of exception thrown by clear() is initialised.
- */
- public void testExceptionThrowFromClear() {
-
- if (BeanUtilsTestCase.isPre14JVM()) {
- System.out.println("testExceptionThrowFromClear() skipped on pre 1.4 JVM");
- return;
- }
-
- try {
- final Object bean = Jira87BeanFactory.createMappedPropertyBean();
- final BeanMap map = new BeanMap(bean);
- map.clear();
- fail("clear() - expected UnsupportedOperationException");
- } catch (final UnsupportedOperationException e) {
- Throwable cause = null;
- try {
- cause = (Throwable)PropertyUtils.getProperty(e, "cause");
- } catch (final Exception e2) {
- fail("Retrieving the cause threw " + e2);
- }
- assertNotNull("Cause null", cause);
- assertEquals("Cause", IllegalAccessException.class, cause.getClass());
- }
- }
-
- /**
- * Test that the cause of exception thrown by put() is initialized.
- */
- public void testExceptionThrowFromPut() {
-
- if (BeanUtilsTestCase.isPre14JVM()) {
- System.out.println("testExceptionThrowFromPut() skipped on pre 1.4 JVM");
- return;
- }
-
- try {
- final Map map = new BeanMap(new BeanThrowingExceptions());
- map.put("valueThrowingException", "value");
- fail("Setter exception - expected IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- Throwable cause1 = null;
- Throwable cause2 = null;
- try {
- cause1 = (Throwable)PropertyUtils.getProperty(e, "cause");
- cause2 = (Throwable)PropertyUtils.getProperty(e, "cause.cause");
- } catch (final Exception e2) {
- fail("Setter exception - retrieving the cause threw " + e2);
- }
- assertNotNull("Setter exception cause 1 null", cause1);
- assertEquals("Setter exception cause 1", InvocationTargetException.class, cause1.getClass());
- assertNotNull("Setter exception cause 2 null", cause2);
- assertEquals("Setter exception cause 2", TestException.class, cause2.getClass());
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanPredicateTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanPredicateTestCase.java
deleted file mode 100644
index f0fc201e2..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanPredicateTestCase.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.util.function.Predicate;
-
-import junit.framework.TestCase;
-
-/**
- * Unit test for {@link BeanPredicate}
- *
- */
-public class BeanPredicateTestCase extends TestCase {
-
- public BeanPredicateTestCase(final String name) {
- super(name);
- }
-
- public void testEqual() {
- final Predicate p = s -> s.equals("foo");
- final BeanPredicate predicate = new BeanPredicate<>("stringProperty", p);
- assertTrue(predicate.test(new TestBean("foo")));
- assertTrue(!predicate.test(new TestBean("bar")));
- }
-
- public void testNotEqual() {
- final Predicate p = s -> !s.equals("foo");
- final BeanPredicate predicate = new BeanPredicate<>("stringProperty", p);
- assertTrue(!predicate.test(new TestBean("foo")));
- assertTrue(predicate.test(new TestBean("bar")));
- }
-
- public void testInstanceOf() {
- final Predicate p = s -> (s instanceof String);
- final BeanPredicate predicate = new BeanPredicate<>("stringProperty", p);
- assertTrue(predicate.test(new TestBean("foo")));
- assertTrue(predicate.test(new TestBean("bar")));
- }
-
- public void testNull() {
- final Predicate p = s -> s == null;
- final BeanPredicate predicate = new BeanPredicate<>("stringProperty", p);
- final String nullString = null;
- assertTrue(predicate.test(new TestBean(nullString)));
- assertTrue(!predicate.test(new TestBean("bar")));
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumerTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumerTestCase.java
deleted file mode 100644
index 28d3944da..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumerTestCase.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import junit.framework.TestCase;
-
-
-/**
- * Test cases for {@code BeanPropertyValueChangeClosure}.
- *
- */
-public class BeanPropertyValueChangeConsumerTestCase extends TestCase {
-
- private static final Integer expectedIntegerValue = new Integer(123);
- private static final Float expectedFloatValue = new Float(123.123f);
- private static final Double expectedDoubleValue = new Double(567879.12344d);
- private static final Boolean expectedBooleanValue = Boolean.TRUE;
- private static final Byte expectedByteValue = new Byte("12");
-
- /**
- * Constructor for BeanPropertyValueChangeClosureTest.
- *
- * @param name Name of this test case.
- */
- public BeanPropertyValueChangeConsumerTestCase(final String name) {
- super(name);
- }
-
- /**
- * Test execute with simple float property and Float value.
- */
- public void testExecuteWithSimpleFloatPropertyAndFloatValue() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("floatProperty", expectedFloatValue).accept(testBean);
- assertTrue(expectedFloatValue.floatValue() == testBean.getFloatProperty());
- }
-
- /**
- * Test execute with simple float property and String value.
- */
- public void testExecuteWithSimpleFloatPropertyAndStringValue() {
- try {
- new BeanPropertyValueChangeConsumer<>("floatProperty", "123").accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with simple float property and Double value.
- */
- public void testExecuteWithSimpleFloatPropertyAndDoubleValue() {
- try {
- new BeanPropertyValueChangeConsumer<>("floatProperty", expectedDoubleValue).accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with simple float property and Integer value.
- */
- public void testExecuteWithSimpleFloatPropertyAndIntegerValue() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("floatProperty", expectedIntegerValue).accept(testBean);
- assertTrue(expectedIntegerValue.floatValue() == testBean.getFloatProperty());
- }
-
- /**
- * Test execute with simple double property and Double value.
- */
- public void testExecuteWithSimpleDoublePropertyAndDoubleValue() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("doubleProperty", expectedDoubleValue).accept(testBean);
- assertTrue(expectedDoubleValue.doubleValue() == testBean.getDoubleProperty());
- }
-
- /**
- * Test execute with simple double property and String value.
- */
- public void testExecuteWithSimpleDoublePropertyAndStringValue() {
- try {
- new BeanPropertyValueChangeConsumer<>("doubleProperty", "123").accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with simple double property and Float value.
- */
- public void testExecuteWithSimpleDoublePropertyAndFloatValue() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("doubleProperty", expectedFloatValue).accept(testBean);
- assertTrue(expectedFloatValue.doubleValue() == testBean.getDoubleProperty());
- }
-
- /**
- * Test execute with simple double property and Integer value.
- */
- public void testExecuteWithSimpleDoublePropertyAndIntegerValue() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("doubleProperty", expectedIntegerValue).accept(testBean);
- assertTrue(expectedIntegerValue.doubleValue() == testBean.getDoubleProperty());
- }
-
- /**
- * Test execute with simple int property and Double value.
- */
- public void testExecuteWithSimpleIntPropertyAndDoubleValue() {
- try {
- new BeanPropertyValueChangeConsumer<>("intProperty", expectedDoubleValue).accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with simple int property and String value.
- */
- public void testExecuteWithSimpleIntPropertyAndStringValue() {
- try {
- new BeanPropertyValueChangeConsumer<>("intProperty", "123").accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with simple int property and Float value.
- */
- public void testExecuteWithSimpleIntPropertyAndFloatValue() {
- try {
- new BeanPropertyValueChangeConsumer<>("intProperty", expectedFloatValue).accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with simple int property and Integer value.
- */
- public void testExecuteWithSimpleIntPropertyAndIntegerValue() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("intProperty", expectedIntegerValue).accept(testBean);
- assertTrue(expectedIntegerValue.intValue() == testBean.getIntProperty());
- }
-
- /**
- * Test execute with simple boolean property and Boolean value.
- */
- public void testExecuteWithSimpleBooleanPropertyAndBooleanValue() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("booleanProperty", expectedBooleanValue).accept(testBean);
- assertTrue(expectedBooleanValue.booleanValue() == testBean.getBooleanProperty());
- }
-
- /**
- * Test execute with simple boolean property and String value.
- */
- public void testExecuteWithSimpleBooleanPropertyAndStringValue() {
- try {
- new BeanPropertyValueChangeConsumer<>("booleanProperty", "true").accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with simple byte property and Byte value.
- */
- public void testExecuteWithSimpleBytePropertyAndByteValue() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("byteProperty", expectedByteValue).accept(testBean);
- assertTrue(expectedByteValue.byteValue() == testBean.getByteProperty());
- }
-
- /**
- * Test execute with simple boolean property and String value.
- */
- public void testExecuteWithSimpleBytePropertyAndStringValue() {
- try {
- new BeanPropertyValueChangeConsumer<>("byteProperty", "foo").accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with simple primitive property and null value.
- */
- public void testExecuteWithSimplePrimitivePropertyAndNullValue() {
- try {
- new BeanPropertyValueChangeConsumer<>("intProperty", null).accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with read only property.
- */
- public void testExecuteWithReadOnlyProperty() {
- try {
- new BeanPropertyValueChangeConsumer<>("readOnlyProperty", "foo").accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with write only property.
- */
- public void testExecuteWithWriteOnlyProperty() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("writeOnlyProperty", "foo").accept(testBean);
- assertEquals("foo", testBean.getWriteOnlyPropertyValue());
- }
-
- /**
- * Test execute with a nested property.
- */
- public void testExecuteWithNestedProperty() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("nested.stringProperty", "bar").accept(testBean);
- assertEquals("bar", testBean.getNested().getStringProperty());
- }
-
- /**
- * Test execute with a nested property and null in the property path.
- */
- public void testExecuteWithNullInPropertyPath() {
- try {
- new BeanPropertyValueChangeConsumer<>("anotherNested.stringProperty", "foo").accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-
- /**
- * Test execute with a nested property and null in the property path and ignoreNull = true.
- */
- public void testExecuteWithNullInPropertyPathAngIgnoreTrue() {
- final TestBean testBean = new TestBean();
-
- // create a consumer that will attempt to set a property on the null bean in the path
- final BeanPropertyValueChangeConsumer consumer = new BeanPropertyValueChangeConsumer<>(
- "anotherNested.stringProperty", "Should ignore exception", true);
-
- try {
- consumer.accept(testBean);
- } catch (final IllegalArgumentException e) {
- fail("Should have ignored the exception.");
- }
- }
-
- /**
- * Test execute with indexed property.
- */
- public void testExecuteWithIndexedProperty() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("intIndexed[0]", expectedIntegerValue).accept(testBean);
- assertTrue(expectedIntegerValue.intValue() == testBean.getIntIndexed(0));
- }
-
- /**
- * Test execute with mapped property.
- */
- public void testExecuteWithMappedProperty() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("mappedProperty(fred)", "barney").accept(testBean);
- assertEquals("barney", testBean.getMappedProperty("fred"));
- }
-
- /**
- * Test execute with a simple String property.
- */
- public void testExecuteWithSimpleStringProperty() {
- final TestBean testBean = new TestBean();
- new BeanPropertyValueChangeConsumer<>("stringProperty", "barney").accept(testBean);
- assertEquals("barney", testBean.getStringProperty());
- }
-
- /**
- * Test execute with an invalid property name.
- */
- public void testExecuteWithInvalidPropertyName() {
- try {
- new BeanPropertyValueChangeConsumer<>("bogusProperty", "foo").accept(new TestBean());
- fail("Should have thrown an IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* this is what we expect */
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicateTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicateTestCase.java
deleted file mode 100644
index a1ec59100..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicateTestCase.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import junit.framework.TestCase;
-
-/**
- * Test cases for {@code BeanPropertyValueEqualsPredicateTest}.
- *
- */
-public class BeanPropertyValueEqualsPredicateTestCase extends TestCase {
-
- private static final Integer expectedIntegerValue = new Integer(123);
- private static final Float expectedFloatValue = new Float(123.123f);
- private static final Double expectedDoubleValue = new Double(567879.12344d);
- private static final Boolean expectedBooleanValue = Boolean.TRUE;
- private static final Byte expectedByteValue = new Byte("12");
-
- /**
- * Constructor for BeanPropertyValueEqualsPredicateTest.
- *
- * @param name Name of this test case.
- */
- public BeanPropertyValueEqualsPredicateTestCase(final String name) {
- super(name);
- }
-
- /**
- * Test evaluate with simple String property.
- */
- public void testEvaluateWithSimpleStringProperty() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("stringProperty","foo");
- assertTrue(predicate.test(new TestBean("foo")));
- assertTrue(!predicate.test(new TestBean("bar")));
- }
-
- /**
- * Test evaluate with simple String property and null values.
- */
- public void testEvaluateWithSimpleStringPropertyWithNullValues() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("stringProperty",null);
- assertTrue(predicate.test(new TestBean((String) null)));
- assertTrue(!predicate.test(new TestBean("bar")));
- }
-
- /**
- * Test evaluate with nested property.
- */
- public void testEvaluateWithNestedProperty() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("anotherNested.stringProperty","match");
- final TestBean testBean = new TestBean();
- final TestBean nestedBean = new TestBean("match");
- testBean.setAnotherNested(nestedBean);
- assertTrue(predicate.test(testBean));
- testBean.setAnotherNested(new TestBean("no-match"));
- assertTrue(!predicate.test(testBean));
- }
-
- /**
- * Test evaluate with null in property path and ignore=false.
- */
- public void testEvaluateWithNullInPath() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("anotherNested.stringProperty","foo");
- try {
- // try to evaluate the predicate
- predicate.test(new TestBean());
- fail("Should have throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* ignore this is what should happen */
- }
- }
-
- /**
- * Test evaluate with null in property path and ignore=true.
- */
- public void testEvaluateWithNullInPathAndIgnoreTrue() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("anotherNested.stringProperty","foo", true);
- try {
- assertTrue(!predicate.test(new TestBean()));
- } catch (final IllegalArgumentException e) {
- fail("Should not have throw IllegalArgumentException");
- }
- }
-
- /**
- * Test evaluate with int property.
- */
- public void testEvaluateWithIntProperty() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("intProperty",expectedIntegerValue);
- assertTrue(predicate.test(new TestBean(expectedIntegerValue.intValue())));
- assertTrue(!predicate.test(new TestBean(expectedIntegerValue.intValue() - 1)));
- }
-
- /**
- * Test evaluate with float property.
- */
- public void testEvaluateWithFloatProperty() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("floatProperty",expectedFloatValue);
- assertTrue(predicate.test(new TestBean(expectedFloatValue.floatValue())));
- assertTrue(!predicate.test(new TestBean(expectedFloatValue.floatValue() - 1)));
- }
-
- /**
- * Test evaluate with double property.
- */
- public void testEvaluateWithDoubleProperty() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("doubleProperty",expectedDoubleValue);
- assertTrue(predicate.test(new TestBean(expectedDoubleValue.doubleValue())));
- assertTrue(!predicate.test(new TestBean(expectedDoubleValue.doubleValue() - 1)));
- }
-
- /**
- * Test evaluate with boolean property.
- */
- public void testEvaluateWithBooleanProperty() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("booleanProperty",expectedBooleanValue);
- assertTrue(predicate.test(new TestBean(expectedBooleanValue.booleanValue())));
- assertTrue(!predicate.test(new TestBean(!expectedBooleanValue.booleanValue())));
- }
-
- /**
- * Test evaluate with byte property.
- */
- public void testEvaluateWithByteProperty() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("byteProperty",expectedByteValue);
- final TestBean testBean = new TestBean();
- testBean.setByteProperty(expectedByteValue.byteValue());
- assertTrue(predicate.test(testBean));
- testBean.setByteProperty((byte) (expectedByteValue.byteValue() - 1));
- assertTrue(!predicate.test(testBean));
- }
-
- /**
- * Test evaluate with mapped property.
- */
- public void testEvaluateWithMappedProperty() {
- // try a key that is in the map
- BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("mappedProperty(test-key)", "match");
- final TestBean testBean = new TestBean();
- testBean.setMappedProperty("test-key", "match");
- assertTrue(predicate.test(testBean));
- testBean.setMappedProperty("test-key", "no-match");
- assertTrue(!predicate.test(testBean));
-
- // try a key that isn't in the map
- predicate = new BeanPropertyValueEqualsPredicate<>("mappedProperty(invalid-key)", "match");
- assertTrue(!predicate.test(testBean));
- }
-
- /**
- * Test evaluate with indexed property.
- */
- public void testEvaluateWithIndexedProperty() {
- // try a valid index
- BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("intIndexed[0]",expectedIntegerValue);
- final TestBean testBean = new TestBean();
- testBean.setIntIndexed(0, expectedIntegerValue.intValue());
- assertTrue(predicate.test(testBean));
- testBean.setIntIndexed(0, expectedIntegerValue.intValue() - 1);
- assertTrue(!predicate.test(testBean));
-
- // try an invalid index
- predicate = new BeanPropertyValueEqualsPredicate<>("intIndexed[999]", "exception-ahead");
-
- try {
- assertTrue(!predicate.test(testBean));
- } catch (final ArrayIndexOutOfBoundsException e) {
- /* this is what should happen */
- }
- }
-
- /**
- * Test evaluate with primitive property and null value.
- */
- public void testEvaluateWithPrimitiveAndNull() {
- BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("intProperty",null);
- assertTrue(!predicate.test(new TestBean(0)));
-
- predicate = new BeanPropertyValueEqualsPredicate<>("booleanProperty", null);
- assertTrue(!predicate.test(new TestBean(true)));
-
- predicate = new BeanPropertyValueEqualsPredicate<>("floatProperty", null);
- assertTrue(!predicate.test(new TestBean(expectedFloatValue.floatValue())));
- }
-
- /**
- * Test evaluate with nested mapped property.
- */
- public void testEvaluateWithNestedMappedProperty() {
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("anotherNested.mappedProperty(test-key)","match");
- final TestBean testBean = new TestBean();
- final TestBean nestedBean = new TestBean();
- nestedBean.setMappedProperty("test-key", "match");
- testBean.setAnotherNested(nestedBean);
- assertTrue(predicate.test(testBean));
- nestedBean.setMappedProperty("test-key", "no-match");
- assertTrue(!predicate.test(testBean));
- }
-
- /**
- * Test evaluate with write only property.
- */
- public void testEvaluateWithWriteOnlyProperty() {
- try {
- new BeanPropertyValueEqualsPredicate("writeOnlyProperty", null).test(new TestBean());
- } catch (final IllegalArgumentException e) {
- /* This is what should happen */
- }
- }
-
- /**
- * Test evaluate with read only property.
- */
- public void testEvaluateWithReadOnlyProperty() {
- final TestBean testBean = new TestBean();
- final BeanPropertyValueEqualsPredicate predicate =
- new BeanPropertyValueEqualsPredicate<>("readOnlyProperty",testBean.getReadOnlyProperty());
- assertTrue(predicate.test(new TestBean()));
- }
-
- /**
- * Test evaluate with an invalid property name.
- */
- public void testEvaluateWithInvalidPropertyName() {
- try {
- new BeanPropertyValueEqualsPredicate("bogusProperty", null).test(new TestBean());
- } catch (final IllegalArgumentException e) {
- /* This is what should happen */
- }
- }
-}
\ No newline at end of file
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformerTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformerTestCase.java
deleted file mode 100644
index bedcf9f19..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformerTestCase.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import junit.framework.TestCase;
-
-
-/**
- * Test cases for {@code BeanToPropertyValueTransformer}.
- *
- */
-public class BeanToPropertyValueTransformerTestCase extends TestCase {
-
- private static final Integer expectedIntegerValue = new Integer(123);
- private static final Long expectedLongValue = new Long(123);
- private static final Float expectedFloatValue = new Float(123.123f);
- private static final Double expectedDoubleValue = new Double(567879.12344d);
- private static final Boolean expectedBooleanValue = Boolean.TRUE;
- private static final Byte expectedByteValue = new Byte("12");
-
- /**
- * Constructor for BeanToPropertyValueTransformerTestCase.
- *
- * @param name Name of this test case.
- */
- public BeanToPropertyValueTransformerTestCase(final String name) {
- super(name);
- }
-
- /**
- * Test transform with simple String property.
- */
- public void testTransformWithSimpleStringProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("stringProperty");
- final TestBean testBean = new TestBean("foo");
- assertEquals("foo", transformer.apply(testBean));
- }
-
- /**
- * Test transform with simple String property and null value.
- *
- */
- public void testTransformWithSimpleStringPropertyAndNullValue() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("stringProperty");
- final TestBean testBean = new TestBean((String) null);
- assertNull(transformer.apply(testBean));
- }
-
- /**
- * Test transform with simple int property.
- */
- public void testTransformWithSimpleIntProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("intProperty");
- final TestBean testBean = new TestBean(expectedIntegerValue.intValue());
- assertEquals(expectedIntegerValue, transformer.apply(testBean));
- }
-
- /**
- * Test transform with simple long property.
- */
- public void testTransformWithSimpleLongProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("longProperty");
- final TestBean testBean = new TestBean();
- testBean.setLongProperty(expectedLongValue.longValue());
- assertEquals(expectedLongValue, transformer.apply(testBean));
- }
-
- /**
- * Test transform with simple float property.
- */
- public void testTransformWithSimpleFloatProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("floatProperty");
- final TestBean testBean = new TestBean(expectedFloatValue.floatValue());
- assertEquals(expectedFloatValue, transformer.apply(testBean));
- }
-
- /**
- * Test transform with simple double property.
- */
- public void testTransformWithSimpleDoubleProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("doubleProperty");
- final TestBean testBean = new TestBean(expectedDoubleValue.doubleValue());
- assertEquals(expectedDoubleValue, transformer.apply(testBean));
- }
-
- /**
- * Test transform with simple byte property.
- */
- public void testTransformWithSimpleByteProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("byteProperty");
- final TestBean testBean = new TestBean();
- testBean.setByteProperty(expectedByteValue.byteValue());
- assertEquals(expectedByteValue, transformer.apply(testBean));
- }
-
- /**
- * Test transform with simple boolean property.
- */
- public void testTransformWithSimpleBooleanProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("booleanProperty");
- final TestBean testBean = new TestBean(expectedBooleanValue.booleanValue());
- assertEquals(expectedBooleanValue, transformer.apply(testBean));
- }
-
- /**
- * Test transform with write only property.
- */
- public void testTransformWithWriteOnlyProperty() {
- try {
- new BeanToPropertyValueTransformer<>("writeOnlyProperty").apply(new TestBean());
- } catch (final IllegalArgumentException e) {
- /* This is what should happen */
- }
- }
-
- /**
- * Test transform with read only property.
- */
- public void testTransformWithReadOnlyProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("readOnlyProperty");
- final TestBean testBean = new TestBean();
- assertEquals(testBean.getReadOnlyProperty(), transformer.apply(testBean));
- }
-
- /**
- * Test transform with invalid property.
- */
- public void testTransformWithInvalidProperty() {
- try {
- new BeanToPropertyValueTransformer<>("bogusProperty").apply(new TestBean());
- } catch (final IllegalArgumentException e) {
- /* This is what should happen */
- }
- }
-
- /**
- * Test transform with nested property.
- */
- public void testTransformWithNestedProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("anotherNested.stringProperty");
- final TestBean testBean = new TestBean();
- final TestBean nestedBean = new TestBean("foo");
- testBean.setAnotherNested(nestedBean);
- assertEquals("foo", transformer.apply(testBean));
- }
-
- /**
- * Test transform with mapped property.
- */
- public void testTransformWithMappedProperty() {
- BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("mappedProperty(test-key)");
- final TestBean testBean = new TestBean();
-
- // try a valid key
- testBean.setMappedProperty("test-key", "test-value");
- assertEquals("test-value", transformer.apply(testBean));
-
- // now try an invalid key
- transformer = new BeanToPropertyValueTransformer<>("mappedProperty(bogus-key)");
- assertEquals(null, transformer.apply(testBean));
- }
-
- /**
- * Test transform with indexed property.
- */
- public void testTransformWithIndexedProperty() {
- BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("intIndexed[0]");
- final TestBean testBean = new TestBean();
- testBean.setIntIndexed(0, expectedIntegerValue.intValue());
- assertEquals(expectedIntegerValue, transformer.apply(testBean));
-
- // test index out of range
- transformer = new BeanToPropertyValueTransformer<>("intIndexed[9999]");
-
- try {
- transformer.apply(testBean);
- fail("Should have thrown an ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException e) {
- /* this is what should happen */
- }
- }
-
- /**
- * Test transform with nested indexed property.
- */
- public void testTransformWithNestedIndexedProperty() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("anotherNested.intIndexed[0]");
- final TestBean testBean = new TestBean();
- final TestBean nestedBean = new TestBean();
- nestedBean.setIntIndexed(0, expectedIntegerValue.intValue());
- testBean.setAnotherNested(nestedBean);
- assertEquals(expectedIntegerValue, transformer.apply(testBean));
- }
-
- /**
- * Test transform with null in property path.
- */
- public void testTransformWithNullInPath() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("anotherNested.stringProperty");
-
- try {
- transformer.apply(new TestBean());
- fail("Should have throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- /* ignore this is what should happen */
- }
- }
-
- /**
- * Test transform with null in property path and ignore = true.
- */
- public void testTransformWithNullInPathAndIgnoreTrue() {
- final BeanToPropertyValueTransformer transformer =
- new BeanToPropertyValueTransformer<>("anotherNested.stringProperty",true);
- assertEquals(null, transformer.apply(new TestBean()));
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanUtils2TestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanUtils2TestCase.java
deleted file mode 100644
index 2187c2db0..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanUtils2TestCase.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test Case for the {@link BeanUtilsBean2}.
- *
- */
-public class BeanUtils2TestCase extends BeanUtilsTestCase {
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public BeanUtils2TestCase(final String name) {
- super(name);
- }
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() {
- ConvertUtils.deregister();
- BeanUtilsBean.setInstance(new BeanUtilsBean2());
- setUpShared();
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
- return new TestSuite(BeanUtils2TestCase.class);
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- bean = null;
- }
-
- /**
- * Test {@code copyProperty()} converting to a String.
- */
- @Override
- public void testCopyPropertyConvertToString() {
- try {
- BeanUtils.copyProperty(bean, "stringProperty", testUtilDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date --> String", testStringDate, bean.getStringProperty());
- }
-
- /**
- * Test {@code copyProperty()} converting to a String.
- */
- @Override
- public void testCopyPropertyConvertToStringArray() {
- try {
- bean.setStringArray(null);
- BeanUtils.copyProperty(bean, "stringArray", new java.util.Date[] {testUtilDate});
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length);
- assertEquals("java.util.Date[] --> String[] value ", testStringDate, bean.getStringArray()[0]);
- }
-
- /**
- * Test {@code copyProperty()} converting to a String on indexed property
- */
- @Override
- public void testCopyPropertyConvertToStringIndexed() {
- try {
- bean.setStringArray(new String[1]);
- BeanUtils.copyProperty(bean, "stringArray[0]", testUtilDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length);
- assertEquals("java.util.Date[] --> String[] value ", testStringDate, bean.getStringArray()[0]);
- }
-
- /**
- * Test {@code getArrayProperty()} converting to a String.
- */
- @Override
- public void testGetArrayPropertyDate() {
- String[] value = null;
- try {
- bean.setDateArrayProperty(new java.util.Date[] {testUtilDate});
- value = BeanUtils.getArrayProperty(bean, "dateArrayProperty");
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date[] --> String[] length", 1, value.length);
- assertEquals("java.util.Date[] --> String[] value ", testStringDate, value[0]);
- }
-
- /**
- * Test {@code getArrayProperty()} converting to a String.
- */
- @Override
- public void testGetIndexedPropertyDate() {
- String value = null;
- try {
- bean.setDateArrayProperty(new java.util.Date[] {testUtilDate});
- value = BeanUtils.getIndexedProperty(bean, "dateArrayProperty[0]");
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date[0] --> String", testStringDate, value);
- }
-
- /**
- * Test {@code getSimpleProperty()} converting to a String.
- */
- @Override
- public void testGetSimplePropertyDate() {
- String value = null;
- try {
- bean.setDateProperty(testUtilDate);
- value = BeanUtils.getSimpleProperty(bean, "dateProperty");
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date --> String", testStringDate, value);
- }
-
- /**
- * Test {@code setProperty()} converting to a String.
- */
- @Override
- public void testSetPropertyConvertToString() {
- try {
- BeanUtils.setProperty(bean, "stringProperty", testUtilDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date --> String", testStringDate, bean.getStringProperty());
- }
-
- /**
- * Test {@code setProperty()} converting to a String array.
- */
- @Override
- public void testSetPropertyConvertToStringArray() {
- try {
- bean.setStringArray(null);
- BeanUtils.setProperty(bean, "stringArray", new java.util.Date[] {testUtilDate});
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length);
- assertEquals("java.util.Date[] --> String[] value ", testStringDate, bean.getStringArray()[0]);
- }
-
- /**
- * Test {@code setProperty()} converting to a String on indexed property
- */
- @Override
- public void testSetPropertyConvertToStringIndexed() {
- try {
- bean.setStringArray(new String[1]);
- BeanUtils.setProperty(bean, "stringArray[0]", testUtilDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date --> String[]", testStringDate, bean.getStringArray()[0]);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanUtilsBenchCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanUtilsBenchCase.java
deleted file mode 100644
index cd76d0f54..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanUtilsBenchCase.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * JUnit Test Case containing microbenchmarks for BeanUtils.
- *
- */
-
-public class BeanUtilsBenchCase extends TestCase {
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public BeanUtilsBenchCase(final String name) {
-
- super(name);
-
- }
-
-
-
- // Basic loop counter
- private long counter = 100000;
-
- // DynaClass for inDyna and outDyna
- private DynaClass dynaClass = null;
-
- // Input objects that have identical sets of properties and values.
- private BenchBean inBean = null;
- private DynaBean inDyna = null;
- private Map inMap = null; // Map of Objects requiring no conversion
- private Map inStrs = null; // Map of Strings requiring conversion
-
- // Output objects that have identical sets of properties.
- private BenchBean outBean = null;
- private DynaBean outDyna = null;
-
- // BeanUtilsBean instance to be used
- private BeanUtilsBean bu = null;
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
-
- // Set up loop counter (if property specified)
- final String prop = System.getProperty("counter");
- if (prop != null) {
- counter = Long.parseLong(prop);
- }
-
- // Set up DynaClass for our DynaBean instances
- dynaClass = new BasicDynaClass
- ("BenchDynaClass", null,
- new DynaProperty[]{
- new DynaProperty("booleanProperty", Boolean.TYPE),
- new DynaProperty("byteProperty", Byte.TYPE),
- new DynaProperty("doubleProperty", Double.TYPE),
- new DynaProperty("floatProperty", Float.TYPE),
- new DynaProperty("intProperty", Integer.TYPE),
- new DynaProperty("longProperty", Long.TYPE),
- new DynaProperty("shortProperty", Short.TYPE),
- new DynaProperty("stringProperty", String.class),
- });
-
- // Create input instances
- inBean = new BenchBean();
- inMap = new HashMap<>();
- inMap.put("booleanProperty", new Boolean(inBean.getBooleanProperty()));
- inMap.put("byteProperty", new Byte(inBean.getByteProperty()));
- inMap.put("doubleProperty", new Double(inBean.getDoubleProperty()));
- inMap.put("floatProperty", new Float(inBean.getFloatProperty()));
- inMap.put("intProperty", new Integer(inBean.getIntProperty()));
- inMap.put("longProperty", new Long(inBean.getLongProperty()));
- inMap.put("shortProperty", new Short(inBean.getShortProperty()));
- inMap.put("stringProperty", inBean.getStringProperty());
- inDyna = dynaClass.newInstance();
- Iterator inKeys = inMap.keySet().iterator();
- while (inKeys.hasNext()) {
- final String inKey = inKeys.next();
- inDyna.set(inKey, inMap.get(inKey));
- }
- inStrs = new HashMap<>();
- inKeys = inMap.keySet().iterator();
- while (inKeys.hasNext()) {
- final String inKey = inKeys.next();
- inStrs.put(inKey, inMap.get(inKey).toString());
- }
-
- // Create output instances
- outBean = new BenchBean();
- outDyna = dynaClass.newInstance();
- final Iterator outKeys = inMap.keySet().iterator();
- while (outKeys.hasNext()) {
- final String outKey = outKeys.next();
- outDyna.set(outKey, inMap.get(outKey));
- }
-
- // Set up BeanUtilsBean instance we will use
- bu = BeanUtilsBean.getInstance();
-
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
-
- return new TestSuite(BeanUtilsBenchCase.class);
-
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
-
- dynaClass = null;
- inBean = null;
- inDyna = null;
- inMap = null;
- outBean = null;
- outDyna = null;
- bu = null;
-
- }
-
-
-
- // Time copyProperties() from a bean
- public void testCopyPropertiesBean() throws Exception {
-
- long start;
- long stop;
-
- // Bean->Bean
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outBean, inBean);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outBean, inBean);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.copyProperties(bean,bean), count=" + counter +
- ", time=" + (stop - start));
-
- // Bean->Dyna
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outDyna, inBean);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outDyna, inBean);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.copyProperties(dyna,bean), count=" + counter +
- ", time=" + (stop - start));
-
- }
-
- // Time copyProperties() from a DynaBean
- public void testCopyPropertiesDyna() throws Exception {
-
- long start;
- long stop;
-
- // Dyna->Bean
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outBean, inDyna);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outBean, inDyna);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.copyProperties(bean,dyna), count=" + counter +
- ", time=" + (stop - start));
-
- // Dyna->Dyna
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outDyna, inDyna);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outDyna, inDyna);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.copyProperties(dyna,dyna), count=" + counter +
- ", time=" + (stop - start));
-
- }
-
- // Time copyProperties() from a Map of Objects
- public void testCopyPropertiesMap() throws Exception {
-
- long start;
- long stop;
-
- // Map->Bean
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outBean, inMap);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outBean, inMap);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.copyProperties(bean, map), count=" + counter +
- ", time=" + (stop - start));
-
- // Map->Dyna
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outDyna, inMap);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outDyna, inMap);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.copyProperties(dyna, map), count=" + counter +
- ", time=" + (stop - start));
-
- }
-
- // Time copyProperties() from a Map of Strings
- public void testCopyPropertiesStrs() throws Exception {
-
- long start;
- long stop;
-
- // Strs->Bean
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outBean, inStrs);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outBean, inStrs);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.copyProperties(bean,strs), count=" + counter +
- ", time=" + (stop - start));
-
- // Strs->Dyna
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outDyna, inStrs);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.copyProperties(outDyna, inStrs);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.copyProperties(dyna,strs), count=" + counter +
- ", time=" + (stop - start));
-
- }
-
- // Time populate() from a Map of Objects
- public void testPopulateMap() throws Exception {
-
- long start;
- long stop;
-
- // Map->Bean
- for (long i = 0; i < counter; i++) {
- bu.populate(outBean, inMap);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.populate(outBean, inMap);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.populate(bean, map), count=" + counter +
- ", time=" + (stop - start));
-
- // Map->Dyna
- for (long i = 0; i < counter; i++) {
- bu.populate(outDyna, inMap);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.populate(outDyna, inMap);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.populate(dyna, map), count=" + counter +
- ", time=" + (stop - start));
-
- }
-
- // Time populate() from a Map of Strings
- // NOTE - This simulates what Struts does when processing form beans
- public void testPopulateStrs() throws Exception {
-
- long start;
- long stop;
-
- // Strs->Bean
- for (long i = 0; i < counter; i++) {
- bu.populate(outBean, inStrs);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.populate(outBean, inStrs);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.populate(bean,strs), count=" + counter +
- ", time=" + (stop - start));
-
- // Strs->Dyna
- for (long i = 0; i < counter; i++) {
- bu.populate(outDyna, inStrs);
- }
- start = System.currentTimeMillis();
- for (long i = 0; i < counter; i++) {
- bu.populate(outDyna, inStrs);
- }
- stop = System.currentTimeMillis();
- System.err.println("BU.populate(dyna,strs), count=" + counter +
- ", time=" + (stop - start));
-
- }
-
-
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanUtilsTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanUtilsTestCase.java
deleted file mode 100644
index 8513ea8fb..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanUtilsTestCase.java
+++ /dev/null
@@ -1,1625 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import org.apache.commons.beanutils2.converters.ArrayConverter;
-import org.apache.commons.beanutils2.converters.DateConverter;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
- * Test Case for the BeanUtils class. The majority of these tests use
- * instances of the TestBean class, so be sure to update the tests if you
- * change the characteristics of that class.
- *
- *
- *
- * Template for this stolen from Craigs PropertyUtilsTestCase
- *
- *
- *
- * Note that the tests are dependant upon the static aspects
- * (such as array sizes...) of the TestBean.java class, so ensure
- * than all changes to TestBean are reflected here.
- *
- *
- *
- * So far, this test case has tests for the following methods of the
- * {@code BeanUtils} class:
- *
- *
- *
getArrayProperty(Object bean, String name)
- *
- *
- */
-
-public class BeanUtilsTestCase extends TestCase {
-
-
-
- /**
- * The test bean for each test.
- */
- protected TestBean bean = null;
-
- /**
- * The set of properties that should be described.
- */
- protected String[] describes =
- { "booleanProperty",
- "booleanSecond",
- "byteProperty",
- "doubleProperty",
- "dupProperty",
- "floatProperty",
- "intArray",
- // "intIndexed",
- "longProperty",
- "listIndexed",
- "longProperty",
- // "mappedProperty",
- // "mappedIntProperty",
- "nested",
- "nullProperty",
- "readOnlyProperty",
- "shortProperty",
- "stringArray",
- // "stringIndexed",
- "stringProperty"
- };
-
- /** Test Calendar value */
- protected java.util.Calendar testCalendar;
-
- /** Test java.util.Date value */
- protected java.util.Date testUtilDate;
-
- /** Test String Date value */
- protected String testStringDate;
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public BeanUtilsTestCase(final String name) {
- super(name);
- }
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() {
- ConvertUtils.deregister();
- BeanUtilsBean.setInstance(new BeanUtilsBean());
- setUpShared();
- }
-
- /**
- * Shared Set up.
- */
- protected void setUpShared() {
- bean = new TestBean();
-
- final DateConverter dateConverter = new DateConverter(null);
- dateConverter.setLocale(Locale.US);
- dateConverter.setPattern("dd.MM.yyyy");
- ConvertUtils.register(dateConverter, java.util.Date.class);
-
- final ArrayConverter dateArrayConverter =
- new ArrayConverter(java.util.Date[].class, dateConverter, 0);
- ConvertUtils.register(dateArrayConverter, java.util.Date[].class);
-
- testCalendar = Calendar.getInstance();
- testCalendar.set(1992, 11, 28, 0, 0, 0);
- testCalendar.set(Calendar.MILLISECOND, 0);
- testUtilDate = testCalendar.getTime();
- testStringDate = "28.12.1992";
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
- return new TestSuite(BeanUtilsTestCase.class);
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- bean = null;
- }
-
-
-
- /**
- * Test the copyProperties() method from a DynaBean.
- */
- public void testCopyPropertiesDynaBean() {
-
- // Set up an origin bean with customized properties
- final DynaClass dynaClass = DynaBeanUtilsTestCase.createDynaClass();
- DynaBean orig = null;
- try {
- orig = dynaClass.newInstance();
- } catch (final Exception e) {
- fail("newInstance(): " + e);
- }
- orig.set("booleanProperty", Boolean.FALSE);
- orig.set("byteProperty", new Byte((byte) 111));
- orig.set("doubleProperty", new Double(333.33));
- orig.set("dupProperty",
- new String[] { "New 0", "New 1", "New 2" });
- orig.set("intArray", new int[] { 100, 200, 300 });
- orig.set("intProperty", new Integer(333));
- orig.set("longProperty", new Long(3333));
- orig.set("shortProperty", new Short((short) 33));
- orig.set("stringArray", new String[] { "New 0", "New 1" });
- orig.set("stringProperty", "Custom string");
-
- // Copy the origin bean to our destination test bean
- try {
- BeanUtils.copyProperties(bean, orig);
- } catch (final Exception e) {
- fail("Threw exception: " + e);
- }
-
- // Validate the results for scalar properties
- assertEquals("Copied boolean property",
- false,
- bean.getBooleanProperty());
- assertEquals("Copied byte property",
- (byte) 111,
- bean.getByteProperty());
- assertEquals("Copied double property",
- 333.33,
- bean.getDoubleProperty(),
- 0.005);
- assertEquals("Copied int property",
- 333,
- bean.getIntProperty());
- assertEquals("Copied long property",
- 3333,
- bean.getLongProperty());
- assertEquals("Copied short property",
- (short) 33,
- bean.getShortProperty());
- assertEquals("Copied string property",
- "Custom string",
- bean.getStringProperty());
-
- // Validate the results for array properties
- final String[] dupProperty = bean.getDupProperty();
- assertNotNull("dupProperty present", dupProperty);
- assertEquals("dupProperty length", 3, dupProperty.length);
- assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
- assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
- assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
- final int[] intArray = bean.getIntArray();
- assertNotNull("intArray present", intArray);
- assertEquals("intArray length", 3, intArray.length);
- assertEquals("intArray[0]", 100, intArray[0]);
- assertEquals("intArray[1]", 200, intArray[1]);
- assertEquals("intArray[2]", 300, intArray[2]);
- final String[] stringArray = bean.getStringArray();
- assertNotNull("stringArray present", stringArray);
- assertEquals("stringArray length", 2, stringArray.length);
- assertEquals("stringArray[0]", "New 0", stringArray[0]);
- assertEquals("stringArray[1]", "New 1", stringArray[1]);
-
- }
-
- /**
- * Test copyProperties() when the origin is a a {@code Map}.
- */
- public void testCopyPropertiesMap() {
-
- final Map map = new HashMap<>();
- map.put("booleanProperty", "false");
- map.put("byteProperty", "111");
- map.put("doubleProperty", "333.0");
- map.put("dupProperty", new String[] { "New 0", "New 1", "New 2" });
- map.put("floatProperty", "222.0");
- map.put("intArray", new String[] { "0", "100", "200" });
- map.put("intProperty", "111");
- map.put("longProperty", "444");
- map.put("shortProperty", "555");
- map.put("stringProperty", "New String Property");
-
- try {
- BeanUtils.copyProperties(bean, map);
- } catch (final Throwable t) {
- fail("Threw " + t.toString());
- }
-
- // Scalar properties
- assertEquals("booleanProperty", false,
- bean.getBooleanProperty());
- assertEquals("byteProperty", (byte) 111,
- bean.getByteProperty());
- assertEquals("doubleProperty", 333.0,
- bean.getDoubleProperty(), 0.005);
- assertEquals("floatProperty", (float) 222.0,
- bean.getFloatProperty(), (float) 0.005);
- assertEquals("longProperty", 111,
- bean.getIntProperty());
- assertEquals("longProperty", 444,
- bean.getLongProperty());
- assertEquals("shortProperty", (short) 555,
- bean.getShortProperty());
- assertEquals("stringProperty", "New String Property",
- bean.getStringProperty());
-
- // Indexed Properties
- final String[] dupProperty = bean.getDupProperty();
- assertNotNull("dupProperty present", dupProperty);
- assertEquals("dupProperty length", 3, dupProperty.length);
- assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
- assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
- assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
- final int[] intArray = bean.getIntArray();
- assertNotNull("intArray present", intArray);
- assertEquals("intArray length", 3, intArray.length);
- assertEquals("intArray[0]", 0, intArray[0]);
- assertEquals("intArray[1]", 100, intArray[1]);
- assertEquals("intArray[2]", 200, intArray[2]);
-
- }
-
- /**
- * Test the copyProperties() method from a standard JavaBean.
- */
- public void testCopyPropertiesStandard() {
-
- // Set up an origin bean with customized properties
- final TestBean orig = new TestBean();
- orig.setBooleanProperty(false);
- orig.setByteProperty((byte) 111);
- orig.setDoubleProperty(333.33);
- orig.setDupProperty(new String[] { "New 0", "New 1", "New 2" });
- orig.setIntArray(new int[] { 100, 200, 300 });
- orig.setIntProperty(333);
- orig.setLongProperty(3333);
- orig.setShortProperty((short) 33);
- orig.setStringArray(new String[] { "New 0", "New 1" });
- orig.setStringProperty("Custom string");
-
- // Copy the origin bean to our destination test bean
- try {
- BeanUtils.copyProperties(bean, orig);
- } catch (final Exception e) {
- fail("Threw exception: " + e);
- }
-
- // Validate the results for scalar properties
- assertEquals("Copied boolean property",
- false,
- bean.getBooleanProperty());
- assertEquals("Copied byte property",
- (byte) 111,
- bean.getByteProperty());
- assertEquals("Copied double property",
- 333.33,
- bean.getDoubleProperty(),
- 0.005);
- assertEquals("Copied int property",
- 333,
- bean.getIntProperty());
- assertEquals("Copied long property",
- 3333,
- bean.getLongProperty());
- assertEquals("Copied short property",
- (short) 33,
- bean.getShortProperty());
- assertEquals("Copied string property",
- "Custom string",
- bean.getStringProperty());
-
- // Validate the results for array properties
- final String[] dupProperty = bean.getDupProperty();
- assertNotNull("dupProperty present", dupProperty);
- assertEquals("dupProperty length", 3, dupProperty.length);
- assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
- assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
- assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
- final int[] intArray = bean.getIntArray();
- assertNotNull("intArray present", intArray);
- assertEquals("intArray length", 3, intArray.length);
- assertEquals("intArray[0]", 100, intArray[0]);
- assertEquals("intArray[1]", 200, intArray[1]);
- assertEquals("intArray[2]", 300, intArray[2]);
- final String[] stringArray = bean.getStringArray();
- assertNotNull("stringArray present", stringArray);
- assertEquals("stringArray length", 2, stringArray.length);
- assertEquals("stringArray[0]", "New 0", stringArray[0]);
- assertEquals("stringArray[1]", "New 1", stringArray[1]);
-
- }
-
- /**
- * Test the describe() method.
- */
- public void testDescribe() {
-
- Map map = null;
- try {
- map = BeanUtils.describe(bean);
- } catch (final Exception e) {
- fail("Threw exception " + e);
- }
-
- // Verify existence of all the properties that should be present
- for (final String describe : describes) {
- assertTrue("Property '" + describe + "' is present",
- map.containsKey(describe));
- }
- assertTrue("Property 'writeOnlyProperty' is not present",
- !map.containsKey("writeOnlyProperty"));
-
- // Verify the values of scalar properties
- assertEquals("Value of 'booleanProperty'",
- "true",
- map.get("booleanProperty"));
- assertEquals("Value of 'byteProperty'",
- "121",
- map.get("byteProperty"));
- assertEquals("Value of 'doubleProperty'",
- "321.0",
- map.get("doubleProperty"));
- assertEquals("Value of 'floatProperty'",
- "123.0",
- map.get("floatProperty"));
- assertEquals("Value of 'intProperty'",
- "123",
- map.get("intProperty"));
- assertEquals("Value of 'longProperty'",
- "321",
- map.get("longProperty"));
- assertEquals("Value of 'shortProperty'",
- "987",
- map.get("shortProperty"));
- assertEquals("Value of 'stringProperty'",
- "This is a string",
- map.get("stringProperty"));
-
- }
-
- /**
- * tests the string and int arrays of TestBean
- */
- public void testGetArrayProperty() {
- try {
- String[] arr = BeanUtils.getArrayProperty(bean, "stringArray");
- final String[] comp = bean.getStringArray();
-
- assertTrue("String array length = " + comp.length,
- comp.length == arr.length);
-
- arr = BeanUtils.getArrayProperty(bean, "intArray");
- final int[] iarr = bean.getIntArray();
-
- assertTrue("String array length = " + iarr.length,
- iarr.length == arr.length);
-
- // Test property which isn't array or collection
- arr = BeanUtils.getArrayProperty(bean, "shortProperty");
- final String shortAsString = "" + bean.getShortProperty();
- assertEquals("Short List Test lth", 1, arr.length);
- assertEquals("Short Test value", shortAsString, arr[0]);
-
- // Test comma delimited list
- bean.setStringProperty("ABC");
- arr = BeanUtils.getArrayProperty(bean, "stringProperty");
- assertEquals("Delimited List Test lth", 1, arr.length);
- assertEquals("Delimited List Test value1", "ABC", arr[0]);
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test {@code getArrayProperty()} converting to a String.
- */
- public void testGetArrayPropertyDate() {
- String[] value = null;
- try {
- bean.setDateArrayProperty(new java.util.Date[] {testUtilDate});
- value = BeanUtils.getArrayProperty(bean, "dateArrayProperty");
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date[] --> String[] length", 1, value.length);
- assertEquals("java.util.Date[] --> String[] value ", testUtilDate.toString(), value[0]);
- }
-
- /**
- * tests getting an indexed property
- */
- public void testGetIndexedProperty1() {
- try {
- String val = BeanUtils.getIndexedProperty(bean, "intIndexed[3]");
- String comp = String.valueOf(bean.getIntIndexed(3));
- assertTrue("intIndexed[3] == " + comp, val.equals(comp));
-
- val = BeanUtils.getIndexedProperty(bean, "stringIndexed[3]");
- comp = bean.getStringIndexed(3);
- assertTrue("stringIndexed[3] == " + comp, val.equals(comp));
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * Test {@code getArrayProperty()} converting to a String.
- */
- public void testGetIndexedPropertyDate() {
- String value = null;
- try {
- bean.setDateArrayProperty(new java.util.Date[] {testUtilDate});
- value = BeanUtils.getIndexedProperty(bean, "dateArrayProperty[0]");
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date[0] --> String", testUtilDate.toString(), value);
- }
-
- /**
- * tests getting an indexed property
- */
- public void testGetIndexedProperty2() {
- try {
- String val = BeanUtils.getIndexedProperty(bean, "intIndexed", 3);
- String comp = String.valueOf(bean.getIntIndexed(3));
-
- assertTrue("intIndexed,3 == " + comp, val.equals(comp));
-
- val = BeanUtils.getIndexedProperty(bean, "stringIndexed", 3);
- comp = bean.getStringIndexed(3);
-
- assertTrue("stringIndexed,3 == " + comp, val.equals(comp));
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * tests getting a nested property
- */
- public void testGetNestedProperty() {
- try {
- final String val = BeanUtils.getNestedProperty(bean, "nested.stringProperty");
- final String comp = bean.getNested().getStringProperty();
- assertTrue("nested.StringProperty == " + comp,
- val.equals(comp));
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * tests getting a 'whatever' property
- */
- public void testGetGeneralProperty() {
- try {
- final String val = BeanUtils.getProperty(bean, "nested.intIndexed[2]");
- final String comp = String.valueOf(bean.getIntIndexed(2));
-
- assertTrue("nested.intIndexed[2] == " + comp,
- val.equals(comp));
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * tests getting a 'whatever' property
- */
- public void testGetSimpleProperty() {
- try {
- final String val = BeanUtils.getSimpleProperty(bean, "shortProperty");
- final String comp = String.valueOf(bean.getShortProperty());
-
- assertTrue("shortProperty == " + comp,
- val.equals(comp));
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * Test {@code getSimpleProperty()} converting to a String.
- */
- public void testGetSimplePropertyDate() {
- String value = null;
- try {
- bean.setDateProperty(testUtilDate);
- value = BeanUtils.getSimpleProperty(bean, "dateProperty");
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date --> String", testUtilDate.toString(), value);
- }
-
- /**
- * Test populate() method on individual array elements.
- */
- public void testPopulateArrayElements() {
-
- try {
-
- final HashMap map = new HashMap<>();
- map.put("intIndexed[0]", "100");
- map.put("intIndexed[2]", "120");
- map.put("intIndexed[4]", "140");
-
- BeanUtils.populate(bean, map);
-
- assertEquals("intIndexed[0] is 100",
- 100, bean.getIntIndexed(0));
- assertEquals("intIndexed[1] is 10",
- 10, bean.getIntIndexed(1));
- assertEquals("intIndexed[2] is 120",
- 120, bean.getIntIndexed(2));
- assertEquals("intIndexed[3] is 30",
- 30, bean.getIntIndexed(3));
- assertEquals("intIndexed[4] is 140",
- 140, bean.getIntIndexed(4));
-
- map.clear();
- map.put("stringIndexed[1]", "New String 1");
- map.put("stringIndexed[3]", "New String 3");
-
- BeanUtils.populate(bean, map);
-
- assertEquals("stringIndexed[0] is \"String 0\"",
- "String 0", bean.getStringIndexed(0));
- assertEquals("stringIndexed[1] is \"New String 1\"",
- "New String 1", bean.getStringIndexed(1));
- assertEquals("stringIndexed[2] is \"String 2\"",
- "String 2", bean.getStringIndexed(2));
- assertEquals("stringIndexed[3] is \"New String 3\"",
- "New String 3", bean.getStringIndexed(3));
- assertEquals("stringIndexed[4] is \"String 4\"",
- "String 4", bean.getStringIndexed(4));
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * Test populate() method on array properties as a whole.
- */
- public void testPopulateArrayProperties() {
-
- try {
-
- final HashMap map = new HashMap<>();
- int[] intArray = new int[] { 123, 456, 789 };
- map.put("intArray", intArray);
- String[] stringArray = new String[]
- { "New String 0", "New String 1" };
- map.put("stringArray", stringArray);
-
- BeanUtils.populate(bean, map);
-
- intArray = bean.getIntArray();
- assertNotNull("intArray is present", intArray);
- assertEquals("intArray length",
- 3, intArray.length);
- assertEquals("intArray[0]", 123, intArray[0]);
- assertEquals("intArray[1]", 456, intArray[1]);
- assertEquals("intArray[2]", 789, intArray[2]);
- stringArray = bean.getStringArray();
- assertNotNull("stringArray is present", stringArray);
- assertEquals("stringArray length", 2, stringArray.length);
- assertEquals("stringArray[0]", "New String 0", stringArray[0]);
- assertEquals("stringArray[1]", "New String 1", stringArray[1]);
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * Test populate() on mapped properties.
- */
- public void testPopulateMapped() {
-
- try {
-
- final HashMap map = new HashMap<>();
- map.put("mappedProperty(First Key)", "New First Value");
- map.put("mappedProperty(Third Key)", "New Third Value");
-
- BeanUtils.populate(bean, map);
-
- assertEquals("mappedProperty(First Key)",
- "New First Value",
- bean.getMappedProperty("First Key"));
- assertEquals("mappedProperty(Second Key)",
- "Second Value",
- bean.getMappedProperty("Second Key"));
- assertEquals("mappedProperty(Third Key)",
- "New Third Value",
- bean.getMappedProperty("Third Key"));
- assertNull("mappedProperty(Fourth Key",
- bean.getMappedProperty("Fourth Key"));
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * Test populate() method on nested properties.
- */
- public void testPopulateNested() {
-
- try {
-
- final HashMap map = new HashMap<>();
- map.put("nested.booleanProperty", "false");
- // booleanSecond is left at true
- map.put("nested.doubleProperty", "432.0");
- // floatProperty is left at 123.0
- map.put("nested.intProperty", "543");
- // longProperty is left at 321
- map.put("nested.shortProperty", "654");
- // stringProperty is left at "This is a string"
- map.put("nested.writeOnlyProperty", "New writeOnlyProperty value");
-
- BeanUtils.populate(bean, map);
-
- assertTrue("booleanProperty is false",
- !bean.getNested().getBooleanProperty());
- assertTrue("booleanSecond is true",
- bean.getNested().isBooleanSecond());
- assertEquals("doubleProperty is 432.0",
- 432.0,
- bean.getNested().getDoubleProperty(),
- 0.005);
- assertEquals("floatProperty is 123.0",
- (float) 123.0,
- bean.getNested().getFloatProperty(),
- (float) 0.005);
- assertEquals("intProperty is 543",
- 543, bean.getNested().getIntProperty());
- assertEquals("longProperty is 321",
- 321, bean.getNested().getLongProperty());
- assertEquals("shortProperty is 654",
- (short) 654, bean.getNested().getShortProperty());
- assertEquals("stringProperty is \"This is a string\"",
- "This is a string",
- bean.getNested().getStringProperty());
- assertEquals("writeOnlyProperty is \"New writeOnlyProperty value\"",
- "New writeOnlyProperty value",
- bean.getNested().getWriteOnlyPropertyValue());
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * Test populate() method on scalar properties.
- */
- public void testPopulateScalar() {
-
- try {
-
- bean.setNullProperty("Non-null value");
-
- final HashMap map = new HashMap<>();
- map.put("booleanProperty", "false");
- // booleanSecond is left at true
- map.put("byteProperty", "111");
- map.put("doubleProperty", "432.0");
- // floatProperty is left at 123.0
- map.put("intProperty", "543");
- map.put("longProperty", "");
- map.put("nullProperty", null);
- map.put("shortProperty", "654");
- // stringProperty is left at "This is a string"
- map.put("writeOnlyProperty", "New writeOnlyProperty value");
- map.put("readOnlyProperty", "New readOnlyProperty value");
-
- BeanUtils.populate(bean, map);
-
- assertTrue("booleanProperty is false", !bean.getBooleanProperty());
- assertTrue("booleanSecond is true", bean.isBooleanSecond());
- assertEquals("byteProperty is 111",
- (byte) 111, bean.getByteProperty());
- assertEquals("doubleProperty is 432.0",
- 432.0, bean.getDoubleProperty(),
- 0.005);
- assertEquals("floatProperty is 123.0",
- (float) 123.0, bean.getFloatProperty(),
- (float) 0.005);
- assertEquals("intProperty is 543",
- 543, bean.getIntProperty());
- assertEquals("longProperty is 0",
- 0, bean.getLongProperty());
- assertNull("nullProperty is null",
- bean.getNullProperty());
- assertEquals("shortProperty is 654",
- (short) 654, bean.getShortProperty());
- assertEquals("stringProperty is \"This is a string\"",
- "This is a string", bean.getStringProperty());
- assertEquals("writeOnlyProperty is \"New writeOnlyProperty value\"",
- "New writeOnlyProperty value",
- bean.getWriteOnlyPropertyValue());
- assertEquals("readOnlyProperty is \"Read Only String Property\"",
- "Read Only String Property",
- bean.getReadOnlyProperty());
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * Test calling setProperty() with null property values.
- */
- public void testSetPropertyNullValues() throws Exception {
-
- Object oldValue = null;
- Object newValue = null;
-
- // Scalar value into array
- oldValue = PropertyUtils.getSimpleProperty(bean, "stringArray");
- BeanUtils.setProperty(bean, "stringArray", null);
- newValue = PropertyUtils.getSimpleProperty(bean, "stringArray");
- assertNotNull("stringArray is not null", newValue);
- assertTrue("stringArray of correct type",
- newValue instanceof String[]);
- assertEquals("stringArray length",
- 1, ((String[]) newValue).length);
- PropertyUtils.setProperty(bean, "stringArray", oldValue);
-
- // Indexed value into array
- oldValue = PropertyUtils.getSimpleProperty(bean, "stringArray");
- BeanUtils.setProperty(bean, "stringArray[2]", null);
- newValue = PropertyUtils.getSimpleProperty(bean, "stringArray");
- assertNotNull("stringArray is not null", newValue);
- assertTrue("stringArray of correct type",
- newValue instanceof String[]);
- assertEquals("stringArray length",
- 5, ((String[]) newValue).length);
- assertTrue("stringArray[2] is null",
- ((String[]) newValue)[2] == null);
- PropertyUtils.setProperty(bean, "stringArray", oldValue);
-
- // Value into scalar
- BeanUtils.setProperty(bean, "stringProperty", null);
- assertTrue("stringProperty is now null",
- BeanUtils.getProperty(bean, "stringProperty") == null);
-
- }
-
- /**
- * Test converting to and from primitive wrapper types.
- */
- public void testSetPropertyOnPrimitiveWrappers() throws Exception {
-
- BeanUtils.setProperty(bean,"intProperty", new Integer(1));
- assertEquals(1,bean.getIntProperty());
- BeanUtils.setProperty(bean,"stringProperty", new Integer(1));
- assertEquals(1, Integer.parseInt(bean.getStringProperty()));
-
- }
-
- /**
- * Test narrowing and widening conversions on byte.
- */
- public void testSetPropertyByte() throws Exception {
-
- BeanUtils.setProperty(bean, "byteProperty", new Byte((byte) 123));
- assertEquals((byte) 123, bean.getByteProperty());
-/*
- BeanUtils.setProperty(bean, "byteProperty", new Double((double) 123));
- assertEquals((byte) 123, bean.getByteProperty());
- BeanUtils.setProperty(bean, "byteProperty", new Float((float) 123));
- assertEquals((byte) 123, bean.getByteProperty());
-*/
- BeanUtils.setProperty(bean, "byteProperty", new Integer(123));
- assertEquals((byte) 123, bean.getByteProperty());
- BeanUtils.setProperty(bean, "byteProperty", new Long(123));
- assertEquals((byte) 123, bean.getByteProperty());
- BeanUtils.setProperty(bean, "byteProperty", new Short((short) 123));
- assertEquals((byte) 123, bean.getByteProperty());
-
- }
-
- /**
- * Test {@code setProperty()} conversion.
- */
- public void testSetPropertyConvert() {
- try {
- BeanUtils.setProperty(bean, "dateProperty", testCalendar);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("Calendar --> java.util.Date", testUtilDate, bean.getDateProperty());
- }
-
- /**
- * Test {@code setProperty()} converting from a String.
- */
- public void testSetPropertyConvertFromString() {
- try {
- BeanUtils.setProperty(bean, "dateProperty", testStringDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("String --> java.util.Date", testUtilDate, bean.getDateProperty());
- }
-
- /**
- * Test {@code setProperty()} converting to a String.
- */
- public void testSetPropertyConvertToString() {
- try {
- BeanUtils.setProperty(bean, "stringProperty", testUtilDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date --> String", testUtilDate.toString(), bean.getStringProperty());
- }
-
- /**
- * Test {@code setProperty()} converting to a String array.
- */
- public void testSetPropertyConvertToStringArray() {
- try {
- bean.setStringArray(null);
- BeanUtils.setProperty(bean, "stringArray", new java.util.Date[] {testUtilDate});
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length);
- assertEquals("java.util.Date[] --> String[] value ", testUtilDate.toString(), bean.getStringArray()[0]);
- }
-
- /**
- * Test {@code setProperty()} converting to a String on indexed property
- */
- public void testSetPropertyConvertToStringIndexed() {
- try {
- bean.setStringArray(new String[1]);
- BeanUtils.setProperty(bean, "stringArray[0]", testUtilDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date --> String[]", testUtilDate.toString(), bean.getStringArray()[0]);
- }
-
- /**
- * Test narrowing and widening conversions on double.
- */
- public void testSetPropertyDouble() throws Exception {
-
- BeanUtils.setProperty(bean, "doubleProperty", new Byte((byte) 123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Double(123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Float(123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Integer(123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Long(123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Short((short) 123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
-
- }
-
- /**
- * Test narrowing and widening conversions on float.
- */
- public void testSetPropertyFloat() throws Exception {
-
- BeanUtils.setProperty(bean, "floatProperty", new Byte((byte) 123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Double(123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Float(123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Integer(123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Long(123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Short((short) 123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
-
- }
-
- /**
- * Test narrowing and widening conversions on int.
- */
- public void testSetPropertyInteger() throws Exception {
-
- BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
- assertEquals(123, bean.getIntProperty());
-/*
- BeanUtils.setProperty(bean, "longProperty", new Double((double) 123));
- assertEquals((int) 123, bean.getIntProperty());
- BeanUtils.setProperty(bean, "longProperty", new Float((float) 123));
- assertEquals((int) 123, bean.getIntProperty());
-*/
- BeanUtils.setProperty(bean, "longProperty", new Integer(123));
- assertEquals(123, bean.getIntProperty());
- BeanUtils.setProperty(bean, "longProperty", new Long(123));
- assertEquals(123, bean.getIntProperty());
- BeanUtils.setProperty(bean, "longProperty", new Short((short) 123));
- assertEquals(123, bean.getIntProperty());
-
- }
-
- /**
- * Test narrowing and widening conversions on long.
- */
- public void testSetPropertyLong() throws Exception {
-
- BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
- assertEquals(123, bean.getLongProperty());
-/*
- BeanUtils.setProperty(bean, "longProperty", new Double((double) 123));
- assertEquals((long) 123, bean.getLongProperty());
- BeanUtils.setProperty(bean, "longProperty", new Float((float) 123));
- assertEquals((long) 123, bean.getLongProperty());
-*/
- BeanUtils.setProperty(bean, "longProperty", new Integer(123));
- assertEquals(123, bean.getLongProperty());
- BeanUtils.setProperty(bean, "longProperty", new Long(123));
- assertEquals(123, bean.getLongProperty());
- BeanUtils.setProperty(bean, "longProperty", new Short((short) 123));
- assertEquals(123, bean.getLongProperty());
-
- }
-
- /**
- * Test setting a null property value.
- */
- public void testSetPropertyNull() throws Exception {
-
- bean.setNullProperty("non-null value");
- BeanUtils.setProperty(bean, "nullProperty", null);
- assertNull("nullProperty is null", bean.getNullProperty());
-
- }
-
- /**
- * Test narrowing and widening conversions on short.
- */
- public void testSetPropertyShort() throws Exception {
-
- BeanUtils.setProperty(bean, "shortProperty", new Byte((byte) 123));
- assertEquals((short) 123, bean.getShortProperty());
-/*
- BeanUtils.setProperty(bean, "shortProperty", new Double((double) 123));
- assertEquals((short) 123, bean.getShortProperty());
- BeanUtils.setProperty(bean, "shortProperty", new Float((float) 123));
- assertEquals((short) 123, bean.getShortProperty());
-*/
- BeanUtils.setProperty(bean, "shortProperty", new Integer(123));
- assertEquals((short) 123, bean.getShortProperty());
- BeanUtils.setProperty(bean, "shortProperty", new Long(123));
- assertEquals((short) 123, bean.getShortProperty());
- BeanUtils.setProperty(bean, "shortProperty", new Short((short) 123));
- assertEquals((short) 123, bean.getShortProperty());
-
- }
-
- /**
- * Test setting a String value to a String array property
- */
- public void testSetPropertyStringToArray() throws Exception {
- BeanUtils.setProperty(bean, "stringArray", "ABC,DEF,GHI");
- final String[] strArray = bean.getStringArray();
- assertEquals("length", 3, strArray.length);
- assertEquals("value[0]", "ABC", strArray[0]);
- assertEquals("value[1]", "DEF", strArray[1]);
- assertEquals("value[2]", "GHI", strArray[2]);
-
- BeanUtils.setProperty(bean, "intArray", "0, 10, 20, 30, 40");
- final int[] intArray = bean.getIntArray();
- assertEquals("length", 5, intArray.length);
- assertEquals("value[0]", 0, intArray[0]);
- assertEquals("value[1]", 10, intArray[1]);
- assertEquals("value[2]", 20, intArray[2]);
- assertEquals("value[3]", 30, intArray[3]);
- assertEquals("value[4]", 40, intArray[4]);
- }
-
- /**
- * Test narrowing and widening conversions on byte.
- */
- public void testCopyPropertyByte() throws Exception {
-
- BeanUtils.copyProperty(bean, "byteProperty", new Byte((byte) 123));
- assertEquals((byte) 123, bean.getByteProperty());
- BeanUtils.copyProperty(bean, "byteProperty", new Double(123));
- assertEquals((byte) 123, bean.getByteProperty());
- BeanUtils.copyProperty(bean, "byteProperty", new Float(123));
- assertEquals((byte) 123, bean.getByteProperty());
- BeanUtils.copyProperty(bean, "byteProperty", new Integer(123));
- assertEquals((byte) 123, bean.getByteProperty());
- BeanUtils.copyProperty(bean, "byteProperty", new Long(123));
- assertEquals((byte) 123, bean.getByteProperty());
- BeanUtils.copyProperty(bean, "byteProperty", new Short((short) 123));
- assertEquals((byte) 123, bean.getByteProperty());
-
- }
-
- /**
- * Test {@code copyProperty()} conversion.
- */
- public void testCopyPropertyConvert() {
- try {
- BeanUtils.copyProperty(bean, "dateProperty", testCalendar);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("Calendar --> java.util.Date", testUtilDate, bean.getDateProperty());
- }
-
- /**
- * Test {@code copyProperty()} converting from a String.
- */
- public void testCopyPropertyConvertFromString() {
- try {
- BeanUtils.copyProperty(bean, "dateProperty", testStringDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("String --> java.util.Date", testUtilDate, bean.getDateProperty());
- }
-
- /**
- * Test {@code copyProperty()} converting to a String.
- */
- public void testCopyPropertyConvertToString() {
- try {
- BeanUtils.copyProperty(bean, "stringProperty", testUtilDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date --> String", testUtilDate.toString(), bean.getStringProperty());
- }
-
- /**
- * Test {@code copyProperty()} converting to a String.
- */
- public void testCopyPropertyConvertToStringArray() {
- try {
- bean.setStringArray(null);
- BeanUtils.copyProperty(bean, "stringArray", new java.util.Date[] {testUtilDate});
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date[] --> String[] length", 1, bean.getStringArray().length);
- assertEquals("java.util.Date[] --> String[] value ", testUtilDate.toString(), bean.getStringArray()[0]);
- }
-
- /**
- * Test {@code copyProperty()} converting to a String on indexed property
- */
- public void testCopyPropertyConvertToStringIndexed() {
- try {
- bean.setStringArray(new String[1]);
- BeanUtils.copyProperty(bean, "stringArray[0]", testUtilDate);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
- assertEquals("java.util.Date --> String[]", testUtilDate.toString(), bean.getStringArray()[0]);
- }
-
- /**
- * Test narrowing and widening conversions on double.
- */
- public void testCopyPropertyDouble() throws Exception {
-
- BeanUtils.copyProperty(bean, "doubleProperty", new Byte((byte) 123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.copyProperty(bean, "doubleProperty", new Double(123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.copyProperty(bean, "doubleProperty", new Float(123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.copyProperty(bean, "doubleProperty", new Integer(123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.copyProperty(bean, "doubleProperty", new Long(123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
- BeanUtils.copyProperty(bean, "doubleProperty", new Short((short) 123));
- assertEquals(123, bean.getDoubleProperty(), 0.005);
-
- }
-
- /**
- * Test narrowing and widening conversions on float.
- */
- public void testCopyPropertyFloat() throws Exception {
-
- BeanUtils.copyProperty(bean, "floatProperty", new Byte((byte) 123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.copyProperty(bean, "floatProperty", new Double(123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.copyProperty(bean, "floatProperty", new Float(123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.copyProperty(bean, "floatProperty", new Integer(123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.copyProperty(bean, "floatProperty", new Long(123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
- BeanUtils.copyProperty(bean, "floatProperty", new Short((short) 123));
- assertEquals(123, bean.getFloatProperty(), 0.005);
-
- }
-
- /**
- * Test narrowing and widening conversions on int.
- */
- public void testCopyPropertyInteger() throws Exception {
-
- BeanUtils.copyProperty(bean, "longProperty", new Byte((byte) 123));
- assertEquals(123, bean.getIntProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Double(123));
- assertEquals(123, bean.getIntProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Float(123));
- assertEquals(123, bean.getIntProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Integer(123));
- assertEquals(123, bean.getIntProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Long(123));
- assertEquals(123, bean.getIntProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Short((short) 123));
- assertEquals(123, bean.getIntProperty());
-
- }
-
- /**
- * Test narrowing and widening conversions on long.
- */
- public void testCopyPropertyLong() throws Exception {
-
- BeanUtils.copyProperty(bean, "longProperty", new Byte((byte) 123));
- assertEquals(123, bean.getLongProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Double(123));
- assertEquals(123, bean.getLongProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Float(123));
- assertEquals(123, bean.getLongProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Integer(123));
- assertEquals(123, bean.getLongProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Long(123));
- assertEquals(123, bean.getLongProperty());
- BeanUtils.copyProperty(bean, "longProperty", new Short((short) 123));
- assertEquals(123, bean.getLongProperty());
-
- }
-
- /**
- * Test narrowing and widening conversions on short.
- */
- public void testCopyPropertyShort() throws Exception {
-
- BeanUtils.copyProperty(bean, "shortProperty", new Byte((byte) 123));
- assertEquals((short) 123, bean.getShortProperty());
- BeanUtils.copyProperty(bean, "shortProperty", new Double(123));
- assertEquals((short) 123, bean.getShortProperty());
- BeanUtils.copyProperty(bean, "shortProperty", new Float(123));
- assertEquals((short) 123, bean.getShortProperty());
- BeanUtils.copyProperty(bean, "shortProperty", new Integer(123));
- assertEquals((short) 123, bean.getShortProperty());
- BeanUtils.copyProperty(bean, "shortProperty", new Long(123));
- assertEquals((short) 123, bean.getShortProperty());
- BeanUtils.copyProperty(bean, "shortProperty", new Short((short) 123));
- assertEquals((short) 123, bean.getShortProperty());
-
- }
-
- /**
- * Test copying a property using a nested indexed array expression,
- * with and without conversions.
- */
- public void testCopyPropertyNestedIndexedArray() throws Exception {
-
- final int[] origArray = { 0, 10, 20, 30, 40 };
- final int[] intArray = { 0, 0, 0 };
- bean.getNested().setIntArray(intArray);
- final int[] intChanged = { 0, 0, 0 };
-
- // No conversion required
- BeanUtils.copyProperty(bean, "nested.intArray[1]", new Integer(1));
- checkIntArray(bean.getIntArray(), origArray);
- intChanged[1] = 1;
- checkIntArray(bean.getNested().getIntArray(), intChanged);
-
- // Widening conversion required
- BeanUtils.copyProperty(bean, "nested.intArray[1]", new Byte((byte) 2));
- checkIntArray(bean.getIntArray(), origArray);
- intChanged[1] = 2;
- checkIntArray(bean.getNested().getIntArray(), intChanged);
-
- // Narrowing conversion required
- BeanUtils.copyProperty(bean, "nested.intArray[1]", new Long(3));
- checkIntArray(bean.getIntArray(), origArray);
- intChanged[1] = 3;
- checkIntArray(bean.getNested().getIntArray(), intChanged);
-
- // String conversion required
- BeanUtils.copyProperty(bean, "nested.intArray[1]", "4");
- checkIntArray(bean.getIntArray(), origArray);
- intChanged[1] = 4;
- checkIntArray(bean.getNested().getIntArray(), intChanged);
-
- }
-
- /**
- * Test copying a property using a nested mapped map property.
- */
- public void testCopyPropertyNestedMappedMap() throws Exception {
-
- final Map origMap = new HashMap<>();
- origMap.put("First Key", "First Value");
- origMap.put("Second Key", "Second Value");
- final Map changedMap = new HashMap<>();
- changedMap.put("First Key", "First Value");
- changedMap.put("Second Key", "Second Value");
-
- // No conversion required
- BeanUtils.copyProperty(bean, "nested.mapProperty(Second Key)",
- "New Second Value");
- checkMap(bean.getMapProperty(), origMap);
- changedMap.put("Second Key", "New Second Value");
- checkMap(bean.getNested().getMapProperty(), changedMap);
-
- }
-
- /**
- * Test copying a property using a nested simple expression, with and
- * without conversions.
- */
- public void testCopyPropertyNestedSimple() throws Exception {
-
- bean.setIntProperty(0);
- bean.getNested().setIntProperty(0);
-
- // No conversion required
- BeanUtils.copyProperty(bean, "nested.intProperty", new Integer(1));
- assertNotNull(bean.getNested());
- assertEquals(0, bean.getIntProperty());
- assertEquals(1, bean.getNested().getIntProperty());
-
- // Widening conversion required
- BeanUtils.copyProperty(bean, "nested.intProperty", new Byte((byte) 2));
- assertNotNull(bean.getNested());
- assertEquals(0, bean.getIntProperty());
- assertEquals(2, bean.getNested().getIntProperty());
-
- // Narrowing conversion required
- BeanUtils.copyProperty(bean, "nested.intProperty", new Long(3));
- assertNotNull(bean.getNested());
- assertEquals(0, bean.getIntProperty());
- assertEquals(3, bean.getNested().getIntProperty());
-
- // String conversion required
- BeanUtils.copyProperty(bean, "nested.intProperty", "4");
- assertNotNull(bean.getNested());
- assertEquals(0, bean.getIntProperty());
- assertEquals(4, bean.getNested().getIntProperty());
-
- }
-
- /**
- * Test copying a null property value.
- */
- public void testCopyPropertyNull() throws Exception {
-
- bean.setNullProperty("non-null value");
- BeanUtils.copyProperty(bean, "nullProperty", null);
- assertNull("nullProperty is null", bean.getNullProperty());
-
- }
-
- /**
- * Test copying a new value to a write-only property, with and without
- * conversions.
- */
- public void testCopyPropertyWriteOnly() throws Exception {
-
- bean.setWriteOnlyProperty("Original value");
-
- // No conversion required
- BeanUtils.copyProperty(bean, "writeOnlyProperty", "New value");
- assertEquals("New value", bean.getWriteOnlyPropertyValue());
-
- // Integer->String conversion required
- BeanUtils.copyProperty(bean, "writeOnlyProperty", new Integer(123));
- assertEquals("123", bean.getWriteOnlyPropertyValue());
-
- }
-
- /**
- * Test setting a new value to a write-only property, with and without
- * conversions.
- */
- public void testSetPropertyWriteOnly() throws Exception {
-
- bean.setWriteOnlyProperty("Original value");
-
- // No conversion required
- BeanUtils.setProperty(bean, "writeOnlyProperty", "New value");
- assertEquals("New value", bean.getWriteOnlyPropertyValue());
-
- // Integer->String conversion required
- BeanUtils.setProperty(bean, "writeOnlyProperty", new Integer(123));
- assertEquals("123", bean.getWriteOnlyPropertyValue());
-
- }
-
- /**
- * Test setting a value out of a mapped Map
- */
- public void testSetMappedMap() {
- final TestBean bean = new TestBean();
- final Map map = new HashMap<>();
- map.put("sub-key-1", "sub-value-1");
- map.put("sub-key-2", "sub-value-2");
- map.put("sub-key-3", "sub-value-3");
- bean.getMapProperty().put("mappedMap", map);
-
- assertEquals("BEFORE", "sub-value-3", ((Map, ?>)bean.getMapProperty().get("mappedMap")).get("sub-key-3"));
- try {
- BeanUtils.setProperty(bean, "mapProperty(mappedMap)(sub-key-3)", "SUB-KEY-3-UPDATED");
- } catch (final Throwable t) {
- fail("Threw " + t + "");
- }
- assertEquals("AFTER", "SUB-KEY-3-UPDATED", ((Map, ?>)bean.getMapProperty().get("mappedMap")).get("sub-key-3"));
- }
-
- /** Tests that separate instances can register separate instances */
- public void testSeparateInstances() throws Exception {
- final BeanUtilsBean utilsOne = new BeanUtilsBean(
- new ConvertUtilsBean(),
- new PropertyUtilsBean());
- final BeanUtilsBean utilsTwo = new BeanUtilsBean(
- new ConvertUtilsBean(),
- new PropertyUtilsBean());
-
- final TestBean bean = new TestBean();
-
- // Make sure what we're testing works
- bean.setBooleanProperty(false);
- utilsOne.setProperty(bean, "booleanProperty", "true");
- assertEquals("Set property failed (1)", bean.getBooleanProperty(), true);
-
- bean.setBooleanProperty(false);
- utilsTwo.setProperty(bean, "booleanProperty", "true");
- assertEquals("Set property failed (2)", bean.getBooleanProperty(), true);
-
- // now change the registered conversion
-
- utilsOne.getConvertUtils().register(new ThrowExceptionConverter(), Boolean.TYPE);
- try {
-
- bean.setBooleanProperty(false);
- utilsOne.setProperty(bean, "booleanProperty", "true");
- fail("Registered conversion not used.");
-
- } catch (final PassTestException e) { /* Do nothing */ }
-
- // make sure that this conversion has no been registered in the other instance
- try {
-
- bean.setBooleanProperty(false);
- utilsTwo.setProperty(bean, "booleanProperty", "true");
- assertEquals("Set property failed (3)", bean.getBooleanProperty(), true);
-
- } catch (final PassTestException e) {
- fail("Registered converter is used by other instances");
- }
- }
-
- public void testArrayPropertyConversion() throws Exception {
- final BeanUtilsBean beanUtils = new BeanUtilsBean(
- new ConvertUtilsBean(),
- new PropertyUtilsBean());
-
- final TestBean bean = new TestBean();
- final String [] results = beanUtils.getArrayProperty(bean, "intArray");
-
- final int[] values = bean.getIntArray();
- assertEquals(
- "Converted array size not equal to property array size.",
- results.length,
- values.length);
- for (int i=0, size=values.length ; i actual, final Map, ?> expected) {
- assertNotNull("actual map not null", actual);
- assertEquals("actual map size", expected.size(), actual.size());
- final Iterator> keys = expected.keySet().iterator();
- while (keys.hasNext()) {
- final Object key = keys.next();
- assertEquals("actual map value(" + key + ")",
- expected.get(key), actual.get(key));
- }
- }
-
- public void testMappedProperty() throws Exception {
- final MappedPropertyTestBean bean = new MappedPropertyTestBean();
-
- BeanUtils.setProperty(bean, "mapproperty(this.that.the-other)", "some.dotty.value");
-
- assertEquals(
- "Mapped property set correctly",
- "some.dotty.value",
- bean.getMapproperty("this.that.the-other"));
- }
-
- /**
- * Test for {@link BeanUtilsBean#initCause(Throwable, Throwable)} method.
- */
- public void testInitCause() {
- if (isPre14JVM()) {
- return;
- }
- final String parentMsg = "PARENT-THROWABLE";
- final String causeMsg = "THROWABLE-CAUSE";
- try {
- initCauseAndThrowException(parentMsg, causeMsg);
- } catch (final Throwable thrownParent) {
- assertEquals("Parent", parentMsg, thrownParent.getMessage());
- try {
- assertEquals("Parent", parentMsg, thrownParent.getMessage());
- final Throwable thrownCause = getCause(thrownParent);
- assertNotNull("Cause Null", thrownCause);
- assertEquals("Cause", causeMsg, thrownCause.getMessage());
- } catch (final Throwable testError) {
- fail("If you're running JDK 1.3 then don't worry this should fail," +
- " if not then needs checking out: " + testError);
- }
- }
- }
-
- /**
- * Use reflection to get the cause
- */
- private Throwable getCause(final Throwable t) throws Throwable {
- return (Throwable)PropertyUtils.getProperty(t, "cause");
- }
-
- /**
- * Catch a cause, initialize using BeanUtils.initCause() and throw new exception
- */
- private void initCauseAndThrowException(final String parent, final String cause) throws Throwable {
- try {
- throwException(cause);
- } catch (final Throwable e) {
- final Throwable t = new Exception(parent);
- BeanUtils.initCause(t, e);
- throw t;
- }
- }
-
- /**
- * Throw an exception with the specified message.
- */
- private void throwException(final String msg) throws Throwable {
- throw new Exception(msg);
- }
-
- /**
- * Test for JDK 1.4
- */
- public static boolean isPre14JVM() {
- final String version = System.getProperty("java.specification.version");
- final StringTokenizer tokenizer = new StringTokenizer(version,".");
- if (tokenizer.nextToken().equals("1")) {
- final String minorVersion = tokenizer.nextToken();
- if (minorVersion.equals("0")) {
- return true;
- }
- if (minorVersion.equals("1")) {
- return true;
- }
- if (minorVersion.equals("2")) {
- return true;
- }
- if (minorVersion.equals("3")) {
- return true;
- }
- }
- return false;
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanWithInnerBean.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanWithInnerBean.java
deleted file mode 100644
index 5e9d1af7e..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanWithInnerBean.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.util.Properties;
-
-/**
- * Bean with inner bean.
- *
- */
-public class BeanWithInnerBean {
- private final InnerBean innerBean = new InnerBean();
-
- public BeanWithInnerBean() {}
- public InnerBean getInnerBean(){
- return innerBean;
- }
-
- public class InnerBean {
- private final Properties fish = new Properties();
-
- public String getFish(final String key){
- return fish.getProperty(key);
- }
- public void setFish(final String key, final String value){
- fish.setProperty(key, value);
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanificationTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanificationTestCase.java
deleted file mode 100644
index 0b3a71abe..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BeanificationTestCase.java
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.apache.commons.logging.LogFactory;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
- * Test Case for changes made during Beanutils Beanification
- *
- *
- */
-
-public class BeanificationTestCase extends TestCase {
-
-
-
- /** Maximum number of iterations before our test fails */
- public static final int MAX_GC_ITERATIONS = 50;
-
-
-
-
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public BeanificationTestCase(final String name) {
- super(name);
- }
-
-
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() {
-
- ConvertUtils.deregister();
-
- }
-
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
- return new TestSuite(BeanificationTestCase.class);
- }
-
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- // No action required
- }
-
-
-
-
- /** Test of the methodology we'll use for some of the later tests */
- 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 reference = new WeakReference<>(loader);
- @SuppressWarnings("unused")
- Class> myClass = loader.loadClass("org.apache.commons.beanutils2.BetaBean");
-
- assertNotNull("Weak reference released early", reference.get());
-
- // dereference class loader and class:
- loader = null;
- myClass = null;
-
- int iterations = 0;
- int bytz = 2;
- while(true) {
- System.gc();
- if(iterations++ > MAX_GC_ITERATIONS){
- fail("Max iterations reached before resource released.");
- }
- if( reference.get() == null ) {
- break;
-
- }
- // create garbage:
- @SuppressWarnings("unused")
- final
- byte[] b = new byte[bytz];
- bytz = bytz * 2;
- }
- }
-
- /** Tests whether classloaders and beans are released from memory by the map used by beanutils */
- public void testMemoryLeak2() throws Exception {
- // tests when the map used by beanutils has the right behavior
-
- if (BeanUtilsTestCase.isPre14JVM()) {
- System.out.println("WARNING: CANNOT TEST MEMORY LEAK ON PRE1.4 JVM");
- return;
- }
-
- // many thanks to Juozas Baliuka for suggesting this methodology
- TestClassLoader loader = new TestClassLoader();
- final ReferenceQueue queue = new ReferenceQueue<>();
- final WeakReference loaderReference = new WeakReference<>(loader, queue);
- Integer test = new Integer(1);
-
- final WeakReference testReference = new WeakReference<>(test, queue);
- //Map map = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true);
- final Map map = new WeakHashMap<>();
- map.put(loader, test);
-
- assertEquals("In map", test, map.get(loader));
- assertNotNull("Weak reference released early (1)", loaderReference.get());
- assertNotNull("Weak reference released early (2)", testReference.get());
-
- // dereference strong references
- loader = null;
- test = null;
-
- int iterations = 0;
- int bytz = 2;
- while(true) {
- System.gc();
- if(iterations++ > MAX_GC_ITERATIONS){
- fail("Max iterations reached before resource released.");
- }
- map.isEmpty();
-
- if(
- loaderReference.get() == null &&
- testReference.get() == null) {
- break;
-
- }
- // create garbage:
- @SuppressWarnings("unused")
- final
- byte[] b = new byte[bytz];
- bytz = bytz * 2;
- }
- }
-
- /** Tests whether classloaders and beans are released from memory */
- public void testMemoryLeak() throws Exception {
- if (BeanUtilsTestCase.isPre14JVM()) {
- System.out.println("WARNING: CANNOT TEST MEMORY LEAK ON PRE1.4 JVM");
- return;
- }
-
- // many thanks to Juozas Baliuka for suggesting this methodology
- TestClassLoader loader = new TestClassLoader();
- final WeakReference loaderReference = new WeakReference<>(loader);
- BeanUtilsBean.getInstance();
-
- class GetBeanUtilsBeanThread extends Thread {
-
- BeanUtilsBean beanUtils;
- ConvertUtilsBean convertUtils;
- PropertyUtilsBean propertyUtils;
-
- GetBeanUtilsBeanThread() {}
-
- @Override
- public void run() {
- beanUtils = BeanUtilsBean.getInstance();
- convertUtils = ConvertUtilsBean.getInstance();
- propertyUtils = PropertyUtilsBean.getInstance();
- // XXX Log keeps a reference around!
- LogFactory.releaseAll();
- }
-
- @Override
- public String toString() {
- return "GetBeanUtilsBeanThread";
- }
- }
-
-
- GetBeanUtilsBeanThread thread = new GetBeanUtilsBeanThread();
- @SuppressWarnings("unused")
- final
- WeakReference threadWeakReference = new WeakReference<>(thread);
- thread.setContextClassLoader(loader);
-
- thread.start();
- thread.join();
-
- final WeakReference beanUtilsReference = new WeakReference<>(thread.beanUtils);
- final WeakReference propertyUtilsReference = new WeakReference<>(thread.propertyUtils);
- final WeakReference convertUtilsReference = new WeakReference<>(thread.convertUtils);
-
- assertNotNull("Weak reference released early (1)", loaderReference.get());
- assertNotNull("Weak reference released early (2)", beanUtilsReference.get());
- assertNotNull("Weak reference released early (3)", propertyUtilsReference.get());
- assertNotNull("Weak reference released early (4)", convertUtilsReference.get());
-
- // dereference strong references
- loader = null;
- thread.setContextClassLoader(null);
- thread = null;
-
- int iterations = 0;
- int bytz = 2;
- while(true) {
- BeanUtilsBean.getInstance();
- System.gc();
- if(iterations++ > MAX_GC_ITERATIONS){
- fail("Max iterations reached before resource released.");
- }
-
- if(
- loaderReference.get() == null &&
- beanUtilsReference.get() == null &&
- propertyUtilsReference.get() == null &&
- convertUtilsReference.get() == null) {
- break;
-
- }
- // create garbage:
- @SuppressWarnings("unused")
- final
- byte[] b = new byte[bytz];
- bytz = bytz * 2;
- }
- }
-
- /**
- * Tests whether difference instances are loaded by different
- * context classloaders.
- */
- public void testGetByContextClassLoader() throws Exception {
-
- class GetBeanUtilsBeanThread extends Thread {
-
- private final Signal signal;
-
- GetBeanUtilsBeanThread(final Signal signal) {
- this.signal = signal;
- }
-
- @Override
- public void run() {
- signal.setSignal(2);
- signal.setBean(BeanUtilsBean.getInstance());
- signal.setConvertUtils(ConvertUtilsBean.getInstance());
- signal.setPropertyUtils(PropertyUtilsBean.getInstance());
- }
-
- @Override
- public String toString() {
- return "GetBeanUtilsBeanThread";
- }
- }
-
- final Signal signal = new Signal();
- signal.setSignal(1);
-
- final GetBeanUtilsBeanThread thread = new GetBeanUtilsBeanThread(signal);
- thread.setContextClassLoader(new TestClassLoader());
-
- thread.start();
- thread.join();
-
- assertEquals("Signal not set by test thread", 2, signal.getSignal());
- assertTrue(
- "Different BeanUtilsBean instances per context classloader",
- BeanUtilsBean.getInstance() != signal.getBean());
- assertTrue(
- "Different ConvertUtilsBean instances per context classloader",
- ConvertUtilsBean.getInstance() != signal.getConvertUtils());
- assertTrue(
- "Different PropertyUtilsBean instances per context classloader",
- PropertyUtilsBean.getInstance() != signal.getPropertyUtils());
- }
-
-
- /**
- * Tests whether difference instances are loaded by different
- * context classloaders.
- */
- public void testContextClassLoaderLocal() throws Exception {
-
- class CCLLTesterThread extends Thread {
-
- private final Signal signal;
- private final ContextClassLoaderLocal ccll;
-
- CCLLTesterThread(final Signal signal, final ContextClassLoaderLocal ccll) {
- this.signal = signal;
- this.ccll = ccll;
- }
-
- @Override
- public void run() {
- ccll.set(new Integer(1789));
- signal.setSignal(2);
- signal.setMarkerObject(ccll.get());
- }
-
- @Override
- public String toString() {
- return "CCLLTesterThread";
- }
- }
-
- final ContextClassLoaderLocal ccll = new ContextClassLoaderLocal<>();
- ccll.set(new Integer(1776));
- assertEquals("Start thread sets value", new Integer(1776), ccll.get());
-
- final Signal signal = new Signal();
- signal.setSignal(1);
-
- final CCLLTesterThread thread = new CCLLTesterThread(signal, ccll);
- thread.setContextClassLoader(new TestClassLoader());
-
- thread.start();
- thread.join();
-
- assertEquals("Signal not set by test thread", 2, signal.getSignal());
- assertEquals("Second thread preserves value", new Integer(1776), ccll.get());
- assertEquals("Second thread gets value it set", new Integer(1789), signal.getMarkerObject());
- }
-
- /** Tests whether calls are independent for different classloaders */
- public void testContextClassloaderIndependence() throws Exception {
-
- class TestIndependenceThread extends Thread {
- private final Signal signal;
- private final PrimitiveBean bean;
-
- TestIndependenceThread(final Signal signal, final PrimitiveBean bean) {
- this.signal = signal;
- this.bean = bean;
- }
-
- @Override
- public void run() {
- try {
- signal.setSignal(3);
- ConvertUtils.register(new Converter() {
- @Override
- public T convert(final Class type, final Object value) {
- return ConvertUtils.primitiveToWrapper(type).cast(new Integer(9));
- }
- }, Integer.TYPE);
- BeanUtils.setProperty(bean, "int", new Integer(1));
- } catch (final Exception e) {
- e.printStackTrace();
- signal.setException(e);
- }
- }
-
- @Override
- public String toString() {
- return "TestIndependenceThread";
- }
- }
-
- final PrimitiveBean bean = new PrimitiveBean();
- BeanUtils.setProperty(bean, "int", new Integer(1));
- assertEquals("Wrong property value (1)", 1, bean.getInt());
-
- ConvertUtils.register(new Converter() {
- @Override
- public T convert(final Class type, final Object value) {
- return ConvertUtils.primitiveToWrapper(type).cast(new Integer(5));
- }
- }, Integer.TYPE);
- BeanUtils.setProperty(bean, "int", new Integer(1));
- assertEquals("Wrong property value(2)", 5, bean.getInt());
-
- final Signal signal = new Signal();
- signal.setSignal(1);
- final TestIndependenceThread thread = new TestIndependenceThread(signal, bean);
- thread.setContextClassLoader(new TestClassLoader());
-
- thread.start();
- thread.join();
-
- assertNull("Exception thrown by test thread:" + signal.getException(), signal.getException());
- assertEquals("Signal not set by test thread", 3, signal.getSignal());
- assertEquals("Wrong property value(3)", 9, bean.getInt());
-
- }
-
- /** Tests whether different threads can set beanutils instances correctly */
- public void testBeanUtilsBeanSetInstance() throws Exception {
-
- class SetInstanceTesterThread extends Thread {
-
- private final Signal signal;
- private final BeanUtilsBean bean;
-
- SetInstanceTesterThread(final Signal signal, final BeanUtilsBean bean) {
- this.signal = signal;
- this.bean = bean;
- }
-
- @Override
- public void run() {
- BeanUtilsBean.setInstance(bean);
- signal.setSignal(21);
- signal.setBean(BeanUtilsBean.getInstance());
- }
-
- @Override
- public String toString() {
- return "SetInstanceTesterThread";
- }
- }
-
- final Signal signal = new Signal();
- signal.setSignal(1);
-
- final BeanUtilsBean beanOne = new BeanUtilsBean();
- final BeanUtilsBean beanTwo = new BeanUtilsBean();
-
- final SetInstanceTesterThread thread = new SetInstanceTesterThread(signal, beanTwo);
- thread.setContextClassLoader(new TestClassLoader());
-
- BeanUtilsBean.setInstance(beanOne);
- assertEquals("Start thread gets right instance", beanOne, BeanUtilsBean.getInstance());
-
- thread.start();
- thread.join();
-
- assertEquals("Signal not set by test thread", 21, signal.getSignal());
- assertEquals("Second thread preserves value", beanOne, BeanUtilsBean.getInstance());
- assertEquals("Second thread gets value it set", beanTwo, signal.getBean());
- }
-
- /** Tests whether the unset method works*/
- public void testContextClassLoaderUnset() throws Exception {
- final BeanUtilsBean beanOne = new BeanUtilsBean();
- final ContextClassLoaderLocal ccll = new ContextClassLoaderLocal<>();
- ccll.set(beanOne);
- assertEquals("Start thread gets right instance", beanOne, ccll.get());
- ccll.unset();
- assertTrue("Unset works", !beanOne.equals(ccll.get()));
- }
-
- // ---- Auxillary classes
-
- class TestClassLoader extends ClassLoader {
- @Override
- public String toString() {
- return "TestClassLoader";
- }
- }
-
- class Signal {
- private Exception e;
- private int signal = 0;
- private BeanUtilsBean bean;
- private PropertyUtilsBean propertyUtils;
- private ConvertUtilsBean convertUtils;
- private Object marker;
-
- public Exception getException() {
- return e;
- }
-
- public void setException(final Exception e) {
- this.e = e;
- }
-
- public int getSignal() {
- return signal;
- }
-
- public void setSignal(final int signal) {
- this.signal = signal;
- }
-
- public Object getMarkerObject() {
- return marker;
- }
-
- public void setMarkerObject(final Object marker) {
- this.marker = marker;
- }
-
- public BeanUtilsBean getBean() {
- return bean;
- }
-
- public void setBean(final BeanUtilsBean bean) {
- this.bean = bean;
- }
-
- public PropertyUtilsBean getPropertyUtils() {
- return propertyUtils;
- }
-
- public void setPropertyUtils(final PropertyUtilsBean propertyUtils) {
- this.propertyUtils = propertyUtils;
- }
-
- public ConvertUtilsBean getConvertUtils() {
- return convertUtils;
- }
-
- public void setConvertUtils(final ConvertUtilsBean convertUtils) {
- this.convertUtils = convertUtils;
- }
- }
-}
-
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BenchBean.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BenchBean.java
deleted file mode 100644
index fc4ff3a4a..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BenchBean.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- * Plain old java bean (POJO) for microbenchmarks.
- *
- */
-
-public class BenchBean {
-
-
-
- /**
- * A boolean property.
- */
- private boolean booleanProperty = true;
-
- public boolean getBooleanProperty() {
- return booleanProperty;
- }
-
- public void setBooleanProperty(final boolean booleanProperty) {
- this.booleanProperty = booleanProperty;
- }
-
- /**
- * A byte property.
- */
- private byte byteProperty = (byte) 121;
-
- public byte getByteProperty() {
- return this.byteProperty;
- }
-
- public void setByteProperty(final byte byteProperty) {
- this.byteProperty = byteProperty;
- }
-
- /**
- * A double property.
- */
- private double doubleProperty = 321.0;
-
- public double getDoubleProperty() {
- return this.doubleProperty;
- }
-
- public void setDoubleProperty(final double doubleProperty) {
- this.doubleProperty = doubleProperty;
- }
-
- /**
- * A float property.
- */
- private float floatProperty = (float) 123.0;
-
- public float getFloatProperty() {
- return this.floatProperty;
- }
-
- public void setFloatProperty(final float floatProperty) {
- this.floatProperty = floatProperty;
- }
-
- /**
- * An integer property.
- */
- private int intProperty = 123;
-
- public int getIntProperty() {
- return this.intProperty;
- }
-
- public void setIntProperty(final int intProperty) {
- this.intProperty = intProperty;
- }
-
- /**
- * A long property.
- */
- private long longProperty = 321;
-
- public long getLongProperty() {
- return this.longProperty;
- }
-
- public void setLongProperty(final long longProperty) {
- this.longProperty = longProperty;
- }
-
- /**
- * A short property.
- */
- private short shortProperty = (short) 987;
-
- public short getShortProperty() {
- return this.shortProperty;
- }
-
- public void setShortProperty(final short shortProperty) {
- this.shortProperty = shortProperty;
- }
-
- /**
- * A String property.
- */
- private String stringProperty = "This is a string";
-
- public String getStringProperty() {
- return this.stringProperty;
- }
-
- public void setStringProperty(final String stringProperty) {
- this.stringProperty = stringProperty;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BetaBean.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BetaBean.java
deleted file mode 100644
index 09e76c206..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/BetaBean.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- */
-public class BetaBean extends AbstractChild {
-
- private String secret = "utah";
-
- public String getSecret() {
- return secret;
- }
-
- public void setNoGetterProperty(final String secret) {
- this.secret = secret;
- }
-
- public void setNoGetterMappedProperty(final String secret, final String key) {
- this.secret = "MAP:" + secret;
- }
-
- public BetaBean(final String name) {
- setName(name);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/Child.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/Child.java
deleted file mode 100644
index eb7ad71f7..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/Child.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-/**
- */
-public interface Child {
-
- String getName();
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/ConstructorUtilsTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/ConstructorUtilsTestCase.java
deleted file mode 100644
index 65da8ed1e..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/ConstructorUtilsTestCase.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Modifier;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
Test case for {@code ConstructorUtils}
- *
- */
-public class ConstructorUtilsTestCase extends TestCase {
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public ConstructorUtilsTestCase(final String name) {
- super(name);
- }
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
- super.setUp();
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
- return new TestSuite(ConstructorUtilsTestCase.class);
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
-
-
- public void testInvokeConstructor() throws Exception {
- {
- final Object obj = ConstructorUtils.invokeConstructor(TestBean.class,"TEST");
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals("TEST",((TestBean)obj).getStringProperty());
- }
- {
- final Object obj = ConstructorUtils.invokeConstructor(TestBean.class,new Float(17.3f));
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals(17.3f,((TestBean)obj).getFloatProperty(),0.0f);
- }
- }
-
- public void testInvokeConstructorNull() throws Exception {
- final Object obj = ConstructorUtils.invokeConstructor(TestBean.class, (Object) null);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- }
-
- public void testInvokeConstructorWithArgArray() throws Exception {
- final Object[] args = { new Float(17.3f), "TEST" };
- final Object obj = ConstructorUtils.invokeConstructor(TestBean.class,args);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals(17.3f,((TestBean)obj).getFloatProperty(),0.0f);
- assertEquals("TEST",((TestBean)obj).getStringProperty());
- }
-
- public void testInvokeConstructorWithTypeArray() throws Exception {
- {
- final Object[] args = { Boolean.TRUE, "TEST" };
- final Class>[] types = { Boolean.TYPE, String.class };
- final Object obj = ConstructorUtils.invokeConstructor(TestBean.class,args,types);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals(true,((TestBean)obj).getBooleanProperty());
- assertEquals("TEST",((TestBean)obj).getStringProperty());
- }
- {
- final Object[] args = { Boolean.TRUE, "TEST" };
- final Class>[] types = { Boolean.class, String.class };
- final Object obj = ConstructorUtils.invokeConstructor(TestBean.class,args,types);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals(true,((TestBean)obj).isBooleanSecond());
- assertEquals("TEST",((TestBean)obj).getStringProperty());
- }
- }
-
- public void testInvokeExactConstructor() throws Exception {
- {
- final Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class,"TEST");
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals("TEST",((TestBean)obj).getStringProperty());
- }
- {
- try {
- ConstructorUtils.invokeExactConstructor(TestBean.class,new Float(17.3f));
- fail("Expected NoSuchMethodException");
- } catch(final NoSuchMethodException e) {
- // expected
- }
- }
- {
- final Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class,Boolean.TRUE);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals(true,((TestBean)obj).isBooleanSecond());
- }
- }
-
- public void testInvokeExactConstructorWithNull() throws Exception {
- final Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class, (Object) null);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- }
-
- public void testInvokeExactConstructorWithArgArray() throws Exception {
- {
- final Object[] args = { new Float(17.3f), "TEST" };
- try {
- ConstructorUtils.invokeExactConstructor(TestBean.class,args);
- fail("Expected NoSuchMethodException");
- } catch(final NoSuchMethodException e) {
- // expected
- }
- }
- {
- final Object[] args = { Boolean.TRUE, "TEST" };
- final Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class,args);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals(true,((TestBean)obj).isBooleanSecond());
- assertEquals("TEST",((TestBean)obj).getStringProperty());
- }
- }
-
- public void testInvokeExactConstructorWithTypeArray() throws Exception {
- {
- final Object[] args = { Boolean.TRUE, "TEST" };
- final Class>[] types = { Boolean.TYPE, String.class };
- final Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class,args,types);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals(true,((TestBean)obj).getBooleanProperty());
- assertEquals("TEST",((TestBean)obj).getStringProperty());
- }
- {
- final Object[] args = { Boolean.TRUE, "TEST" };
- final Class>[] types = { Boolean.class, String.class };
- final Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class,args,types);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals(true,((TestBean)obj).isBooleanSecond());
- assertEquals("TEST",((TestBean)obj).getStringProperty());
- }
- {
- final Object[] args = { new Float(17.3f), "TEST" };
- final Class>[] types = { Float.TYPE, String.class };
- final Object obj = ConstructorUtils.invokeExactConstructor(TestBean.class,args,types);
- assertNotNull(obj);
- assertTrue(obj instanceof TestBean);
- assertEquals(17.3f,((TestBean)obj).getFloatProperty(),0.0f);
- assertEquals("TEST",((TestBean)obj).getStringProperty());
- }
- {
- final Object[] args = { new Float(17.3f), "TEST" };
- final Class>[] types = { Float.class, String.class };
- try {
- ConstructorUtils.invokeExactConstructor(TestBean.class,args,types);
- fail("Expected NoSuchMethodException");
- } catch(final NoSuchMethodException e) {
- // expected
- }
- }
- }
-
- public void testGetAccessibleConstructor() throws Exception {
- {
- final Constructor> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,String.class);
- assertNotNull(ctor);
- assertTrue(Modifier.isPublic(ctor.getModifiers()));
- }
- {
- final Constructor> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,Integer.class);
- assertNotNull(ctor);
- assertTrue(Modifier.isPublic(ctor.getModifiers()));
- }
- {
- final Constructor> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,Integer.TYPE);
- assertNull(ctor);
- }
- }
-
- public void testGetAccessibleConstructorWithTypeArray() throws Exception {
- {
- final Class>[] types = { Boolean.TYPE, String.class };
- final Constructor> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,types);
- assertNotNull(ctor);
- assertTrue(Modifier.isPublic(ctor.getModifiers()));
- }
- {
- final Class>[] types = { Boolean.TYPE, Boolean.TYPE, String.class };
- final Constructor> ctor = ConstructorUtils.getAccessibleConstructor(TestBean.class,types);
- assertNull(ctor);
- }
- }
-
- public void testGetAccessibleConstructorWithConstructorArg() throws Exception {
- {
- final Class>[] types = { Integer.class };
- final Constructor> c1 = TestBean.class.getConstructor(types);
- final Constructor> ctor = ConstructorUtils.getAccessibleConstructor(c1);
- assertNotNull(ctor);
- assertTrue(Modifier.isPublic(ctor.getModifiers()));
- }
- {
- final Class>[] types = { Integer.class };
- final Constructor> c1 = TestBean.class.getDeclaredConstructor(types);
- final Constructor> ctor = ConstructorUtils.getAccessibleConstructor(c1);
- assertNotNull(ctor);
- assertTrue(Modifier.isPublic(ctor.getModifiers()));
- }
- {
- final Class>[] types = { Integer.TYPE };
- final Constructor> c1 = TestBean.class.getDeclaredConstructor(types);
- final Constructor> ctor = ConstructorUtils.getAccessibleConstructor(c1);
- assertNull(ctor);
- }
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/ConvertUtilsTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/ConvertUtilsTestCase.java
deleted file mode 100644
index 4d107dd7f..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/ConvertUtilsTestCase.java
+++ /dev/null
@@ -1,688 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-
-import org.apache.commons.beanutils2.converters.DateConverter;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
- * Test Case for the ConvertUtils class.
- *
- *
- */
-
-public class ConvertUtilsTestCase extends TestCase {
-
-
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public ConvertUtilsTestCase(final String name) {
- super(name);
- }
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() {
-
- ConvertUtils.deregister();
-
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
- return new TestSuite(ConvertUtilsTestCase.class);
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- // No action required
- }
-
-
-
- /**
- * Negative String to primitive integer array tests.
- */
- public void testNegativeIntegerArray() {
-
- Object value = null;
- final int[] intArray = new int[0];
-
- value = ConvertUtils.convert((String) null, intArray.getClass());
- checkIntegerArray(value, intArray);
- value = ConvertUtils.convert("a", intArray.getClass());
- checkIntegerArray(value, intArray);
- value = ConvertUtils.convert("{ a }", intArray.getClass());
- checkIntegerArray(value, intArray);
- value = ConvertUtils.convert("1a3", intArray.getClass());
- checkIntegerArray(value, intArray);
- value = ConvertUtils.convert("{ 1a3 }", intArray.getClass());
- checkIntegerArray(value, intArray);
- value = ConvertUtils.convert("0,1a3", intArray.getClass());
- checkIntegerArray(value, intArray);
- value = ConvertUtils.convert("{ 0, 1a3 }", intArray.getClass());
- checkIntegerArray(value, intArray);
-
- }
-
- /**
- * Negative scalar conversion tests. These rely on the standard
- * default value conversions in ConvertUtils.
- */
- public void testNegativeScalar() {
-
- Object value = null;
-
- value = ConvertUtils.convert("foo", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("foo", Boolean.class);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("foo", Byte.TYPE);
- assertTrue(value instanceof Byte);
- assertEquals(((Byte) value).byteValue(), (byte) 0);
-
- value = ConvertUtils.convert("foo", Byte.class);
- assertTrue(value instanceof Byte);
- assertEquals(((Byte) value).byteValue(), (byte) 0);
-
- try {
- value = ConvertUtils.convert
- ("org.apache.commons.beanutils2.Undefined", Class.class);
- fail("Should have thrown conversion exception");
- } catch (final ConversionException e) {
- // Expected result
- }
-
- value = ConvertUtils.convert("foo", Double.TYPE);
- assertTrue(value instanceof Double);
- assertEquals(((Double) value).doubleValue(), 0.0,
- 0.005);
-
- value = ConvertUtils.convert("foo", Double.class);
- assertTrue(value instanceof Double);
- assertEquals(((Double) value).doubleValue(), 0.0, 0.005);
-
- value = ConvertUtils.convert("foo", Float.TYPE);
- assertTrue(value instanceof Float);
- assertEquals(((Float) value).floatValue(), (float) 0.0,
- (float) 0.005);
-
- value = ConvertUtils.convert("foo", Float.class);
- assertTrue(value instanceof Float);
- assertEquals(((Float) value).floatValue(), (float) 0.0,
- (float) 0.005);
-
- value = ConvertUtils.convert("foo", Integer.TYPE);
- assertTrue(value instanceof Integer);
- assertEquals(((Integer) value).intValue(), 0);
-
- value = ConvertUtils.convert("foo", Integer.class);
- assertTrue(value instanceof Integer);
- assertEquals(((Integer) value).intValue(), 0);
-
- value = ConvertUtils.convert("foo", Byte.TYPE);
- assertTrue(value instanceof Byte);
- assertEquals(((Byte) value).byteValue(), (byte) 0);
-
- value = ConvertUtils.convert("foo", Long.class);
- assertTrue(value instanceof Long);
- assertEquals(((Long) value).longValue(), 0);
-
- value = ConvertUtils.convert("foo", Short.TYPE);
- assertTrue(value instanceof Short);
- assertEquals(((Short) value).shortValue(), (short) 0);
-
- value = ConvertUtils.convert("foo", Short.class);
- assertTrue(value instanceof Short);
- assertEquals(((Short) value).shortValue(), (short) 0);
-
- }
-
- /**
- * Negative String to String array tests.
- */
- public void testNegativeStringArray() {
-
- Object value = null;
- final String[] stringArray = new String[0];
-
- value = ConvertUtils.convert((String) null, stringArray.getClass());
- checkStringArray(value, stringArray);
-
- }
-
- /**
- * Test conversion of object to string for arrays.
- */
- public void testObjectToStringArray() {
-
- final int[] intArray0 = new int[0];
- final int[] intArray1 = { 123 };
- final int[] intArray2 = { 123, 456 };
- final String[] stringArray0 = new String[0];
- final String[] stringArray1 = { "abc" };
- final String[] stringArray2 = { "abc", "def" };
-
- assertEquals("intArray0", null,
- ConvertUtils.convert(intArray0));
- assertEquals("intArray1", "123",
- ConvertUtils.convert(intArray1));
- assertEquals("intArray2", "123",
- ConvertUtils.convert(intArray2));
-
- assertEquals("stringArray0", null,
- ConvertUtils.convert(stringArray0));
- assertEquals("stringArray1", "abc",
- ConvertUtils.convert(stringArray1));
- assertEquals("stringArray2", "abc",
- ConvertUtils.convert(stringArray2));
-
- }
-
- /**
- * Test conversion of object to string for scalars.
- */
- public void testObjectToStringScalar() {
-
- assertEquals("Boolean->String", "false",
- ConvertUtils.convert(Boolean.FALSE));
- assertEquals("Boolean->String", "true",
- ConvertUtils.convert(Boolean.TRUE));
- assertEquals("Byte->String", "123",
- ConvertUtils.convert(new Byte((byte) 123)));
- assertEquals("Character->String", "a",
- ConvertUtils.convert(new Character('a')));
- assertEquals("Double->String", "123.0",
- ConvertUtils.convert(new Double(123.0)));
- assertEquals("Float->String", "123.0",
- ConvertUtils.convert(new Float((float) 123.0)));
- assertEquals("Integer->String", "123",
- ConvertUtils.convert(new Integer(123)));
- assertEquals("Long->String", "123",
- ConvertUtils.convert(new Long(123)));
- assertEquals("Short->String", "123",
- ConvertUtils.convert(new Short((short) 123)));
- assertEquals("String->String", "abc",
- ConvertUtils.convert("abc"));
- assertEquals("String->String null", null,
- ConvertUtils.convert(null));
-
- }
-
- /**
- * Positive array conversion tests.
- */
- public void testPositiveArray() {
-
- final String[] values1 = { "10", "20", "30" };
- Object value = ConvertUtils.convert(values1, Integer.TYPE);
- final int[] shape = new int[0];
- assertEquals(shape.getClass(), value.getClass());
- final int[] results1 = (int[]) value;
- assertEquals(results1[0], 10);
- assertEquals(results1[1], 20);
- assertEquals(results1[2], 30);
-
- final String[] values2 = { "100", "200", "300" };
- value = ConvertUtils.convert(values2, shape.getClass());
- assertEquals(shape.getClass(), value.getClass());
- final int[] results2 = (int[]) value;
- assertEquals(results2[0], 100);
- assertEquals(results2[1], 200);
- assertEquals(results2[2], 300);
-
- }
-
- /**
- * Positive String to primitive integer array tests.
- */
- public void testPositiveIntegerArray() {
-
- Object value = null;
- final int[] intArray = new int[0];
- final int[] intArray1 = new int[] { 0 };
- final int[] intArray2 = new int[] { 0, 10 };
-
- value = ConvertUtils.convert("{ }", intArray.getClass());
- checkIntegerArray(value, intArray);
-
- value = ConvertUtils.convert("0", intArray.getClass());
- checkIntegerArray(value, intArray1);
- value = ConvertUtils.convert(" 0 ", intArray.getClass());
- checkIntegerArray(value, intArray1);
- value = ConvertUtils.convert("{ 0 }", intArray.getClass());
- checkIntegerArray(value, intArray1);
-
- value = ConvertUtils.convert("0,10", intArray.getClass());
- checkIntegerArray(value, intArray2);
- value = ConvertUtils.convert("0 10", intArray.getClass());
- checkIntegerArray(value, intArray2);
- value = ConvertUtils.convert("{0,10}", intArray.getClass());
- checkIntegerArray(value, intArray2);
- value = ConvertUtils.convert("{0 10}", intArray.getClass());
- checkIntegerArray(value, intArray2);
- value = ConvertUtils.convert("{ 0, 10 }", intArray.getClass());
- checkIntegerArray(value, intArray2);
- value = ConvertUtils.convert("{ 0 10 }", intArray.getClass());
- checkIntegerArray(value, intArray2);
-
- }
-
- /**
- * Positive scalar conversion tests.
- */
- public void testPositiveScalar() {
-
- Object value = null;
-
- value = ConvertUtils.convert("true", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), true);
-
- value = ConvertUtils.convert("true", Boolean.class);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), true);
-
- value = ConvertUtils.convert("yes", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), true);
-
- value = ConvertUtils.convert("yes", Boolean.class);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), true);
-
- value = ConvertUtils.convert("y", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), true);
-
- value = ConvertUtils.convert("y", Boolean.class);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), true);
-
- value = ConvertUtils.convert("on", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), true);
-
- value = ConvertUtils.convert("on", Boolean.class);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), true);
-
- value = ConvertUtils.convert("false", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("false", Boolean.class);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("no", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("no", Boolean.class);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("n", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("n", Boolean.class);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("off", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("off", Boolean.class);
- assertTrue(value instanceof Boolean);
- assertEquals(((Boolean) value).booleanValue(), false);
-
- value = ConvertUtils.convert("123", Byte.TYPE);
- assertTrue(value instanceof Byte);
- assertEquals(((Byte) value).byteValue(), (byte) 123);
-
- value = ConvertUtils.convert("123", Byte.class);
- assertTrue(value instanceof Byte);
- assertEquals(((Byte) value).byteValue(), (byte) 123);
-
- value = ConvertUtils.convert("a", Character.TYPE);
- assertTrue(value instanceof Character);
- assertEquals(((Character) value).charValue(), 'a');
-
- value = ConvertUtils.convert("a", Character.class);
- assertTrue(value instanceof Character);
- assertEquals(((Character) value).charValue(), 'a');
-
- value = ConvertUtils.convert("java.lang.String", Class.class);
- assertTrue(value instanceof Class);
- assertEquals(String.class, value);
-
- value = ConvertUtils.convert("123.456", Double.TYPE);
- assertTrue(value instanceof Double);
- assertEquals(((Double) value).doubleValue(), 123.456, 0.005);
-
- value = ConvertUtils.convert("123.456", Double.class);
- assertTrue(value instanceof Double);
- assertEquals(((Double) value).doubleValue(), 123.456, 0.005);
-
- value = ConvertUtils.convert("123.456", Float.TYPE);
- assertTrue(value instanceof Float);
- assertEquals(((Float) value).floatValue(), (float) 123.456,
- (float) 0.005);
-
- value = ConvertUtils.convert("123.456", Float.class);
- assertTrue(value instanceof Float);
- assertEquals(((Float) value).floatValue(), (float) 123.456,
- (float) 0.005);
-
- value = ConvertUtils.convert("123", Integer.TYPE);
- assertTrue(value instanceof Integer);
- assertEquals(((Integer) value).intValue(), 123);
-
- value = ConvertUtils.convert("123", Integer.class);
- assertTrue(value instanceof Integer);
- assertEquals(((Integer) value).intValue(), 123);
-
- value = ConvertUtils.convert("123", Long.TYPE);
- assertTrue(value instanceof Long);
- assertEquals(((Long) value).longValue(), 123);
-
- value = ConvertUtils.convert("123", Long.class);
- assertTrue(value instanceof Long);
- assertEquals(((Long) value).longValue(), 123);
-
- value = ConvertUtils.convert("123", Short.TYPE);
- assertTrue(value instanceof Short);
- assertEquals(((Short) value).shortValue(), (short) 123);
-
- value = ConvertUtils.convert("123", Short.class);
- assertTrue(value instanceof Short);
- assertEquals(((Short) value).shortValue(), (short) 123);
-
- String input = null;
-
- input = "2002-03-17";
- value = ConvertUtils.convert(input, Date.class);
- assertTrue(value instanceof Date);
- assertEquals(input, value.toString());
-
- input = "20:30:40";
- value = ConvertUtils.convert(input, Time.class);
- assertTrue(value instanceof Time);
- assertEquals(input, value.toString());
-
- input = "2002-03-17 20:30:40.0";
- value = ConvertUtils.convert(input, Timestamp.class);
- assertTrue(value instanceof Timestamp);
- assertEquals(input, value.toString());
-
- }
-
- /**
- * Positive String to String array tests.
- */
- public void testPositiveStringArray() {
-
- Object value = null;
- final String[] stringArray = new String[0];
- final String[] stringArray1 = new String[]
- { "abc" };
- final String[] stringArray2 = new String[]
- { "abc", "de,f" };
-
- value = ConvertUtils.convert("", stringArray.getClass());
- checkStringArray(value, stringArray);
- value = ConvertUtils.convert(" ", stringArray.getClass());
- checkStringArray(value, stringArray);
- value = ConvertUtils.convert("{}", stringArray.getClass());
- checkStringArray(value, stringArray);
- value = ConvertUtils.convert("{ }", stringArray.getClass());
- checkStringArray(value, stringArray);
-
- value = ConvertUtils.convert("abc", stringArray.getClass());
- checkStringArray(value, stringArray1);
- value = ConvertUtils.convert("{abc}", stringArray.getClass());
- checkStringArray(value, stringArray1);
- value = ConvertUtils.convert("\"abc\"", stringArray.getClass());
- checkStringArray(value, stringArray1);
- value = ConvertUtils.convert("{\"abc\"}", stringArray.getClass());
- checkStringArray(value, stringArray1);
- value = ConvertUtils.convert("'abc'", stringArray.getClass());
- checkStringArray(value, stringArray1);
- value = ConvertUtils.convert("{'abc'}", stringArray.getClass());
- checkStringArray(value, stringArray1);
-
- value = ConvertUtils.convert("abc 'de,f'",
- stringArray.getClass());
- checkStringArray(value, stringArray2);
- value = ConvertUtils.convert("{abc, 'de,f'}",
- stringArray.getClass());
- checkStringArray(value, stringArray2);
- value = ConvertUtils.convert("\"abc\",\"de,f\"",
- stringArray.getClass());
- checkStringArray(value, stringArray2);
- value = ConvertUtils.convert("{\"abc\" 'de,f'}",
- stringArray.getClass());
- checkStringArray(value, stringArray2);
- value = ConvertUtils.convert("'abc' 'de,f'",
- stringArray.getClass());
- checkStringArray(value, stringArray2);
- value = ConvertUtils.convert("{'abc', \"de,f\"}",
- stringArray.getClass());
- checkStringArray(value, stringArray2);
-
- }
-
- public void testSeparateConvertInstances() throws Exception {
- final ConvertUtilsBean utilsOne = new ConvertUtilsBean();
- final ConvertUtilsBean utilsTwo = new ConvertUtilsBean();
-
- // make sure that the test work ok before anything's changed
- Object
- value = utilsOne.convert("true", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(
- "Standard conversion failed (1)",
- ((Boolean) value).booleanValue(),
- true);
-
- value = utilsTwo.convert("true", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(
- "Standard conversion failed (2)",
- ((Boolean) value).booleanValue(),
- true);
-
- // now register a test
-
- utilsOne.register(new ThrowExceptionConverter(), Boolean.TYPE);
- try {
-
- utilsOne.convert("true", Boolean.TYPE);
- fail("Register converter failed.");
-
- } catch (final PassTestException e) { /* This shows that the registration has worked */ }
-
- try {
- // nothing should have changed
- value = utilsTwo.convert("true", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(
- "Standard conversion failed (3)",
- ((Boolean) value).booleanValue(),
- true);
-
- } catch (final PassTestException e) {
- // This is a failure since utilsTwo should still have
- // standard converters registered
- fail("Registering a converter for an instance should not effect another instance.");
- }
-
- // nothing we'll test deregister
- utilsOne.deregister();
- value = utilsOne.convert("true", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals("Instance deregister failed.", ((Boolean) value).booleanValue(), true);
-
- value = utilsTwo.convert("true", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(
- "Standard conversion failed (4)",
- ((Boolean) value).booleanValue(),
- true);
- }
-
- public void testDeregisteringSingleConverter() throws Exception {
- // make sure that the test work ok before anything's changed
- final Object
- value = ConvertUtils.convert("true", Boolean.TYPE);
- assertTrue(value instanceof Boolean);
- assertEquals(
- "Standard conversion failed (1)",
- ((Boolean) value).booleanValue(),
- true);
-
- // we'll test deregister
- ConvertUtils.deregister(Boolean.TYPE);
- assertNull("Converter should be null",ConvertUtils.lookup(Boolean.TYPE));
-
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- // We need to use raw types in order to test legacy converters
- public void testConvertToString() throws Exception {
- final Converter dummyConverter = new Converter() {
- @Override
- public Object convert(final Class type, final Object value) {
- return value;
- }
- };
-
- final Converter fooConverter = new Converter() {
- @Override
- public Object convert(final Class type, final Object value) {
- return "Foo-Converter";
- }
- };
-
- final DateConverter dateConverter = new DateConverter();
- dateConverter.setLocale(Locale.US);
-
- final ConvertUtilsBean utils = new ConvertUtilsBean();
- utils.register(dateConverter, java.util.Date.class);
- utils.register(fooConverter, String.class);
-
- // Convert using registered DateConverter
- final java.util.Date today = new java.util.Date();
- final DateFormat fmt = new SimpleDateFormat("M/d/yy"); /* US Short Format */
- final String expected = fmt.format(today);
- assertEquals("DateConverter M/d/yy", expected, utils.convert(today, String.class));
-
- // Date converter doesn't do String conversion - use String Converter
- utils.register(dummyConverter, java.util.Date.class);
- assertEquals("Date Converter doesn't do String conversion", "Foo-Converter", utils.convert(today, String.class));
-
- // No registered Date converter - use String Converter
- utils.deregister(java.util.Date.class);
- assertEquals("No registered Date converter", "Foo-Converter", utils.convert(today, String.class));
-
- // String Converter doesn't do Strings!!!
- utils.register(dummyConverter, String.class);
- assertEquals("String Converter doesn't do Strings!!!", today.toString(), utils.convert(today, String.class));
-
- // No registered Date or String converter - use Object's toString()
- utils.deregister(String.class);
- assertEquals("Object's toString()", today.toString(), utils.convert(today, String.class));
-
- }
-
- /**
- * Tests a conversion to an unsupported target type.
- */
- public void testConvertUnsupportedTargetType() {
- final ConvertUtilsBean utils = new ConvertUtilsBean();
- final Object value = "A test value";
- assertSame("Got different object", value,
- utils.convert(value, getClass()));
- }
-
-
-
- private void checkIntegerArray(final Object value, final int[] intArray) {
-
- assertNotNull("Returned value is not null", value);
- assertEquals("Returned value is int[]",
- intArray.getClass(), value.getClass());
- final int[] results = (int[]) value;
- assertEquals("Returned array length", intArray.length, results.length);
- for (int i = 0; i < intArray.length; i++) {
- assertEquals("Returned array value " + i,
- intArray[i], results[i]);
- }
-
- }
-
- private void checkStringArray(final Object value, final String[] stringArray) {
-
- assertNotNull("Returned value is not null", value);
- assertEquals("Returned value is String[]",
- stringArray.getClass(), value.getClass());
- final String[] results = (String[]) value;
- assertEquals("Returned array length",
- stringArray.length, results.length);
- for (int i = 0; i < stringArray.length; i++) {
- assertEquals("Returned array value " + i,
- stringArray[i], results[i]);
- }
-
- }
-
-}
-
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DefaultIntrospectionContextTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DefaultIntrospectionContextTestCase.java
deleted file mode 100644
index 86dc19776..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DefaultIntrospectionContextTestCase.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.util.HashSet;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-/**
- * Test class for {@code IntrospectionContext}.
- *
- */
-public class DefaultIntrospectionContextTestCase extends TestCase {
- /** Constant for the name of a property. */
- private static final String PROP = "foo";
-
- /** The context to be tested. */
- private DefaultIntrospectionContext context;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- context = new DefaultIntrospectionContext(getClass());
- }
-
- /**
- * Creates a property descriptor object for a property with the given name.
- *
- * @param propName the property name
- * @return the descriptor for this property
- */
- private static PropertyDescriptor createDescriptor(final String propName) {
- try {
- return new PropertyDescriptor(propName,
- DefaultIntrospectionContextTestCase.class, null, null);
- } catch (final IntrospectionException e) {
- throw new IllegalStateException("Unexpected exception: " + e);
- }
- }
-
- /**
- * Tests a newly created instance.
- */
- public void testInit() {
- assertEquals("Wrong current class", getClass(),
- context.getTargetClass());
- assertTrue("Got property names", context.propertyNames().isEmpty());
- }
-
- /**
- * Tests whether a property descriptor can be added.
- */
- public void testAddPropertyDescriptor() {
- final PropertyDescriptor desc = createDescriptor(PROP);
- context.addPropertyDescriptor(desc);
- assertTrue("Property not found", context.hasProperty(PROP));
- assertSame("Wrong descriptor", desc,
- context.getPropertyDescriptor(PROP));
- }
-
- /**
- * Tries to add a null descriptor.
- */
- public void testAddPropertyDescriptorNull() {
- try {
- context.addPropertyDescriptor(null);
- fail("Could add null descriptor!");
- } catch (final IllegalArgumentException iex) {
- // ok
- }
- }
-
- /**
- * Tests whether multiple descriptors can be added.
- */
- public void testAddPropertyDescriptors() {
- final int count = 4;
- final PropertyDescriptor[] descs = new PropertyDescriptor[count];
- final Set descSet = new HashSet<>();
- for (int i = 0; i < count; i++) {
- descs[i] = createDescriptor(PROP + i);
- descSet.add(descs[i]);
- }
- context.addPropertyDescriptors(descs);
- final PropertyDescriptor d = createDescriptor(PROP);
- context.addPropertyDescriptor(d);
- descSet.add(d);
- final Set names = context.propertyNames();
- assertEquals("Wrong number of property names", count + 1, names.size());
- assertTrue("Property not found: " + PROP, names.contains(PROP));
- for (int i = 0; i < count; i++) {
- assertTrue("Property not found: " + (PROP + i),
- names.contains(PROP + i));
- }
- final PropertyDescriptor[] addedDescs = context.getPropertyDescriptors();
- assertEquals("Wrong number of added descriptors", count + 1,
- addedDescs.length);
- for (final PropertyDescriptor pd : addedDescs) {
- assertTrue("Unexpected descriptor: " + pd, descSet.remove(pd));
- }
- }
-
- /**
- * Tries to add a null array with property descriptors.
- */
- public void testAddPropertyDescriptorsNull() {
- try {
- context.addPropertyDescriptors(null);
- fail("Could add a null array with descriptors!");
- } catch (final IllegalArgumentException iex) {
- // ok
- }
- }
-
- /**
- * Tests hasProperty() if the expected result is false.
- */
- public void testHasPropertyFalse() {
- assertFalse("Wrong result (1)", context.hasProperty(PROP));
- context.addPropertyDescriptor(createDescriptor(PROP));
- assertFalse("Wrong result (2)", context.hasProperty("other"));
- }
-
- /**
- * Tests getPropertyDescriptor() if the property name is unknown.
- */
- public void testGetPropertyDescriptorUnknown() {
- assertNull("Got a property (1)", context.getPropertyDescriptor(PROP));
- context.addPropertyDescriptor(createDescriptor(PROP));
- assertNull("Got a property (2)", context.getPropertyDescriptor("other"));
- }
-
- /**
- * Tests that the set with property names cannot be changed.
- */
- public void testPropertyNamesModify() {
- final Set names = context.propertyNames();
- try {
- names.add(PROP);
- fail("Could modify property names set!");
- } catch (final UnsupportedOperationException uex) {
- // ok
- }
- }
-
- /**
- * Tests whether a descriptor can be removed.
- */
- public void testRemovePropertyDescriptor() {
- context.addPropertyDescriptor(createDescriptor(PROP));
- context.removePropertyDescriptor(PROP);
- assertTrue("Got property names", context.propertyNames().isEmpty());
- assertEquals("Got descriptors", 0,
- context.getPropertyDescriptors().length);
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaBeanMapDecoratorTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaBeanMapDecoratorTestCase.java
deleted file mode 100644
index 7ea8fa0f4..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaBeanMapDecoratorTestCase.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
Test Case for the {@code DynaBeanMapDecorator} implementation class.
- *
- */
-@SuppressWarnings("deprecation")
-public class DynaBeanMapDecoratorTestCase extends TestCase {
-
- private static final DynaProperty stringProp = new DynaProperty("stringProp", String.class);
- private static final DynaProperty nullProp = new DynaProperty("nullProp", String.class);
- private static final DynaProperty intProp = new DynaProperty("intProp", Integer.class);
- private static final DynaProperty dateProp = new DynaProperty("dateProp", Date.class);
- private static final DynaProperty mapProp = new DynaProperty("mapProp", Map.class);
- private static final DynaProperty[] properties = new DynaProperty[] {
- stringProp, nullProp, intProp, dateProp, mapProp};
- private static final DynaClass dynaClass = new BasicDynaClass("testDynaClass", BasicDynaBean.class, properties);
-
- private static String stringVal = "somevalue";
- private static Integer intVal = new Integer(5);
- private static Date dateVal = new Date();
- private final Map mapVal = new HashMap<>();
-
- private final Object[] values = new Object[] {stringVal, null, intVal, dateVal, mapVal};
-
- private BasicDynaBean dynaBean;
- private Map decoratedMap;
- private Map modifiableMap;
- private static final Map emptyMap = new DynaBeanPropertyMapDecorator(new BasicDynaBean(new BasicDynaClass()));
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public DynaBeanMapDecoratorTestCase(final String name) {
- super(name);
- }
-
-
-
- /**
- * Run thus Test
- */
- public static void main(final String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
- return new TestSuite(DynaBeanMapDecoratorTestCase.class);
- }
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
-
- mapVal.clear();
- mapVal.put("key1", "key1Value");
- mapVal.put("key2", "key2Value");
-
- // Initialize DynaBean and properties
- dynaBean = new BasicDynaBean(dynaClass);
- for (int i = 0; i < properties.length; i++) {
- dynaBean.set(properties[i].getName(), values[i]);
- }
-
- // Create decorated Maps
- decoratedMap = new DynaBeanPropertyMapDecorator(dynaBean);
- modifiableMap = new DynaBeanPropertyMapDecorator(dynaBean, false);
-
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- dynaBean = null;
- decoratedMap = null;
- modifiableMap = null;
- }
-
-
-
- /**
- * Test isReadOnly() method
- */
- public void testIsReadOnly() {
- assertTrue("decoratedMap true", ((DynaBeanPropertyMapDecorator)decoratedMap).isReadOnly());
- assertFalse("modifiableMap false", ((DynaBeanPropertyMapDecorator)modifiableMap).isReadOnly());
- }
-
- /**
- * Test clear() method
- */
- public void testClear() {
- try {
- decoratedMap.clear();
- fail("decoratedMap.clear()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
- try {
- modifiableMap.clear();
- fail("modifiableMap.clear()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
- }
-
- /**
- * Test containsKey() method
- */
- public void testContainsKey() {
- assertTrue("decoratedMap true", decoratedMap.containsKey(stringProp.getName()));
- assertFalse("decoratedMap false", decoratedMap.containsKey("xyz"));
- }
-
- /**
- * Test containsValue() method
- */
- public void testContainsValue() {
- assertTrue("decoratedMap true", decoratedMap.containsValue(stringVal));
- assertFalse("decoratedMap false", decoratedMap.containsValue("xyz"));
- }
-
- /**
- * Test entrySet() method
- */
- public void testEntrySet() {
- final Set> set = modifiableMap.entrySet();
-
- // Check the Set can't be modified
- final Map m = new HashMap<>();
- m.put("key", "value");
- checkUnmodifiable("entrySet()", set, m.entrySet().iterator().next());
-
- assertEquals("entrySet size", properties.length, set.size());
-
- final Iterator> iterator = set.iterator();
- final List namesList = new ArrayList<>();
- int i = 0;
- while (iterator.hasNext()) {
- final Map.Entry entry = iterator.next();
- final String name = entry.getKey();
- namesList.add(name);
- final Object expectValue = decoratedMap.get(name);
- assertEquals("entrySet("+i+") val", expectValue, entry.getValue());
- i++;
- }
- for (int j = 0; j < properties.length; j++) {
- final String name = properties[j].getName();
- assertTrue("Check property[" + j + "]", namesList.contains(name));
- }
- }
-
- /**
- * Test get() method
- */
- public void testGet() {
-
- // valid property name
- assertEquals("decoratedMap valid", stringVal, decoratedMap.get(stringProp.getName()));
-
- // invalid property name
- try {
- decoratedMap.get("xyz");
- fail("decoratedMap invalid");
- } catch(final IllegalArgumentException ignore) {
- // expected result
- }
- }
-
- /**
- * Test isEmpty() method
- */
- public void testIsEmpty() {
- assertTrue("Empty", emptyMap.isEmpty());
- assertFalse("Not Empty", decoratedMap.isEmpty());
- }
-
- /**
- * Test keySet() method
- */
- public void testKeySet() {
- final Set set = modifiableMap.keySet();
-
- // Check the Set can't be modified
- checkUnmodifiable("keySet()", set, "xyz");
-
- assertEquals("keySet size", properties.length, set.size());
-
- for (int i = 0; i < properties.length; i++) {
- final String name = properties[i].getName();
- assertTrue("Check property[" + i + "]", set.contains(name));
- }
- }
-
- /**
- * Test put() method
- */
- public void testPut() {
-
- final String newValue = "ABC";
-
- // Test read only
- try {
- decoratedMap.put(stringProp.getName(), newValue);
- fail("Not read only");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
-
- // Test Writable
- assertEquals("modifiableMap put", stringVal, modifiableMap.put(stringProp.getName(), newValue));
- assertEquals("dynaBean get", newValue, dynaBean.get(stringProp.getName()));
- assertEquals("modifiableMap get", newValue, modifiableMap.get(stringProp.getName()));
- }
-
- /**
- * Test putAll() method
- */
- public void testPutAll() {
-
- final String newValue = "ABC";
- final Map newMap = new HashMap<>();
- newMap.put(stringProp.getName(), newValue);
-
- // Test read only
- try {
- decoratedMap.putAll(newMap);
- fail("Not read only");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
-
- // Test Writable
- assertEquals("before putAll", stringVal, dynaBean.get(stringProp.getName()));
- modifiableMap.putAll(newMap);
- assertEquals("after putAll", newValue, dynaBean.get(stringProp.getName()));
- }
-
- /**
- * Test remove() method
- */
- public void testRemove() {
- try {
- decoratedMap.remove(stringProp.getName());
- fail("decoratedMap.remove()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
- try {
- modifiableMap.remove(stringProp.getName());
- fail("modifiableMap.remove()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
- }
-
- /**
- * Test size() method
- */
- public void testSize() {
- assertEquals("Empty", 0, emptyMap.size());
- assertEquals("Not Empty", properties.length, decoratedMap.size());
- }
-
- /**
- * Test values() method
- */
- public void testValues() {
- final Collection collection = modifiableMap.values();
-
- // Check the Collection can't be modified
- checkUnmodifiable("values()", collection, "xyz");
-
- assertEquals("values size", values.length, collection.size());
-
- // Collection should be ordered in same sequence as properties
- final Iterator iterator = collection.iterator();
- int i = 0;
- while (iterator.hasNext()) {
- assertEquals("values("+i+")", values[i], iterator.next());
- i++;
- }
- }
-
- /**
- * Check that a Collection is not modifiable
- */
- private void checkUnmodifiable(final String desc, final Collection collection, final E addElem) {
- // Check can't add()
- try {
- collection.add(addElem);
- fail(desc + ".add()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
-
- // Check can't addAll()
- final List list = new ArrayList<>(1);
- list.add(addElem);
- try {
- collection.addAll(list);
- fail(desc + ".addAll()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
-
- // Check can't clear()
- try {
- collection.clear();
- fail(desc + ".clear()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
-
- // Check can't remove()
- try {
- collection.remove("abc");
- fail(desc + ".remove()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
-
- // Check can't removeAll()
- try {
- collection.removeAll(list);
- fail(desc + ".removeAll()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
-
- // Check can't retainAll()
- try {
- collection.retainAll(list);
- fail(desc + ".retainAll()");
- } catch(final UnsupportedOperationException ignore) {
- // expected result
- }
- }
-}
\ No newline at end of file
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaBeanUtilsTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaBeanUtilsTestCase.java
deleted file mode 100644
index f346618c8..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaBeanUtilsTestCase.java
+++ /dev/null
@@ -1,1220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test case for BeanUtils when the underlying bean is actually a DynaBean.
- *
- */
-
-public class DynaBeanUtilsTestCase extends TestCase {
-
-
-
- /**
- * The basic test bean for each test.
- */
- protected DynaBean bean = null;
-
- /**
- * The nested bean pointed at by the "nested" property.
- */
- protected TestBean nested = null;
-
- /**
- * The set of properties that should be described.
- */
- protected String[] describes =
- { "booleanProperty",
- "booleanSecond",
- "byteProperty",
- "doubleProperty",
- "dupProperty",
- "floatProperty",
- "intArray",
- "intIndexed",
- "intProperty",
- "listIndexed",
- "longProperty",
- "mapProperty",
- "mappedProperty",
- "mappedIntProperty",
- "nested",
- "nullProperty",
- // "readOnlyProperty",
- "shortProperty",
- "stringArray",
- "stringIndexed",
- "stringProperty"
- };
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public DynaBeanUtilsTestCase(final String name) {
-
- super(name);
-
- }
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
-
- ConvertUtils.deregister();
-
- // Instantiate a new DynaBean instance
- final DynaClass dynaClass = createDynaClass();
- bean = dynaClass.newInstance();
-
- // Initialize the DynaBean's property values (like TestBean)
- bean.set("booleanProperty", new Boolean(true));
- bean.set("booleanSecond", new Boolean(true));
- bean.set("byteProperty", new Byte((byte) 121));
- bean.set("doubleProperty", new Double(321.0));
- bean.set("floatProperty", new Float((float) 123.0));
- final String[] dupProperty = { "Dup 0", "Dup 1", "Dup 2", "Dup 3", "Dup 4"};
- bean.set("dupProperty", dupProperty);
- final int[] intArray = { 0, 10, 20, 30, 40 };
- bean.set("intArray", intArray);
- final int[] intIndexed = { 0, 10, 20, 30, 40 };
- bean.set("intIndexed", intIndexed);
- bean.set("intProperty", new Integer(123));
- final List listIndexed = new ArrayList<>();
- listIndexed.add("String 0");
- listIndexed.add("String 1");
- listIndexed.add("String 2");
- listIndexed.add("String 3");
- listIndexed.add("String 4");
- bean.set("listIndexed", listIndexed);
- bean.set("longProperty", new Long(321));
- final HashMap mapProperty = new HashMap<>();
- mapProperty.put("First Key", "First Value");
- mapProperty.put("Second Key", "Second Value");
- bean.set("mapProperty", mapProperty);
- final HashMap mappedProperty = new HashMap<>();
- mappedProperty.put("First Key", "First Value");
- mappedProperty.put("Second Key", "Second Value");
- bean.set("mappedProperty", mappedProperty);
- final HashMap mappedIntProperty = new HashMap<>();
- mappedIntProperty.put("One", new Integer(1));
- mappedIntProperty.put("Two", new Integer(2));
- bean.set("mappedIntProperty", mappedIntProperty);
- nested = new TestBean();
- bean.set("nested", nested);
- // Property "nullProperty" is not initialized, so it should return null
- bean.set("shortProperty", new Short((short) 987));
- final String[] stringArray =
- { "String 0", "String 1", "String 2", "String 3", "String 4" };
- bean.set("stringArray", stringArray);
- final String[] stringIndexed =
- { "String 0", "String 1", "String 2", "String 3", "String 4" };
- bean.set("stringIndexed", stringIndexed);
- bean.set("stringProperty", "This is a string");
-
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
-
- return new TestSuite(DynaBeanUtilsTestCase.class);
-
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
-
- bean = null;
- nested = null;
-
- }
-
-
-
- /**
- * Test the cloneBean() method from a DynaBean.
- */
- public void testCloneDynaBean() {
-
- // Set up an origin bean with customized properties
- final DynaClass dynaClass = DynaBeanUtilsTestCase.createDynaClass();
- DynaBean orig = null;
- try {
- orig = dynaClass.newInstance();
- } catch (final Exception e) {
- fail("newInstance(): " + e);
- }
- orig.set("booleanProperty", Boolean.FALSE);
- orig.set("byteProperty", new Byte((byte)111));
- orig.set("doubleProperty", new Double(333.33));
- orig.set("dupProperty", new String[] { "New 0", "New 1", "New 2" });
- orig.set("intArray", new int[] { 100, 200, 300 });
- orig.set("intProperty", new Integer(333));
- orig.set("longProperty", new Long(3333));
- orig.set("shortProperty", new Short((short) 33));
- orig.set("stringArray", new String[] { "New 0", "New 1" });
- orig.set("stringProperty", "Custom string");
-
- // Copy the origin bean to our destination test bean
- DynaBean clonedBean = null;
- try {
- clonedBean = (DynaBean) BeanUtils.cloneBean(orig);
- } catch (final Exception e) {
- fail("Threw exception: " + e);
- }
-
- // Validate the results for scalar properties
- assertEquals("Cloned boolean property",
- false,
- ((Boolean) clonedBean.get("booleanProperty")).booleanValue());
- assertEquals("Cloned byte property",
- (byte) 111,
- ((Byte) clonedBean.get("byteProperty")).byteValue());
- assertEquals("Cloned double property",
- 333.33,
- ((Double) clonedBean.get("doubleProperty")).doubleValue(),
- 0.005);
- assertEquals("Cloned int property",
- 333,
- ((Integer) clonedBean.get("intProperty")).intValue());
- assertEquals("Cloned long property",
- 3333,
- ((Long) clonedBean.get("longProperty")).longValue());
- assertEquals("Cloned short property",
- (short) 33,
- ((Short) clonedBean.get("shortProperty")).shortValue());
- assertEquals("Cloned string property",
- "Custom string",
- (String) clonedBean.get("stringProperty"));
-
- // Validate the results for array properties
- final String[] dupProperty = (String[]) clonedBean.get("dupProperty");
- assertNotNull("dupProperty present", dupProperty);
- assertEquals("dupProperty length", 3, dupProperty.length);
- assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
- assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
- assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
- final int[] intArray = (int[]) clonedBean.get("intArray");
- assertNotNull("intArray present", intArray);
- assertEquals("intArray length", 3, intArray.length);
- assertEquals("intArray[0]", 100, intArray[0]);
- assertEquals("intArray[1]", 200, intArray[1]);
- assertEquals("intArray[2]", 300, intArray[2]);
- final String[] stringArray = (String[]) clonedBean.get("stringArray");
- assertNotNull("stringArray present", stringArray);
- assertEquals("stringArray length", 2, stringArray.length);
- assertEquals("stringArray[0]", "New 0", stringArray[0]);
- assertEquals("stringArray[1]", "New 1", stringArray[1]);
-
- }
-
- /**
- * Test the copyProperties() method from a DynaBean.
- */
- public void testCopyPropertiesDynaBean() {
-
- // Set up an origin bean with customized properties
- final DynaClass dynaClass = DynaBeanUtilsTestCase.createDynaClass();
- DynaBean orig = null;
- try {
- orig = dynaClass.newInstance();
- } catch (final Exception e) {
- fail("newInstance(): " + e);
- }
- orig.set("booleanProperty", Boolean.FALSE);
- orig.set("byteProperty", new Byte((byte)111));
- orig.set("doubleProperty", new Double(333.33));
- orig.set("dupProperty", new String[] { "New 0", "New 1", "New 2" });
- orig.set("intArray", new int[] { 100, 200, 300 });
- orig.set("intProperty", new Integer(333));
- orig.set("longProperty", new Long(3333));
- orig.set("shortProperty", new Short((short) 33));
- orig.set("stringArray", new String[] { "New 0", "New 1" });
- orig.set("stringProperty", "Custom string");
-
- // Copy the origin bean to our destination test bean
- try {
- BeanUtils.copyProperties(bean, orig);
- } catch (final Exception e) {
- fail("Threw exception: " + e);
- }
-
- // Validate the results for scalar properties
- assertEquals("Copied boolean property",
- false,
- ((Boolean) bean.get("booleanProperty")).booleanValue());
- assertEquals("Copied byte property",
- (byte) 111,
- ((Byte) bean.get("byteProperty")).byteValue());
- assertEquals("Copied double property",
- 333.33,
- ((Double) bean.get("doubleProperty")).doubleValue(),
- 0.005);
- assertEquals("Copied int property",
- 333,
- ((Integer) bean.get("intProperty")).intValue());
- assertEquals("Copied long property",
- 3333,
- ((Long) bean.get("longProperty")).longValue());
- assertEquals("Copied short property",
- (short) 33,
- ((Short) bean.get("shortProperty")).shortValue());
- assertEquals("Copied string property",
- "Custom string",
- (String) bean.get("stringProperty"));
-
- // Validate the results for array properties
- final String[] dupProperty = (String[]) bean.get("dupProperty");
- assertNotNull("dupProperty present", dupProperty);
- assertEquals("dupProperty length", 3, dupProperty.length);
- assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
- assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
- assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
- final int[] intArray = (int[]) bean.get("intArray");
- assertNotNull("intArray present", intArray);
- assertEquals("intArray length", 3, intArray.length);
- assertEquals("intArray[0]", 100, intArray[0]);
- assertEquals("intArray[1]", 200, intArray[1]);
- assertEquals("intArray[2]", 300, intArray[2]);
- final String[] stringArray = (String[]) bean.get("stringArray");
- assertNotNull("stringArray present", stringArray);
- assertEquals("stringArray length", 2, stringArray.length);
- assertEquals("stringArray[0]", "New 0", stringArray[0]);
- assertEquals("stringArray[1]", "New 1", stringArray[1]);
-
- }
-
- /**
- * Test copyProperties() when the origin is a a {@code Map}.
- */
- public void testCopyPropertiesMap() {
-
- final Map map = new HashMap<>();
- map.put("booleanProperty", "false");
- map.put("byteProperty", "111");
- map.put("doubleProperty", "333.0");
- map.put("dupProperty", new String[] { "New 0", "New 1", "New 2" });
- map.put("floatProperty", "222.0");
- map.put("intArray", new String[] { "0", "100", "200" });
- map.put("intProperty", "111");
- map.put("longProperty", "444");
- map.put("shortProperty", "555");
- map.put("stringProperty", "New String Property");
-
- try {
- BeanUtils.copyProperties(bean, map);
- } catch (final Throwable t) {
- fail("Threw " + t.toString());
- }
-
- // Scalar properties
- assertEquals("booleanProperty", false,
- ((Boolean) bean.get("booleanProperty")).booleanValue());
- assertEquals("byteProperty", (byte) 111,
- ((Byte) bean.get("byteProperty")).byteValue());
- assertEquals("doubleProperty", 333.0,
- ((Double) bean.get("doubleProperty")).doubleValue(),
- 0.005);
- assertEquals("floatProperty", (float) 222.0,
- ((Float) bean.get("floatProperty")).floatValue(),
- (float) 0.005);
- assertEquals("intProperty", 111,
- ((Integer) bean.get("intProperty")).intValue());
- assertEquals("longProperty", 444,
- ((Long) bean.get("longProperty")).longValue());
- assertEquals("shortProperty", (short) 555,
- ((Short) bean.get("shortProperty")).shortValue());
- assertEquals("stringProperty", "New String Property",
- (String) bean.get("stringProperty"));
-
- // Indexed Properties
- final String[] dupProperty = (String[]) bean.get("dupProperty");
- assertNotNull("dupProperty present", dupProperty);
- assertEquals("dupProperty length", 3, dupProperty.length);
- assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
- assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
- assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
- final int[] intArray = (int[]) bean.get("intArray");
- assertNotNull("intArray present", intArray);
- assertEquals("intArray length", 3, intArray.length);
- assertEquals("intArray[0]", 0, intArray[0]);
- assertEquals("intArray[1]", 100, intArray[1]);
- assertEquals("intArray[2]", 200, intArray[2]);
-
- }
-
- /**
- * Test the copyProperties() method from a standard JavaBean.
- */
- public void testCopyPropertiesStandard() {
-
- // Set up an origin bean with customized properties
- final TestBean orig = new TestBean();
- orig.setBooleanProperty(false);
- orig.setByteProperty((byte) 111);
- orig.setDoubleProperty(333.33);
- orig.setDupProperty(new String[] { "New 0", "New 1", "New 2" });
- orig.setIntArray(new int[] { 100, 200, 300 });
- orig.setIntProperty(333);
- orig.setLongProperty(3333);
- orig.setShortProperty((short) 33);
- orig.setStringArray(new String[] { "New 0", "New 1" });
- orig.setStringProperty("Custom string");
-
- // Copy the origin bean to our destination test bean
- try {
- BeanUtils.copyProperties(bean, orig);
- } catch (final Exception e) {
- fail("Threw exception: " + e);
- }
-
- // Validate the results for scalar properties
- assertEquals("Copied boolean property",
- false,
- ((Boolean) bean.get("booleanProperty")).booleanValue());
- assertEquals("Copied byte property",
- (byte) 111,
- ((Byte) bean.get("byteProperty")).byteValue());
- assertEquals("Copied double property",
- 333.33,
- ((Double) bean.get("doubleProperty")).doubleValue(),
- 0.005);
- assertEquals("Copied int property",
- 333,
- ((Integer) bean.get("intProperty")).intValue());
- assertEquals("Copied long property",
- 3333,
- ((Long) bean.get("longProperty")).longValue());
- assertEquals("Copied short property",
- (short) 33,
- ((Short) bean.get("shortProperty")).shortValue());
- assertEquals("Copied string property",
- "Custom string",
- (String) bean.get("stringProperty"));
-
- // Validate the results for array properties
- final String[] dupProperty = (String[]) bean.get("dupProperty");
- assertNotNull("dupProperty present", dupProperty);
- assertEquals("dupProperty length", 3, dupProperty.length);
- assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
- assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
- assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
- final int[] intArray = (int[]) bean.get("intArray");
- assertNotNull("intArray present", intArray);
- assertEquals("intArray length", 3, intArray.length);
- assertEquals("intArray[0]", 100, intArray[0]);
- assertEquals("intArray[1]", 200, intArray[1]);
- assertEquals("intArray[2]", 300, intArray[2]);
- final String[] stringArray = (String[]) bean.get("stringArray");
- assertNotNull("stringArray present", stringArray);
- assertEquals("stringArray length", 2, stringArray.length);
- assertEquals("stringArray[0]", "New 0", stringArray[0]);
- assertEquals("stringArray[1]", "New 1", stringArray[1]);
-
- }
-
- /**
- * Test the describe() method.
- */
- public void testDescribe() {
-
- Map map = null;
- try {
- map = PropertyUtils.describe(bean);
- } catch (final Exception e) {
- fail("Threw exception " + e);
- }
-
- // Verify existence of all the properties that should be present
- for (final String describe : describes) {
- assertTrue("Property '" + describe + "' is present",
- map.containsKey(describe));
- }
- assertTrue("Property 'writeOnlyProperty' is not present",
- !map.containsKey("writeOnlyProperty"));
-
- // Verify the values of scalar properties
- assertEquals("Value of 'booleanProperty'",
- Boolean.TRUE,
- map.get("booleanProperty"));
- assertEquals("Value of 'byteProperty'",
- new Byte((byte) 121),
- map.get("byteProperty"));
- assertEquals("Value of 'doubleProperty'",
- new Double(321.0),
- map.get("doubleProperty"));
- assertEquals("Value of 'floatProperty'",
- new Float((float) 123.0),
- map.get("floatProperty"));
- assertEquals("Value of 'intProperty'",
- new Integer(123),
- map.get("intProperty"));
- assertEquals("Value of 'longProperty'",
- new Long(321),
- map.get("longProperty"));
- assertEquals("Value of 'shortProperty'",
- new Short((short) 987),
- map.get("shortProperty"));
- assertEquals("Value of 'stringProperty'",
- "This is a string",
- (String) map.get("stringProperty"));
-
- }
-
- /**
- * Test populate() method on array properties as a whole.
- */
- public void testPopulateArrayProperties() {
-
- try {
-
- final HashMap map = new HashMap<>();
- // int intArray[] = new int[] { 123, 456, 789 };
- final String[] intArrayIn = new String[] { "123", "456", "789" };
- map.put("intArray", intArrayIn);
- String[] stringArray = new String[]
- { "New String 0", "New String 1" };
- map.put("stringArray", stringArray);
-
- BeanUtils.populate(bean, map);
-
- final int[] intArray = (int[]) bean.get("intArray");
- assertNotNull("intArray is present", intArray);
- assertEquals("intArray length",
- 3, intArray.length);
- assertEquals("intArray[0]", 123, intArray[0]);
- assertEquals("intArray[1]", 456, intArray[1]);
- assertEquals("intArray[2]", 789, intArray[2]);
- stringArray = (String[]) bean.get("stringArray");
- assertNotNull("stringArray is present", stringArray);
- assertEquals("stringArray length", 2, stringArray.length);
- assertEquals("stringArray[0]", "New String 0", stringArray[0]);
- assertEquals("stringArray[1]", "New String 1", stringArray[1]);
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * tests the string and int arrays of TestBean
- */
- public void testGetArrayProperty() {
- try {
- String[] arr = BeanUtils.getArrayProperty(bean, "stringArray");
- final String[] comp = (String[]) bean.get("stringArray");
-
- assertTrue("String array length = " + comp.length,
- comp.length == arr.length);
-
- arr = BeanUtils.getArrayProperty(bean, "intArray");
- final int[] iarr = (int[]) bean.get("intArray");
-
- assertTrue("String array length = " + iarr.length,
- iarr.length == arr.length);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * tests getting an indexed property
- */
- public void testGetIndexedProperty1() {
- try {
- String val = BeanUtils.getIndexedProperty(bean, "intIndexed[3]");
- String comp = String.valueOf(bean.get("intIndexed", 3));
- assertTrue("intIndexed[3] == " + comp, val.equals(comp));
-
- val = BeanUtils.getIndexedProperty(bean, "stringIndexed[3]");
- comp = (String) bean.get("stringIndexed", 3);
- assertTrue("stringIndexed[3] == " + comp, val.equals(comp));
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * tests getting an indexed property
- */
- public void testGetIndexedProperty2() {
- try {
- String val = BeanUtils.getIndexedProperty(bean, "intIndexed", 3);
- String comp = String.valueOf(bean.get("intIndexed", 3));
-
- assertTrue("intIndexed,3 == " + comp, val.equals(comp));
-
- val = BeanUtils.getIndexedProperty(bean, "stringIndexed", 3);
- comp = (String) bean.get("stringIndexed", 3);
-
- assertTrue("stringIndexed,3 == " + comp, val.equals(comp));
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * tests getting a nested property
- */
- public void testGetNestedProperty() {
- try {
- final String val = BeanUtils.getNestedProperty(bean, "nested.stringProperty");
- final String comp = nested.getStringProperty();
- assertTrue("nested.StringProperty == " + comp,
- val.equals(comp));
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * tests getting a 'whatever' property
- */
- public void testGetGeneralProperty() {
- try {
- final String val = BeanUtils.getProperty(bean, "nested.intIndexed[2]");
- final String comp = String.valueOf(bean.get("intIndexed", 2));
-
- assertTrue("nested.intIndexed[2] == " + comp,
- val.equals(comp));
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * tests getting a 'whatever' property
- */
- public void testGetSimpleProperty() {
- try {
- final String val = BeanUtils.getSimpleProperty(bean, "shortProperty");
- final String comp = String.valueOf(bean.get("shortProperty"));
-
- assertTrue("shortProperty == " + comp,
- val.equals(comp));
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
- }
-
- /**
- * Test populate() method on individual array elements.
- */
- public void testPopulateArrayElements() {
-
- try {
-
- final HashMap map = new HashMap<>();
- map.put("intIndexed[0]", "100");
- map.put("intIndexed[2]", "120");
- map.put("intIndexed[4]", "140");
-
- BeanUtils.populate(bean, map);
- final Integer intIndexed0 = (Integer) bean.get("intIndexed", 0);
- assertEquals("intIndexed[0] is 100",
- 100, intIndexed0.intValue());
- final Integer intIndexed1 = (Integer) bean.get("intIndexed", 1);
- assertEquals("intIndexed[1] is 10",
- 10, intIndexed1.intValue());
- final Integer intIndexed2 = (Integer) bean.get("intIndexed", 2);
- assertEquals("intIndexed[2] is 120",
- 120, intIndexed2.intValue());
- final Integer intIndexed3 = (Integer) bean.get("intIndexed", 3);
- assertEquals("intIndexed[3] is 30",
- 30, intIndexed3.intValue());
- final Integer intIndexed4 = (Integer) bean.get("intIndexed", 4);
- assertEquals("intIndexed[4] is 140",
- 140, intIndexed4.intValue());
-
- map.clear();
- map.put("stringIndexed[1]", "New String 1");
- map.put("stringIndexed[3]", "New String 3");
-
- BeanUtils.populate(bean, map);
-
- assertEquals("stringIndexed[0] is \"String 0\"",
- "String 0",
- (String) bean.get("stringIndexed", 0));
- assertEquals("stringIndexed[1] is \"New String 1\"",
- "New String 1",
- (String) bean.get("stringIndexed", 1));
- assertEquals("stringIndexed[2] is \"String 2\"",
- "String 2",
- (String) bean.get("stringIndexed", 2));
- assertEquals("stringIndexed[3] is \"New String 3\"",
- "New String 3",
- (String) bean.get("stringIndexed", 3));
- assertEquals("stringIndexed[4] is \"String 4\"",
- "String 4",
- (String) bean.get("stringIndexed", 4));
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * Test populate() on mapped properties.
- */
- public void testPopulateMapped() {
-
- try {
-
- final HashMap map = new HashMap<>();
- map.put("mappedProperty(First Key)", "New First Value");
- map.put("mappedProperty(Third Key)", "New Third Value");
-
- BeanUtils.populate(bean, map);
-
- assertEquals("mappedProperty(First Key)",
- "New First Value",
- (String) bean.get("mappedProperty", "First Key"));
- assertEquals("mappedProperty(Second Key)",
- "Second Value",
- (String) bean.get("mappedProperty", "Second Key"));
- assertEquals("mappedProperty(Third Key)",
- "New Third Value",
- (String) bean.get("mappedProperty", "Third Key"));
- assertNull("mappedProperty(Fourth Key",
- bean.get("mappedProperty", "Fourth Key"));
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * Test populate() method on nested properties.
- */
- public void testPopulateNested() {
-
- try {
-
- final HashMap map = new HashMap<>();
- map.put("nested.booleanProperty", "false");
- // booleanSecond is left at true
- map.put("nested.doubleProperty", "432.0");
- // floatProperty is left at 123.0
- map.put("nested.intProperty", "543");
- // longProperty is left at 321
- map.put("nested.shortProperty", "654");
- // stringProperty is left at "This is a string"
-
- BeanUtils.populate(bean, map);
-
- final TestBean nested = (TestBean) bean.get("nested");
- assertTrue("booleanProperty is false",
- !nested.getBooleanProperty());
- assertTrue("booleanSecond is true",
- nested.isBooleanSecond());
- assertEquals("doubleProperty is 432.0",
- 432.0,
- nested.getDoubleProperty(),
- 0.005);
- assertEquals("floatProperty is 123.0",
- (float) 123.0,
- nested.getFloatProperty(),
- (float) 0.005);
- assertEquals("intProperty is 543",
- 543, nested.getIntProperty());
- assertEquals("longProperty is 321",
- 321, nested.getLongProperty());
- assertEquals("shortProperty is 654",
- (short) 654, nested.getShortProperty());
- assertEquals("stringProperty is \"This is a string\"",
- "This is a string",
- nested.getStringProperty());
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * Test populate() method on scalar properties.
- */
- public void testPopulateScalar() {
-
- try {
-
- bean.set("nullProperty", "non-null value");
-
- final HashMap map = new HashMap<>();
- map.put("booleanProperty", "false");
- // booleanSecond is left at true
- map.put("doubleProperty", "432.0");
- // floatProperty is left at 123.0
- map.put("intProperty", "543");
- // longProperty is left at 321
- map.put("nullProperty", null);
- map.put("shortProperty", "654");
- // stringProperty is left at "This is a string"
-
- BeanUtils.populate(bean, map);
-
- final Boolean booleanProperty = (Boolean) bean.get("booleanProperty");
- assertTrue("booleanProperty is false", !booleanProperty.booleanValue());
- final Boolean booleanSecond = (Boolean) bean.get("booleanSecond");
- assertTrue("booleanSecond is true", booleanSecond.booleanValue());
- final Double doubleProperty = (Double) bean.get("doubleProperty");
- assertEquals("doubleProperty is 432.0",
- 432.0, doubleProperty.doubleValue(), 0.005);
- final Float floatProperty = (Float) bean.get("floatProperty");
- assertEquals("floatProperty is 123.0",
- (float) 123.0, floatProperty.floatValue(),
- (float) 0.005);
- final Integer intProperty = (Integer) bean.get("intProperty");
- assertEquals("intProperty is 543",
- 543, intProperty.intValue());
- final Long longProperty = (Long) bean.get("longProperty");
- assertEquals("longProperty is 321",
- 321, longProperty.longValue());
- assertNull("nullProperty is null", bean.get("nullProperty"));
- final Short shortProperty = (Short) bean.get("shortProperty");
- assertEquals("shortProperty is 654",
- (short) 654, shortProperty.shortValue());
- assertEquals("stringProperty is \"This is a string\"",
- "This is a string",
- (String) bean.get("stringProperty"));
-
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- }
-
- }
-
- /**
- * Test calling setProperty() with null property values.
- */
- public void testSetPropertyNullValues() throws Exception {
-
- Object oldValue = null;
- Object newValue = null;
-
- // Scalar value into array
- oldValue = PropertyUtils.getSimpleProperty(bean, "stringArray");
- BeanUtils.setProperty(bean, "stringArray", null);
- newValue = PropertyUtils.getSimpleProperty(bean, "stringArray");
- assertNotNull("stringArray is not null", newValue);
- assertTrue("stringArray of correct type",
- newValue instanceof String[]);
- assertEquals("stringArray length",
- 1, ((String[]) newValue).length);
- PropertyUtils.setProperty(bean, "stringArray", oldValue);
-
- // Indexed value into array
- oldValue = PropertyUtils.getSimpleProperty(bean, "stringArray");
- BeanUtils.setProperty(bean, "stringArray[2]", null);
- newValue = PropertyUtils.getSimpleProperty(bean, "stringArray");
- assertNotNull("stringArray is not null", newValue);
- assertTrue("stringArray of correct type",
- newValue instanceof String[]);
- assertEquals("stringArray length",
- 5, ((String[]) newValue).length);
- assertTrue("stringArray[2] is null",
- ((String[]) newValue)[2] == null);
- PropertyUtils.setProperty(bean, "stringArray", oldValue);
-
- // Value into scalar
- BeanUtils.setProperty(bean, "stringProperty", null);
- assertTrue("stringProperty is now null",
- BeanUtils.getProperty(bean, "stringProperty") == null);
-
- }
-
- /**
- * Test converting to and from primitive wrapper types.
- */
- public void testSetPropertyOnPrimitiveWrappers() throws Exception {
-
- BeanUtils.setProperty(bean,"intProperty", new Integer(1));
- assertEquals(1,((Integer) bean.get("intProperty")).intValue());
- BeanUtils.setProperty(bean,"stringProperty", new Integer(1));
- assertEquals(1, Integer.parseInt((String) bean.get("stringProperty")));
-
- }
-
- /**
- * Test setting a null property value.
- */
- public void testSetPropertyNull() throws Exception {
-
- bean.set("nullProperty", "non-null value");
- BeanUtils.setProperty(bean, "nullProperty", null);
- assertNull("nullProperty is null", bean.get("nullProperty"));
-
- }
-
- /**
- * Test narrowing and widening conversions on byte.
- */
- public void testCopyPropertyByte() throws Exception {
-
- BeanUtils.setProperty(bean, "byteProperty", new Byte((byte) 123));
- assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
-/*
- BeanUtils.setProperty(bean, "byteProperty", new Double((double) 123));
- assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
- BeanUtils.setProperty(bean, "byteProperty", new Float((float) 123));
- assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
-*/
- BeanUtils.setProperty(bean, "byteProperty", new Integer(123));
- assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
- BeanUtils.setProperty(bean, "byteProperty", new Long(123));
- assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
- BeanUtils.setProperty(bean, "byteProperty", new Short((short) 123));
- assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
-
- }
-
- /**
- * Test narrowing and widening conversions on double.
- */
- public void testCopyPropertyDouble() throws Exception {
-
- BeanUtils.setProperty(bean, "doubleProperty", new Byte((byte) 123));
- assertEquals(123, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Double(123));
- assertEquals(123, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Float(123));
- assertEquals(123, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Integer(123));
- assertEquals(123, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Long(123));
- assertEquals(123, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005);
- BeanUtils.setProperty(bean, "doubleProperty", new Short((short) 123));
- assertEquals(123, ((Double) bean.get("doubleProperty")).doubleValue(), 0.005);
-
- }
-
- /**
- * Test narrowing and widening conversions on float.
- */
- public void testCopyPropertyFloat() throws Exception {
-
- BeanUtils.setProperty(bean, "floatProperty", new Byte((byte) 123));
- assertEquals(123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Double(123));
- assertEquals(123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Float(123));
- assertEquals(123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Integer(123));
- assertEquals(123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Long(123));
- assertEquals(123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
- BeanUtils.setProperty(bean, "floatProperty", new Short((short) 123));
- assertEquals(123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
-
- }
-
- /**
- * Test narrowing and widening conversions on int.
- */
- public void testCopyPropertyInteger() throws Exception {
-
- BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
- assertEquals(123, ((Integer) bean.get("intProperty")).intValue());
-/*
- BeanUtils.setProperty(bean, "longProperty", new Double((double) 123));
- assertEquals((int) 123, ((Integer) bean.get("intProperty")).intValue());
- BeanUtils.setProperty(bean, "longProperty", new Float((float) 123));
- assertEquals((int) 123, ((Integer) bean.get("intProperty")).intValue());
-*/
- BeanUtils.setProperty(bean, "longProperty", new Integer(123));
- assertEquals(123, ((Integer) bean.get("intProperty")).intValue());
- BeanUtils.setProperty(bean, "longProperty", new Long(123));
- assertEquals(123, ((Integer) bean.get("intProperty")).intValue());
- BeanUtils.setProperty(bean, "longProperty", new Short((short) 123));
- assertEquals(123, ((Integer) bean.get("intProperty")).intValue());
-
- }
-
- /**
- * Test narrowing and widening conversions on long.
- */
- public void testCopyPropertyLong() throws Exception {
-
- BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
- assertEquals(123, ((Long) bean.get("longProperty")).longValue());
-/*
- BeanUtils.setProperty(bean, "longProperty", new Double((double) 123));
- assertEquals((long) 123, ((Long) bean.get("longProperty")).longValue());
- BeanUtils.setProperty(bean, "longProperty", new Float((float) 123));
- assertEquals((long) 123, ((Long) bean.get("longProperty")).longValue());
-*/
- BeanUtils.setProperty(bean, "longProperty", new Integer(123));
- assertEquals(123, ((Long) bean.get("longProperty")).longValue());
- BeanUtils.setProperty(bean, "longProperty", new Long(123));
- assertEquals(123, ((Long) bean.get("longProperty")).longValue());
- BeanUtils.setProperty(bean, "longProperty", new Short((short) 123));
- assertEquals(123, ((Long) bean.get("longProperty")).longValue());
-
- }
-
- /**
- * Test copying a null property value.
- */
- public void testCopyPropertyNull() throws Exception {
-
- bean.set("nullProperty", "non-null value");
- BeanUtils.copyProperty(bean, "nullProperty", null);
- assertNull("nullProperty is null", bean.get("nullProperty"));
-
- }
-
- /**
- * Test narrowing and widening conversions on short.
- */
- public void testCopyPropertyShort() throws Exception {
-
- BeanUtils.setProperty(bean, "shortProperty", new Byte((byte) 123));
- assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
-/*
- BeanUtils.setProperty(bean, "shortProperty", new Double((double) 123));
- assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
- BeanUtils.setProperty(bean, "shortProperty", new Float((float) 123));
- assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
-*/
- BeanUtils.setProperty(bean, "shortProperty", new Integer(123));
- assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
- BeanUtils.setProperty(bean, "shortProperty", new Long(123));
- assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
- BeanUtils.setProperty(bean, "shortProperty", new Short((short) 123));
- assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
-
- }
-
- /**
- * Test copying a property using a nested indexed array expression,
- * with and without conversions.
- */
- public void testCopyPropertyNestedIndexedArray() throws Exception {
-
- final int[] origArray = { 0, 10, 20, 30, 40};
- final int[] intArray = { 0, 0, 0 };
- ((TestBean) bean.get("nested")).setIntArray(intArray);
- final int[] intChanged = { 0, 0, 0 };
-
- // No conversion required
- BeanUtils.copyProperty(bean, "nested.intArray[1]", new Integer(1));
- checkIntArray((int[]) bean.get("intArray"), origArray);
- intChanged[1] = 1;
- checkIntArray(((TestBean) bean.get("nested")).getIntArray(),
- intChanged);
-
- // Widening conversion required
- BeanUtils.copyProperty(bean, "nested.intArray[1]", new Byte((byte) 2));
- checkIntArray((int[]) bean.get("intArray"), origArray);
- intChanged[1] = 2;
- checkIntArray(((TestBean) bean.get("nested")).getIntArray(),
- intChanged);
-
- // Narrowing conversion required
- BeanUtils.copyProperty(bean, "nested.intArray[1]", new Long(3));
- checkIntArray((int[]) bean.get("intArray"), origArray);
- intChanged[1] = 3;
- checkIntArray(((TestBean) bean.get("nested")).getIntArray(),
- intChanged);
-
- // String conversion required
- BeanUtils.copyProperty(bean, "nested.intArray[1]", "4");
- checkIntArray((int[]) bean.get("intArray"), origArray);
- intChanged[1] = 4;
- checkIntArray(((TestBean) bean.get("nested")).getIntArray(),
- intChanged);
-
- }
-
- /**
- * Test copying a property using a nested mapped map property.
- */
- public void testCopyPropertyNestedMappedMap() throws Exception {
-
- final Map origMap = new HashMap<>();
- origMap.put("First Key", "First Value");
- origMap.put("Second Key", "Second Value");
- final Map changedMap = new HashMap<>();
- changedMap.put("First Key", "First Value");
- changedMap.put("Second Key", "Second Value");
-
- // No conversion required
- BeanUtils.copyProperty(bean, "nested.mapProperty(Second Key)",
- "New Second Value");
- checkMap((Map, ?>) bean.get("mapProperty"), origMap);
- changedMap.put("Second Key", "New Second Value");
- checkMap(((TestBean) bean.get("nested")).getMapProperty(), changedMap);
-
- }
-
- /**
- * Test copying a property using a nested simple expression, with and
- * without conversions.
- */
- public void testCopyPropertyNestedSimple() throws Exception {
-
- bean.set("intProperty", new Integer(0));
- nested.setIntProperty(0);
-
- // No conversion required
- BeanUtils.copyProperty(bean, "nested.intProperty", new Integer(1));
- assertEquals(0, ((Integer) bean.get("intProperty")).intValue());
- assertEquals(1, nested.getIntProperty());
-
- // Widening conversion required
- BeanUtils.copyProperty(bean, "nested.intProperty", new Byte((byte) 2));
- assertEquals(0, ((Integer) bean.get("intProperty")).intValue());
- assertEquals(2, nested.getIntProperty());
-
- // Narrowing conversion required
- BeanUtils.copyProperty(bean, "nested.intProperty", new Long(3));
- assertEquals(0, ((Integer) bean.get("intProperty")).intValue());
- assertEquals(3, nested.getIntProperty());
-
- // String conversion required
- BeanUtils.copyProperty(bean, "nested.intProperty", "4");
- assertEquals(0, ((Integer) bean.get("intProperty")).intValue());
- assertEquals(4, nested.getIntProperty());
-
- }
-
-
-
- // Ensure that the nested intArray matches the specified values
- protected void checkIntArray(final int[] actual, final int[] expected) {
- assertNotNull("actual array not null", actual);
- assertEquals("actual array length", expected.length, actual.length);
- for (int i = 0; i < actual.length; i++) {
- assertEquals("actual array value[" + i + "]",
- expected[i], actual[i]);
- }
- }
-
- // Ensure that the actual Map matches the expected Map
- protected void checkMap(final Map, ?> actual, final Map, ?> expected) {
- assertNotNull("actual map not null", actual);
- assertEquals("actual map size", expected.size(), actual.size());
- final Iterator> keys = expected.keySet().iterator();
- while (keys.hasNext()) {
- final Object key = keys.next();
- assertEquals("actual map value(" + key + ")",
- expected.get(key), actual.get(key));
- }
- }
-
- /**
- * Create and return a {@code DynaClass} instance for our test
- * {@code DynaBean}.
- */
- protected static DynaClass createDynaClass() {
-
- final int[] intArray = new int[0];
- final String[] stringArray = new String[0];
-
- final DynaClass dynaClass = new BasicDynaClass
- ("TestDynaClass", null,
- new DynaProperty[]{
- new DynaProperty("booleanProperty", Boolean.TYPE),
- new DynaProperty("booleanSecond", Boolean.TYPE),
- new DynaProperty("byteProperty", Byte.TYPE),
- new DynaProperty("doubleProperty", Double.TYPE),
- new DynaProperty("dupProperty", stringArray.getClass()),
- new DynaProperty("floatProperty", Float.TYPE),
- new DynaProperty("intArray", intArray.getClass()),
- new DynaProperty("intIndexed", intArray.getClass()),
- new DynaProperty("intProperty", Integer.TYPE),
- new DynaProperty("listIndexed", List.class),
- new DynaProperty("longProperty", Long.TYPE),
- new DynaProperty("mapProperty", Map.class),
- new DynaProperty("mappedProperty", Map.class),
- new DynaProperty("mappedIntProperty", Map.class),
- new DynaProperty("nested", TestBean.class),
- new DynaProperty("nullProperty", String.class),
- new DynaProperty("shortProperty", Short.TYPE),
- new DynaProperty("stringArray", stringArray.getClass()),
- new DynaProperty("stringIndexed", stringArray.getClass()),
- new DynaProperty("stringProperty", String.class),
- });
- return dynaClass;
-
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaPropertyTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaPropertyTestCase.java
deleted file mode 100644
index 1d38d9528..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaPropertyTestCase.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.util.Collection;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test case for {@link DynaProperty}.
- *
- */
-public class DynaPropertyTestCase extends TestCase {
-
- private DynaProperty testPropertyWithName;
- private DynaProperty testProperty1Duplicate;
- private DynaProperty testPropertyWithNameAndType;
- private DynaProperty testProperty2Duplicate;
- private DynaProperty testPropertyWithNameAndTypeAndContentType;
- private DynaProperty testProperty3Duplicate;
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public DynaPropertyTestCase(final String name) {
- super(name);
- }
-
- /**
- * Return the tests included in this test suite.
- * @return a test suite
- */
- public static Test suite() {
-
- return new TestSuite(DynaPropertyTestCase.class);
-
- }
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- protected void setUp() throws Exception {
-
- super.setUp();
-
- testPropertyWithName = new DynaProperty("test1");
- testProperty1Duplicate = new DynaProperty("test1");
-
- testPropertyWithNameAndType = new DynaProperty("test2", Integer.class);
- testProperty2Duplicate = new DynaProperty("test2", Integer.class);
-
- testPropertyWithNameAndTypeAndContentType = new DynaProperty("test3", Collection.class, Short.class);
- testProperty3Duplicate = new DynaProperty("test3", Collection.class, Short.class);
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- protected void tearDown() throws Exception {
-
- testPropertyWithName = testProperty1Duplicate = null;
- testPropertyWithNameAndType = testProperty2Duplicate = null;
- testPropertyWithNameAndTypeAndContentType = testProperty3Duplicate = null;
- super.tearDown();
- }
-
- /**
- * Class under test for int hashCode(Object)
- */
- public void testHashCode() {
-
- final int initialHashCode = testPropertyWithNameAndTypeAndContentType.hashCode();
- assertEquals(testPropertyWithName.hashCode(), testProperty1Duplicate.hashCode());
- assertEquals(testPropertyWithNameAndType.hashCode(), testProperty2Duplicate.hashCode());
- assertEquals(testPropertyWithNameAndTypeAndContentType.hashCode(), testProperty3Duplicate.hashCode());
- assertEquals(initialHashCode, testPropertyWithNameAndTypeAndContentType.hashCode());
- }
-
- /**
- * Class under test for boolean equals(Object)
- */
- public void testEqualsObject() {
-
- assertEquals(testPropertyWithName, testProperty1Duplicate);
- assertEquals(testPropertyWithNameAndType, testProperty2Duplicate);
- assertEquals(testPropertyWithNameAndTypeAndContentType, testProperty3Duplicate);
- assertFalse(testPropertyWithName.equals(testPropertyWithNameAndType));
- assertFalse(testPropertyWithNameAndType.equals(testPropertyWithNameAndTypeAndContentType));
- assertFalse(testPropertyWithName.equals(null));
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaPropertyUtilsTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaPropertyUtilsTestCase.java
deleted file mode 100644
index 6d4f9f368..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaPropertyUtilsTestCase.java
+++ /dev/null
@@ -1,2570 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test accessing DynaBeans transparently via PropertyUtils.
- *
- */
-
-public class DynaPropertyUtilsTestCase extends TestCase {
-
-
-
- /**
- * The basic test bean for each test.
- */
- protected DynaBean bean = null;
-
- /**
- * The set of properties that should be described.
- */
- protected String[] describes =
- { "booleanProperty",
- "booleanSecond",
- "doubleProperty",
- "floatProperty",
- "intArray",
- "intIndexed",
- "intProperty",
- "listIndexed",
- "longProperty",
- "mappedObjects",
- "mappedProperty",
- "mappedIntProperty",
- "nested",
- "nullProperty",
- // "readOnlyProperty",
- "shortProperty",
- "stringArray",
- "stringIndexed",
- "stringProperty"
- };
-
- /**
- * The nested bean pointed at by the "nested" property.
- */
- protected TestBean nested = null;
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public DynaPropertyUtilsTestCase(final String name) {
-
- super(name);
-
- }
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
-
- // Instantiate a new DynaBean instance
- final DynaClass dynaClass = createDynaClass();
- bean = dynaClass.newInstance();
-
- // Initialize the DynaBean's property values (like TestBean)
- bean.set("booleanProperty", new Boolean(true));
- bean.set("booleanSecond", new Boolean(true));
- bean.set("doubleProperty", new Double(321.0));
- bean.set("floatProperty", new Float((float) 123.0));
- final int[] intArray = { 0, 10, 20, 30, 40 };
- bean.set("intArray", intArray);
- final int[] intIndexed = { 0, 10, 20, 30, 40 };
- bean.set("intIndexed", intIndexed);
- bean.set("intProperty", new Integer(123));
- final List listIndexed = new ArrayList<>();
- listIndexed.add("String 0");
- listIndexed.add("String 1");
- listIndexed.add("String 2");
- listIndexed.add("String 3");
- listIndexed.add("String 4");
- bean.set("listIndexed", listIndexed);
- bean.set("longProperty", new Long(321));
- final HashMap mapProperty = new HashMap<>();
- mapProperty.put("First Key", "First Value");
- mapProperty.put("Second Key", "Second Value");
- bean.set("mapProperty", mapProperty);
- final HashMap mappedObjects = new HashMap<>();
- mappedObjects.put("First Key", "First Value");
- mappedObjects.put("Second Key", "Second Value");
- bean.set("mappedObjects", mappedObjects);
- final HashMap mappedProperty = new HashMap<>();
- mappedProperty.put("First Key", "First Value");
- mappedProperty.put("Second Key", "Second Value");
- bean.set("mappedProperty", mappedProperty);
- final HashMap mappedIntProperty = new HashMap<>();
- mappedIntProperty.put("One", new Integer(1));
- mappedIntProperty.put("Two", new Integer(2));
- bean.set("mappedIntProperty", mappedIntProperty);
- nested = new TestBean();
- bean.set("nested", nested);
- // Property "nullProperty" is not initialized, so it should return null
- bean.set("shortProperty", new Short((short) 987));
- final String[] stringArray =
- { "String 0", "String 1", "String 2", "String 3", "String 4" };
- bean.set("stringArray", stringArray);
- final String[] stringIndexed =
- { "String 0", "String 1", "String 2", "String 3", "String 4" };
- bean.set("stringIndexed", stringIndexed);
- bean.set("stringProperty", "This is a string");
-
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
-
- return new TestSuite(DynaPropertyUtilsTestCase.class);
-
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
-
- bean = null;
- nested = null;
-
- }
-
-
-
- /**
- * Test copyProperties() when the origin is a a {@code Map}.
- */
- public void testCopyPropertiesMap() {
-
- final Map map = new HashMap<>();
- map.put("booleanProperty", Boolean.FALSE);
- map.put("doubleProperty", new Double(333.0));
- map.put("dupProperty", new String[] { "New 0", "New 1", "New 2" });
- map.put("floatProperty", new Float((float) 222.0));
- map.put("intArray", new int[] { 0, 100, 200 });
- map.put("intProperty", new Integer(111));
- map.put("longProperty", new Long(444));
- map.put("shortProperty", new Short((short) 555));
- map.put("stringProperty", "New String Property");
-
- try {
- PropertyUtils.copyProperties(bean, map);
- } catch (final Throwable t) {
- fail("Threw " + t.toString());
- }
-
- // Scalar properties
- assertEquals("booleanProperty", false,
- ((Boolean) bean.get("booleanProperty")).booleanValue());
- assertEquals("doubleProperty", 333.0,
- ((Double) bean.get("doubleProperty")).doubleValue(),
- 0.005);
- assertEquals("floatProperty", (float) 222.0,
- ((Float) bean.get("floatProperty")).floatValue(),
- (float) 0.005);
- assertEquals("intProperty", 111,
- ((Integer) bean.get("intProperty")).intValue());
- assertEquals("longProperty", 444,
- ((Long) bean.get("longProperty")).longValue());
- assertEquals("shortProperty", (short) 555,
- ((Short) bean.get("shortProperty")).shortValue());
- assertEquals("stringProperty", "New String Property",
- (String) bean.get("stringProperty"));
-
- // Indexed Properties
- final String[] dupProperty = (String[]) bean.get("dupProperty");
- assertNotNull("dupProperty present", dupProperty);
- assertEquals("dupProperty length", 3, dupProperty.length);
- assertEquals("dupProperty[0]", "New 0", dupProperty[0]);
- assertEquals("dupProperty[1]", "New 1", dupProperty[1]);
- assertEquals("dupProperty[2]", "New 2", dupProperty[2]);
- final int[] intArray = (int[]) bean.get("intArray");
- assertNotNull("intArray present", intArray);
- assertEquals("intArray length", 3, intArray.length);
- assertEquals("intArray[0]", 0, intArray[0]);
- assertEquals("intArray[1]", 100, intArray[1]);
- assertEquals("intArray[2]", 200, intArray[2]);
-
- }
-
- /**
- * Test the describe() method.
- */
- public void testDescribe() {
-
- Map map = null;
- try {
- map = PropertyUtils.describe(bean);
- } catch (final Exception e) {
- fail("Threw exception " + e);
- }
-
- // Verify existence of all the properties that should be present
- for (final String describe : describes) {
- assertTrue("Property '" + describe + "' is present",
- map.containsKey(describe));
- }
- assertTrue("Property 'writeOnlyProperty' is not present",
- !map.containsKey("writeOnlyProperty"));
-
- // Verify the values of scalar properties
- assertEquals("Value of 'booleanProperty'",
- Boolean.TRUE, map.get("booleanProperty"));
- assertEquals("Value of 'doubleProperty'",
- new Double(321.0), map.get("doubleProperty"));
- assertEquals("Value of 'floatProperty'",
- new Float((float) 123.0), map.get("floatProperty"));
- assertEquals("Value of 'intProperty'",
- new Integer(123), map.get("intProperty"));
- assertEquals("Value of 'longProperty'",
- new Long(321), map.get("longProperty"));
- assertEquals("Value of 'shortProperty'",
- new Short((short) 987), map.get("shortProperty"));
- assertEquals("Value of 'stringProperty'",
- "This is a string",
- (String) map.get("stringProperty"));
-
- }
-
- /**
- * Corner cases on getIndexedProperty invalid arguments.
- */
- public void testGetIndexedArguments() {
-
- // Use explicit index argument
-
- try {
- PropertyUtils.getIndexedProperty(null, "intArray", 0);
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.getIndexedProperty(bean, null, 0);
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- // Use index expression
-
- try {
- PropertyUtils.getIndexedProperty(null,
- "intArray[0]");
- fail("Should throw IllegalArgumentException 3");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 3");
- }
-
- try {
- PropertyUtils.getIndexedProperty(bean, "[0]");
- fail("Should throw NoSuchMethodException 4");
- } catch (final NoSuchMethodException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of NoSuchMethodException 4");
- }
-
- try {
- PropertyUtils.getIndexedProperty(bean, "intArray");
- fail("Should throw IllegalArgumentException 5");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 5");
- }
-
- // Use explicit index argument
-
- try {
- PropertyUtils.getIndexedProperty(null, "intIndexed", 0);
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.getIndexedProperty(bean, null, 0);
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- // Use index expression
-
- try {
- PropertyUtils.getIndexedProperty(null,
- "intIndexed[0]");
- fail("Should throw IllegalArgumentException 3");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 3");
- }
-
- try {
- PropertyUtils.getIndexedProperty(bean, "[0]");
- fail("Should throw NoSuchMethodException 4");
- } catch (final NoSuchMethodException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of NoSuchMethodException 4");
- }
-
- try {
- PropertyUtils.getIndexedProperty(bean, "intIndexed");
- fail("Should throw IllegalArgumentException 5");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 5");
- }
-
- }
-
- /**
- * Positive and negative tests on getIndexedProperty valid arguments.
- */
- public void testGetIndexedValues() {
-
- Object value = null;
-
- // Use explicit key argument
-
- for (int i = 0; i < 5; i++) {
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean, "intArray", i);
- assertNotNull("intArray returned value " + i, value);
- assertTrue("intArray returned Integer " + i,
- value instanceof Integer);
- assertEquals("intArray returned correct " + i, i * 10,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("intArray " + i + " threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean, "intIndexed", i);
- assertNotNull("intIndexed returned value " + i, value);
- assertTrue("intIndexed returned Integer " + i,
- value instanceof Integer);
- assertEquals("intIndexed returned correct " + i, i * 10,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("intIndexed " + i + " threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean, "listIndexed", i);
- assertNotNull("listIndexed returned value " + i, value);
- assertTrue("list returned String " + i,
- value instanceof String);
- assertEquals("listIndexed returned correct " + i,
- "String " + i, (String) value);
- } catch (final Throwable t) {
- fail("listIndexed " + i + " threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean, "stringArray", i);
- assertNotNull("stringArray returned value " + i, value);
- assertTrue("stringArray returned String " + i,
- value instanceof String);
- assertEquals("stringArray returned correct " + i,
- "String " + i, (String) value);
- } catch (final Throwable t) {
- fail("stringArray " + i + " threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean, "stringIndexed", i);
- assertNotNull("stringIndexed returned value " + i, value);
- assertTrue("stringIndexed returned String " + i,
- value instanceof String);
- assertEquals("stringIndexed returned correct " + i,
- "String " + i, (String) value);
- } catch (final Throwable t) {
- fail("stringIndexed " + i + " threw " + t);
- }
-
- }
-
- // Use key expression
-
- for (int i = 0; i < 5; i++) {
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intArray[" + i + "]");
- assertNotNull("intArray returned value " + i, value);
- assertTrue("intArray returned Integer " + i,
- value instanceof Integer);
- assertEquals("intArray returned correct " + i, i * 10,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("intArray " + i + " threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intIndexed[" + i + "]");
- assertNotNull("intIndexed returned value " + i, value);
- assertTrue("intIndexed returned Integer " + i,
- value instanceof Integer);
- assertEquals("intIndexed returned correct " + i, i * 10,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("intIndexed " + i + " threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "listIndexed[" + i + "]");
- assertNotNull("listIndexed returned value " + i, value);
- assertTrue("listIndexed returned String " + i,
- value instanceof String);
- assertEquals("listIndexed returned correct " + i,
- "String " + i, (String) value);
- } catch (final Throwable t) {
- fail("listIndexed " + i + " threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringArray[" + i + "]");
- assertNotNull("stringArray returned value " + i, value);
- assertTrue("stringArray returned String " + i,
- value instanceof String);
- assertEquals("stringArray returned correct " + i,
- "String " + i, (String) value);
- } catch (final Throwable t) {
- fail("stringArray " + i + " threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringIndexed[" + i + "]");
- assertNotNull("stringIndexed returned value " + i, value);
- assertTrue("stringIndexed returned String " + i,
- value instanceof String);
- assertEquals("stringIndexed returned correct " + i,
- "String " + i, (String) value);
- } catch (final Throwable t) {
- fail("stringIndexed " + i + " threw " + t);
- }
-
- }
-
- // Index out of bounds tests
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intArray", -1);
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intArray", 5);
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intIndexed", -1);
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intIndexed", 5);
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "listIndexed", -1);
- fail("Should have thrown IndexOutOfBoundsException");
- } catch (final IndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IndexOutOfBoundsException");
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "listIndexed", 5);
- fail("Should have thrown IndexOutOfBoundsException");
- } catch (final IndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IndexOutOfBoundsException");
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringArray", -1);
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringArray", 5);
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringIndexed", -1);
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringIndexed", 5);
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- }
-
- /**
- * Corner cases on getMappedProperty invalid arguments.
- */
- public void testGetMappedArguments() {
-
- // Use explicit key argument
-
- try {
- PropertyUtils.getMappedProperty(null, "mappedProperty",
- "First Key");
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.getMappedProperty(bean, null, "First Key");
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- try {
- PropertyUtils.getMappedProperty(bean, "mappedProperty", null);
- fail("Should throw IllegalArgumentException 3");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 3");
- }
-
- // Use key expression
-
- try {
- PropertyUtils.getMappedProperty(null,
- "mappedProperty(First Key)");
- fail("Should throw IllegalArgumentException 4");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 4");
- }
-
- try {
- PropertyUtils.getMappedProperty(bean, "(Second Key)");
- fail("Should throw IllegalArgumentException 5");
- } catch (final NoSuchMethodException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of NoSuchMethodException 5");
- }
-
- try {
- PropertyUtils.getMappedProperty(bean, "mappedProperty");
- fail("Should throw IllegalArgumentException 6");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 6");
- }
-
- }
-
- /**
- * Test getting mapped values with periods in the key.
- */
- public void testGetMappedPeriods() {
-
- bean.set("mappedProperty", "key.with.a.dot", "Special Value");
- assertEquals("Can retrieve directly",
- "Special Value",
- (String) bean.get("mappedProperty", "key.with.a.dot"));
- try {
- assertEquals("Can retrieve via getMappedProperty",
- "Special Value",
- PropertyUtils.getMappedProperty
- (bean, "mappedProperty", "key.with.a.dot"));
- } catch (final Exception e) {
- fail("Thew exception: " + e);
- }
- try {
- assertEquals("Can retrieve via getNestedProperty",
- "Special Value",
- PropertyUtils.getNestedProperty
- (bean, "mappedProperty(key.with.a.dot)"));
- } catch (final Exception e) {
- fail("Thew exception: " + e);
- }
-
- bean.set("mappedObjects", "nested.property", new TestBean());
- assertNotNull("Can retrieve directly",
- bean.get("mappedObjects", "nested.property"));
- try {
- assertEquals("Can retrieve nested",
- "This is a string",
- PropertyUtils.getNestedProperty
- (bean,
- "mappedObjects(nested.property).stringProperty"));
- } catch (final Exception e) {
- fail("Thew exception: " + e);
- }
-
- }
-
- /**
- * Test getting mapped values with slashes in the key. This is different
- * from periods because slashes are not syntactically significant.
- */
- public void testGetMappedSlashes() {
-
- bean.set("mappedProperty", "key/with/a/slash", "Special Value");
- assertEquals("Can retrieve directly",
- "Special Value",
- bean.get("mappedProperty", "key/with/a/slash"));
- try {
- assertEquals("Can retrieve via getMappedProperty",
- "Special Value",
- PropertyUtils.getMappedProperty
- (bean, "mappedProperty", "key/with/a/slash"));
- } catch (final Exception e) {
- fail("Thew exception: " + e);
- }
- try {
- assertEquals("Can retrieve via getNestedProperty",
- "Special Value",
- PropertyUtils.getNestedProperty
- (bean, "mappedProperty(key/with/a/slash)"));
- } catch (final Exception e) {
- fail("Thew exception: " + e);
- }
-
- bean.set("mappedObjects", "nested/property", new TestBean());
- assertNotNull("Can retrieve directly",
- bean.get("mappedObjects", "nested/property"));
- try {
- assertEquals("Can retrieve nested",
- "This is a string",
- PropertyUtils.getNestedProperty
- (bean,
- "mappedObjects(nested/property).stringProperty"));
- } catch (final Exception e) {
- fail("Thew exception: " + e);
- }
-
- }
-
- /**
- * Positive and negative tests on getMappedProperty valid arguments.
- */
- public void testGetMappedValues() {
-
- Object value = null;
-
- // Use explicit key argument
-
- try {
- value = PropertyUtils.getMappedProperty(bean, "mappedProperty",
- "First Key");
- assertEquals("Can find first value", "First Value", value);
- } catch (final Throwable t) {
- fail("Finding first value threw " + t);
- }
-
- try {
- value = PropertyUtils.getMappedProperty(bean, "mappedProperty",
- "Second Key");
- assertEquals("Can find second value", "Second Value", value);
- } catch (final Throwable t) {
- fail("Finding second value threw " + t);
- }
-
- try {
- value = PropertyUtils.getMappedProperty(bean, "mappedProperty",
- "Third Key");
- assertNull("Can not find third value", value);
- } catch (final Throwable t) {
- fail("Finding third value threw " + t);
- }
-
- // Use key expression with parentheses
-
- try {
- value =
- PropertyUtils.getMappedProperty(bean,
- "mappedProperty(First Key)");
- assertEquals("Can find first value", "First Value", value);
- } catch (final Throwable t) {
- fail("Finding first value threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getMappedProperty(bean,
- "mappedProperty(Second Key)");
- assertEquals("Can find second value", "Second Value", value);
- } catch (final Throwable t) {
- fail("Finding second value threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getMappedProperty(bean,
- "mappedProperty(Third Key)");
- assertNull("Can not find third value", value);
- } catch (final Throwable t) {
- fail("Finding third value threw " + t);
- }
-
- // Use key expression with dotted syntax
-
- try {
- value =
- PropertyUtils.getNestedProperty(bean,
- "mapProperty.First Key");
- assertEquals("Can find first value", "First Value", value);
- } catch (final Throwable t) {
- fail("Finding first value threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getNestedProperty(bean,
- "mapProperty.Second Key");
- assertEquals("Can find second value", "Second Value", value);
- } catch (final Throwable t) {
- fail("Finding second value threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getNestedProperty(bean,
- "mapProperty.Third Key");
- assertNull("Can not find third value", value);
- } catch (final Throwable t) {
- fail("Finding third value threw " + t);
- }
-
- }
-
- /**
- * Corner cases on getNestedProperty invalid arguments.
- */
- public void testGetNestedArguments() {
-
- try {
- PropertyUtils.getNestedProperty(null, "stringProperty");
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.getNestedProperty(bean, null);
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- }
-
- /**
- * Test getNestedProperty on a boolean property.
- */
- public void testGetNestedBoolean() {
-
- try {
- final Object value =
- PropertyUtils.getNestedProperty
- (bean, "nested.booleanProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Boolean);
- final TestBean nested = (TestBean) bean.get("nested");
- assertTrue("Got correct value",
- ((Boolean) value).booleanValue() ==
- nested.getBooleanProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getNestedProperty on a double property.
- */
- public void testGetNestedDouble() {
-
- try {
- final Object value =
- PropertyUtils.getNestedProperty
- (bean, "nested.doubleProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Double);
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals("Got correct value",
- ((Double) value).doubleValue(),
- nested.getDoubleProperty(),
- 0.005);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getNestedProperty on a float property.
- */
- public void testGetNestedFloat() {
-
- try {
- final Object value =
- PropertyUtils.getNestedProperty
- (bean, "nested.floatProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Float);
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals("Got correct value",
- ((Float) value).floatValue(),
- nested.getFloatProperty(),
- (float) 0.005);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getNestedProperty on an int property.
- */
- public void testGetNestedInt() {
-
- try {
- final Object value =
- PropertyUtils.getNestedProperty
- (bean, "nested.intProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Integer);
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals("Got correct value",
- ((Integer) value).intValue(),
- nested.getIntProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getNestedProperty on a long property.
- */
- public void testGetNestedLong() {
-
- try {
- final Object value =
- PropertyUtils.getNestedProperty
- (bean, "nested.longProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Long);
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals("Got correct value",
- ((Long) value).longValue(),
- nested.getLongProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getNestedProperty on a read-only String property.
- */
- public void testGetNestedReadOnly() {
-
- try {
- final Object value =
- PropertyUtils.getNestedProperty
- (bean, "nested.readOnlyProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof String);
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals("Got correct value",
- (String) value,
- nested.getReadOnlyProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getNestedProperty on a short property.
- */
- public void testGetNestedShort() {
-
- try {
- final Object value =
- PropertyUtils.getNestedProperty
- (bean, "nested.shortProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Short);
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals("Got correct value",
- ((Short) value).shortValue(),
- nested.getShortProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getNestedProperty on a String property.
- */
- public void testGetNestedString() {
-
- try {
- final Object value =
- PropertyUtils.getNestedProperty
- (bean, "nested.stringProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof String);
- final TestBean nested = (TestBean) bean.get("nested");
- assertEquals("Got correct value",
- (String) value,
- nested.getStringProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Negative test getNestedProperty on an unknown property.
- */
- public void testGetNestedUnknown() {
-
- try {
- PropertyUtils.getNestedProperty(bean, "nested.unknown");
- fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- // Correct result for this test
- }
-
- }
-
- /**
- * Corner cases on getSimpleProperty invalid arguments.
- */
- public void testGetSimpleArguments() {
-
- try {
- PropertyUtils.getSimpleProperty(null, "stringProperty");
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.getSimpleProperty(bean, null);
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- }
-
- /**
- * Test getSimpleProperty on a boolean property.
- */
- public void testGetSimpleBoolean() {
-
- try {
- final Object value =
- PropertyUtils.getSimpleProperty(bean,
- "booleanProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Boolean);
- assertTrue("Got correct value",
- ((Boolean) value).booleanValue());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getSimpleProperty on a double property.
- */
- public void testGetSimpleDouble() {
-
- try {
- final Object value =
- PropertyUtils.getSimpleProperty(bean,
- "doubleProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Double);
- assertEquals("Got correct value",
- ((Double) value).doubleValue(), 321.0, 0.005);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getSimpleProperty on a float property.
- */
- public void testGetSimpleFloat() {
-
- try {
- final Object value =
- PropertyUtils.getSimpleProperty(bean,
- "floatProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Float);
- assertEquals("Got correct value",
- ((Float) value).floatValue(),
- (float) 123.0,
- (float) 0.005);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Negative test getSimpleProperty on an indexed property.
- */
- public void testGetSimpleIndexed() {
-
- try {
- PropertyUtils.getSimpleProperty(bean,
- "intIndexed[0]");
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- // Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getSimpleProperty on an int property.
- */
- public void testGetSimpleInt() {
-
- try {
- final Object value =
- PropertyUtils.getSimpleProperty(bean,
- "intProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Integer);
- assertEquals("Got correct value",
- ((Integer) value).intValue(),
- 123);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getSimpleProperty on a long property.
- */
- public void testGetSimpleLong() {
-
- try {
- final Object value =
- PropertyUtils.getSimpleProperty(bean,
- "longProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Long);
- assertEquals("Got correct value",
- ((Long) value).longValue(),
- 321);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Negative test getSimpleProperty on a nested property.
- */
- public void testGetSimpleNested() {
-
- try {
- PropertyUtils.getSimpleProperty(bean,
- "nested.stringProperty");
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- // Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getSimpleProperty on a short property.
- */
- public void testGetSimpleShort() {
-
- try {
- final Object value =
- PropertyUtils.getSimpleProperty(bean,
- "shortProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof Short);
- assertEquals("Got correct value",
- ((Short) value).shortValue(),
- (short) 987);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test getSimpleProperty on a String property.
- */
- public void testGetSimpleString() {
-
- try {
- final Object value =
- PropertyUtils.getSimpleProperty(bean,
- "stringProperty");
- assertNotNull("Got a value", value);
- assertTrue("Got correct type", value instanceof String);
- assertEquals("Got correct value",
- (String) value,
- "This is a string");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Negative test getSimpleProperty on an unknown property.
- */
- public void testGetSimpleUnknown() {
-
- try {
- PropertyUtils.getSimpleProperty(bean, "unknown");
- fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- // Correct result for this test
- assertEquals("Unknown property 'unknown' on dynaclass '" +
- bean.getDynaClass() + "'", e.getMessage() );
- }
-
- }
-
- /**
- * Corner cases on setIndexedProperty invalid arguments.
- */
- public void testSetIndexedArguments() {
-
- // Use explicit index argument
-
- try {
- PropertyUtils.setIndexedProperty(null, "intArray", 0,
- new Integer(1));
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean, null, 0,
- new Integer(1));
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- // Use index expression
-
- try {
- PropertyUtils.setIndexedProperty(null,
- "intArray[0]",
- new Integer(1));
- fail("Should throw IllegalArgumentException 3");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 3");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean, "[0]",
- new Integer(1));
- fail("Should throw NoSuchMethodException 4");
- } catch (final NoSuchMethodException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of NoSuchMethodException 4");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean, "intArray",
- new Integer(1));
- fail("Should throw IllegalArgumentException 5");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 5");
- }
-
- // Use explicit index argument
-
- try {
- PropertyUtils.setIndexedProperty(null, "intIndexed", 0,
- new Integer(1));
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean, null, 0,
- new Integer(1));
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- // Use index expression
-
- try {
- PropertyUtils.setIndexedProperty(null,
- "intIndexed[0]",
- new Integer(1));
- fail("Should throw IllegalArgumentException 3");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 3");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean, "[0]",
- new Integer(1));
- fail("Should throw NoSuchMethodException 4");
- } catch (final NoSuchMethodException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of NoSuchMethodException 4");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean, "intIndexed",
- new Integer(1));
- fail("Should throw IllegalArgumentException 5");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 5");
- }
-
- }
-
- /**
- * Positive and negative tests on setIndexedProperty valid arguments.
- */
- public void testSetIndexedValues() {
-
- Object value = null;
-
- // Use explicit index argument
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "intArray", 0,
- new Integer(1));
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intArray", 0);
- assertNotNull("Returned new value 0", value);
- assertTrue("Returned Integer new value 0",
- value instanceof Integer);
- assertEquals("Returned correct new value 0", 1,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "intIndexed", 1,
- new Integer(11));
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intIndexed", 1);
- assertNotNull("Returned new value 1", value);
- assertTrue("Returned Integer new value 1",
- value instanceof Integer);
- assertEquals("Returned correct new value 1", 11,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "listIndexed", 2,
- "New Value 2");
- value =
- PropertyUtils.getIndexedProperty(bean,
- "listIndexed", 2);
- assertNotNull("Returned new value 2", value);
- assertTrue("Returned String new value 2",
- value instanceof String);
- assertEquals("Returned correct new value 2", "New Value 2",
- (String) value);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "stringArray", 2,
- "New Value 2");
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringArray", 2);
- assertNotNull("Returned new value 2", value);
- assertTrue("Returned String new value 2",
- value instanceof String);
- assertEquals("Returned correct new value 2", "New Value 2",
- (String) value);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "stringArray", 3,
- "New Value 3");
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringArray", 3);
- assertNotNull("Returned new value 3", value);
- assertTrue("Returned String new value 3",
- value instanceof String);
- assertEquals("Returned correct new value 3", "New Value 3",
- (String) value);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- // Use index expression
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "intArray[4]",
- new Integer(1));
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intArray[4]");
- assertNotNull("Returned new value 4", value);
- assertTrue("Returned Integer new value 4",
- value instanceof Integer);
- assertEquals("Returned correct new value 4", 1,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "intIndexed[3]",
- new Integer(11));
- value =
- PropertyUtils.getIndexedProperty(bean,
- "intIndexed[3]");
- assertNotNull("Returned new value 5", value);
- assertTrue("Returned Integer new value 5",
- value instanceof Integer);
- assertEquals("Returned correct new value 5", 11,
- ((Integer) value).intValue());
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "listIndexed[1]",
- "New Value 2");
- value =
- PropertyUtils.getIndexedProperty(bean,
- "listIndexed[1]");
- assertNotNull("Returned new value 6", value);
- assertTrue("Returned String new value 6",
- value instanceof String);
- assertEquals("Returned correct new value 6", "New Value 2",
- (String) value);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "stringArray[1]",
- "New Value 2");
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringArray[2]");
- assertNotNull("Returned new value 6", value);
- assertTrue("Returned String new value 6",
- value instanceof String);
- assertEquals("Returned correct new value 6", "New Value 2",
- (String) value);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "stringArray[0]",
- "New Value 3");
- value =
- PropertyUtils.getIndexedProperty(bean,
- "stringArray[0]");
- assertNotNull("Returned new value 7", value);
- assertTrue("Returned String new value 7",
- value instanceof String);
- assertEquals("Returned correct new value 7", "New Value 3",
- (String) value);
- } catch (final Throwable t) {
- fail("Threw " + t);
- }
-
- // Index out of bounds tests
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "intArray", -1,
- new Integer(0));
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "intArray", 5,
- new Integer(0));
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "intIndexed", -1,
- new Integer(0));
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "intIndexed", 5,
- new Integer(0));
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "listIndexed", 5,
- "New String");
- fail("Should have thrown IndexOutOfBoundsException");
- } catch (final IndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IndexOutOfBoundsException");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "listIndexed", -1,
- "New String");
- fail("Should have thrown IndexOutOfBoundsException");
- } catch (final IndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IndexOutOfBoundsException");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "stringArray", -1,
- "New String");
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "stringArray", 5,
- "New String");
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "stringIndexed", -1,
- "New String");
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- try {
- PropertyUtils.setIndexedProperty(bean,
- "stringIndexed", 5,
- "New String");
- fail("Should have thrown ArrayIndexOutOfBoundsException");
- } catch (final ArrayIndexOutOfBoundsException t) {
- // Expected results
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");
- }
-
- }
-
- /**
- * Corner cases on getMappedProperty invalid arguments.
- */
- public void testSetMappedArguments() {
-
- // Use explicit key argument
-
- try {
- PropertyUtils.setMappedProperty(null, "mappedProperty",
- "First Key", "First Value");
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.setMappedProperty(bean, null, "First Key",
- "First Value");
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- try {
- PropertyUtils.setMappedProperty(bean, "mappedProperty", null,
- "First Value");
- fail("Should throw IllegalArgumentException 3");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 3");
- }
-
- // Use key expression
-
- try {
- PropertyUtils.setMappedProperty(null,
- "mappedProperty(First Key)",
- "First Value");
- fail("Should throw IllegalArgumentException 4");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 4");
- }
-
- try {
- PropertyUtils.setMappedProperty(bean, "(Second Key)",
- "Second Value");
- fail("Should throw IllegalArgumentException 5");
- } catch (final NoSuchMethodException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of NoSuchMethodException 5");
- }
-
- try {
- PropertyUtils.setMappedProperty(bean, "mappedProperty",
- "Third Value");
- fail("Should throw IllegalArgumentException 6");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 6");
- }
-
- }
-
- /**
- * Positive and negative tests on setMappedProperty valid arguments.
- */
- public void testSetMappedValues() {
-
- Object value = null;
-
- // Use explicit key argument
-
- try {
- value = PropertyUtils.getMappedProperty(bean, "mappedProperty",
- "Fourth Key");
- assertNull("Can not find fourth value", value);
- } catch (final Throwable t) {
- fail("Finding fourth value threw " + t);
- }
-
- try {
- PropertyUtils.setMappedProperty(bean, "mappedProperty",
- "Fourth Key", "Fourth Value");
- } catch (final Throwable t) {
- fail("Setting fourth value threw " + t);
- }
-
- try {
- value = PropertyUtils.getMappedProperty(bean, "mappedProperty",
- "Fourth Key");
- assertEquals("Can find fourth value", "Fourth Value", value);
- } catch (final Throwable t) {
- fail("Finding fourth value threw " + t);
- }
-
- // Use key expression with parentheses
-
- try {
- value =
- PropertyUtils.getMappedProperty(bean,
- "mappedProperty(Fifth Key)");
- assertNull("Can not find fifth value", value);
- } catch (final Throwable t) {
- fail("Finding fifth value threw " + t);
- }
-
- try {
- PropertyUtils.setMappedProperty(bean,
- "mappedProperty(Fifth Key)",
- "Fifth Value");
- } catch (final Throwable t) {
- fail("Setting fifth value threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getMappedProperty(bean,
- "mappedProperty(Fifth Key)");
- assertEquals("Can find fifth value", "Fifth Value", value);
- } catch (final Throwable t) {
- fail("Finding fifth value threw " + t);
- }
-
- // Use key expression with dotted expression
-
- try {
- value =
- PropertyUtils.getNestedProperty(bean,
- "mapProperty.Sixth Key");
- assertNull("Can not find sixth value", value);
- } catch (final Throwable t) {
- fail("Finding fifth value threw " + t);
- }
-
- try {
- PropertyUtils.setNestedProperty(bean,
- "mapProperty.Sixth Key",
- "Sixth Value");
- } catch (final Throwable t) {
- fail("Setting sixth value threw " + t);
- }
-
- try {
- value =
- PropertyUtils.getNestedProperty(bean,
- "mapProperty.Sixth Key");
- assertEquals("Can find sixth value", "Sixth Value", value);
- } catch (final Throwable t) {
- fail("Finding sixth value threw " + t);
- }
-
- }
-
- /**
- * Corner cases on setNestedProperty invalid arguments.
- */
- public void testSetNestedArguments() {
-
- try {
- PropertyUtils.setNestedProperty(null, "stringProperty", "");
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.setNestedProperty(bean, null, "");
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- }
-
- /**
- * Test setNextedProperty on a boolean property.
- */
- public void testSetNestedBoolean() {
-
- try {
- final boolean oldValue = nested.getBooleanProperty();
- final boolean newValue = !oldValue;
- PropertyUtils.setNestedProperty(bean,
- "nested.booleanProperty",
- new Boolean(newValue));
- assertTrue("Matched new value",
- newValue ==
- nested.getBooleanProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setNestedProperty on a double property.
- */
- public void testSetNestedDouble() {
-
- try {
- final double oldValue = nested.getDoubleProperty();
- final double newValue = oldValue + 1.0;
- PropertyUtils.setNestedProperty(bean,
- "nested.doubleProperty",
- new Double(newValue));
- assertEquals("Matched new value",
- newValue,
- nested.getDoubleProperty(),
- 0.005);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setNestedProperty on a float property.
- */
- public void testSetNestedFloat() {
-
- try {
- final float oldValue = nested.getFloatProperty();
- final float newValue = oldValue + (float) 1.0;
- PropertyUtils.setNestedProperty(bean,
- "nested.floatProperty",
- new Float(newValue));
- assertEquals("Matched new value",
- newValue,
- nested.getFloatProperty(),
- (float) 0.005);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setNestedProperty on a int property.
- */
- public void testSetNestedInt() {
-
- try {
- final int oldValue = nested.getIntProperty();
- final int newValue = oldValue + 1;
- PropertyUtils.setNestedProperty(bean,
- "nested.intProperty",
- new Integer(newValue));
- assertEquals("Matched new value",
- newValue,
- nested.getIntProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setNestedProperty on a long property.
- */
- public void testSetNestedLong() {
-
- try {
- final long oldValue = nested.getLongProperty();
- final long newValue = oldValue + 1;
- PropertyUtils.setNestedProperty(bean,
- "nested.longProperty",
- new Long(newValue));
- assertEquals("Matched new value",
- newValue,
- nested.getLongProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setNestedProperty on a read-only String property.
- */
- public void testSetNestedReadOnly() {
-
- try {
- final String oldValue = nested.getWriteOnlyPropertyValue();
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setNestedProperty(bean,
- "nested.readOnlyProperty",
- newValue);
- fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- // Correct result for this test
- }
-
- }
-
- /**
- * Test setNestedProperty on a short property.
- */
- public void testSetNestedShort() {
-
- try {
- final short oldValue = nested.getShortProperty();
- short newValue = oldValue;
- newValue++;
- PropertyUtils.setNestedProperty(bean,
- "nested.shortProperty",
- new Short(newValue));
- assertEquals("Matched new value",
- newValue,
- nested.getShortProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setNestedProperty on a String property.
- */
- public void testSetNestedString() {
-
- try {
- final String oldValue = nested.getStringProperty();
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setNestedProperty(bean,
- "nested.stringProperty",
- newValue);
- assertEquals("Matched new value",
- newValue,
- nested.getStringProperty());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setNestedProperty on an unknown property name.
- */
- public void testSetNestedUnknown() {
-
- try {
- final String newValue = "New String Value";
- PropertyUtils.setNestedProperty(bean,
- "nested.unknown",
- newValue);
- fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- // Correct result for this test
- }
-
- }
-
- /**
- * Test setNestedProperty on a write-only String property.
- */
- public void testSetNestedWriteOnly() {
-
- try {
- final String oldValue = nested.getWriteOnlyPropertyValue();
- final String newValue = oldValue + " Extra Value";
- PropertyUtils.setNestedProperty(bean,
- "nested.writeOnlyProperty",
- newValue);
- assertEquals("Matched new value",
- newValue,
- nested.getWriteOnlyPropertyValue());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Corner cases on setSimpleProperty invalid arguments.
- */
- public void testSetSimpleArguments() {
-
- try {
- PropertyUtils.setSimpleProperty(null, "stringProperty", "");
- fail("Should throw IllegalArgumentException 1");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 1");
- }
-
- try {
- PropertyUtils.setSimpleProperty(bean, null, "");
- fail("Should throw IllegalArgumentException 2");
- } catch (final IllegalArgumentException e) {
- // Expected response
- } catch (final Throwable t) {
- fail("Threw " + t + " instead of IllegalArgumentException 2");
- }
-
- }
-
- /**
- * Test setSimpleProperty on a boolean property.
- */
- public void testSetSimpleBoolean() {
-
- try {
- final boolean oldValue = ((Boolean) bean.get("booleanProperty")).booleanValue();
- final boolean newValue = !oldValue;
- PropertyUtils.setSimpleProperty(bean,
- "booleanProperty",
- new Boolean(newValue));
- assertTrue("Matched new value",
- newValue ==
- ((Boolean) bean.get("booleanProperty")).booleanValue());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setSimpleProperty on a double property.
- */
- public void testSetSimpleDouble() {
-
- try {
- final double oldValue = ((Double) bean.get("doubleProperty")).doubleValue();
- final double newValue = oldValue + 1.0;
- PropertyUtils.setSimpleProperty(bean,
- "doubleProperty",
- new Double(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Double) bean.get("doubleProperty")).doubleValue(),
- 0.005);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setSimpleProperty on a float property.
- */
- public void testSetSimpleFloat() {
-
- try {
- final float oldValue = ((Float) bean.get("floatProperty")).floatValue();
- final float newValue = oldValue + (float) 1.0;
- PropertyUtils.setSimpleProperty(bean,
- "floatProperty",
- new Float(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Float) bean.get("floatProperty")).floatValue(),
- (float) 0.005);
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Negative test setSimpleProperty on an indexed property.
- */
- public void testSetSimpleIndexed() {
-
- try {
- PropertyUtils.setSimpleProperty(bean,
- "stringIndexed[0]",
- "New String Value");
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- // Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setSimpleProperty on a int property.
- */
- public void testSetSimpleInt() {
-
- try {
- final int oldValue = ((Integer) bean.get("intProperty")).intValue();
- final int newValue = oldValue + 1;
- PropertyUtils.setSimpleProperty(bean,
- "intProperty",
- new Integer(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Integer) bean.get("intProperty")).intValue());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setSimpleProperty on a long property.
- */
- public void testSetSimpleLong() {
-
- try {
- final long oldValue = ((Long) bean.get("longProperty")).longValue();
- final long newValue = oldValue + 1;
- PropertyUtils.setSimpleProperty(bean,
- "longProperty",
- new Long(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Long) bean.get("longProperty")).longValue());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Negative test setSimpleProperty on a nested property.
- */
- public void testSetSimpleNested() {
-
- try {
- PropertyUtils.setSimpleProperty(bean,
- "nested.stringProperty",
- "New String Value");
- fail("Should have thrown IllegalArgumentException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- // Correct result for this test
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setSimpleProperty on a short property.
- */
- public void testSetSimpleShort() {
-
- try {
- final short oldValue = ((Short) bean.get("shortProperty")).shortValue();
- short newValue = oldValue;
- newValue++;
- PropertyUtils.setSimpleProperty(bean,
- "shortProperty",
- new Short(newValue));
- assertEquals("Matched new value",
- newValue,
- ((Short) bean.get("shortProperty")).shortValue());
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setSimpleProperty on a String property.
- */
- public void testSetSimpleString() {
-
- 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"));
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- fail("NoSuchMethodException");
- }
-
- }
-
- /**
- * Test setSimpleProperty on an unknown property name.
- */
- public void testSetSimpleUnknown() {
-
- try {
- final String newValue = "New String Value";
- PropertyUtils.setSimpleProperty(bean,
- "unknown",
- newValue);
- fail("Should have thrown NoSuchMethodException");
- } catch (final IllegalAccessException e) {
- fail("IllegalAccessException");
- } catch (final IllegalArgumentException e) {
- fail("IllegalArgumentException");
- } catch (final InvocationTargetException e) {
- fail("InvocationTargetException");
- } catch (final NoSuchMethodException e) {
- // Correct result for this test
- assertEquals("Unknown property 'unknown' on dynaclass '" +
- bean.getDynaClass() + "'", e.getMessage() );
- }
-
- }
-
-
-
- /**
- * Create and return a {@code DynaClass} instance for our test
- * {@code DynaBean}.
- */
- protected DynaClass createDynaClass() {
-
- final int[] intArray = new int[0];
- final String[] stringArray = new String[0];
-
- final DynaClass dynaClass = new BasicDynaClass
- ("TestDynaClass", null,
- new DynaProperty[]{
- new DynaProperty("booleanProperty", Boolean.TYPE),
- new DynaProperty("booleanSecond", Boolean.TYPE),
- new DynaProperty("doubleProperty", Double.TYPE),
- new DynaProperty("dupProperty", stringArray.getClass()),
- new DynaProperty("floatProperty", Float.TYPE),
- new DynaProperty("intArray", intArray.getClass()),
- new DynaProperty("intIndexed", intArray.getClass()),
- new DynaProperty("intProperty", Integer.TYPE),
- new DynaProperty("listIndexed", List.class),
- new DynaProperty("longProperty", Long.TYPE),
- new DynaProperty("mapProperty", Map.class),
- new DynaProperty("mappedObjects", Map.class),
- new DynaProperty("mappedProperty", Map.class),
- new DynaProperty("mappedIntProperty", Map.class),
- new DynaProperty("nested", TestBean.class),
- new DynaProperty("nullProperty", String.class),
- new DynaProperty("shortProperty", Short.TYPE),
- new DynaProperty("stringArray", stringArray.getClass()),
- new DynaProperty("stringIndexed", stringArray.getClass()),
- new DynaProperty("stringProperty", String.class),
- });
- return dynaClass;
-
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaResultSetTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaResultSetTestCase.java
deleted file mode 100644
index 90c9f3369..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaResultSetTestCase.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.math.BigDecimal;
-import java.util.Iterator;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test accessing ResultSets via DynaBeans.
- *
- */
-
-public class DynaResultSetTestCase extends TestCase {
-
-
-
- /**
- * The mock result set DynaClass to be tested.
- */
- protected ResultSetDynaClass dynaClass = null;
-
- /**
- * Names of the columns for this test. Must match the order they are
- * defined in {@link TestResultSetMetaData}, and must be all lower case.
- */
- protected String[] columns =
- { "bigdecimalproperty", "booleanproperty",
- "byteproperty", "dateproperty",
- "doubleproperty", "floatproperty",
- "intproperty", "longproperty",
- "nullproperty", "shortproperty",
- "stringproperty", "timeproperty",
- "timestampproperty" };
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public DynaResultSetTestCase(final String name) {
-
- super(name);
-
- }
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
-
- dynaClass = new ResultSetDynaClass(TestResultSet.createProxy());
-
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
-
- return new TestSuite(DynaResultSetTestCase.class);
-
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
-
- dynaClass = null;
-
- }
-
-
-
- public void testGetName() {
-
- assertEquals("DynaClass name",
- "org.apache.commons.beanutils2.ResultSetDynaClass",
- dynaClass.getName());
-
- }
-
- public void testGetDynaProperty() {
-
- // Invalid argument test
- try {
- dynaClass.getDynaProperty(null);
- fail("Did not throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- // Expected result
- }
-
- // Negative test
- DynaProperty dynaProp = dynaClass.getDynaProperty("unknownProperty");
- assertTrue("unknown property returns null",
- dynaProp == null);
-
- // Positive test
- dynaProp = dynaClass.getDynaProperty("stringproperty");
- assertNotNull("string property exists", dynaProp);
- assertEquals("string property name", "stringproperty",
- dynaProp.getName());
- assertEquals("string property class", String.class,
- dynaProp.getType());
-
- }
-
- public void testGetDynaProperties() {
-
- final DynaProperty[] dynaProps = dynaClass.getDynaProperties();
- assertNotNull("dynaProps exists", dynaProps);
- assertEquals("dynaProps length", columns.length, dynaProps.length);
- for (int i = 0; i < columns.length; i++) {
- assertEquals("Property " + columns[i],
- columns[i], dynaProps[i].getName());
- }
-
- }
-
- public void testNewInstance() {
-
- try {
- dynaClass.newInstance();
- fail("Did not throw UnsupportedOperationException()");
- } catch (final UnsupportedOperationException e) {
- // Expected result
- } catch (final Exception e) {
- fail("Threw exception " + e);
- }
-
- }
-
- public void testIteratorCount() {
-
- final Iterator> rows = dynaClass.iterator();
- assertNotNull("iterator exists", rows);
- int n = 0;
- while (rows.hasNext()) {
- rows.next();
- n++;
- if (n > 10) {
- fail("Returned too many rows");
- }
- }
- assertEquals("iterator rows", 5, n);
-
- }
-
- public void testIteratorResults() {
-
- // Grab the third row
- final Iterator rows = dynaClass.iterator();
- rows.next();
- rows.next();
- final DynaBean row = rows.next();
-
- // Invalid argument test
- try {
- row.get("unknownProperty");
- fail("Did not throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- // Expected result
- }
-
- // Verify property values
-
- final Object bigDecimalProperty = row.get("bigdecimalproperty");
- assertNotNull("bigDecimalProperty exists", bigDecimalProperty);
- assertTrue("bigDecimalProperty type",
- bigDecimalProperty instanceof BigDecimal);
- assertEquals("bigDecimalProperty value",
- 123.45,
- ((BigDecimal) bigDecimalProperty).doubleValue(),
- 0.005);
-
- final Object intProperty = row.get("intproperty");
- assertNotNull("intProperty exists", intProperty);
- assertTrue("intProperty type",
- intProperty instanceof Integer);
- assertEquals("intProperty value",
- 103,
- ((Integer) intProperty).intValue());
-
- final Object nullProperty = row.get("nullproperty");
- assertNull("nullProperty null", nullProperty);
-
- final Object stringProperty = row.get("stringproperty");
- assertNotNull("stringProperty exists", stringProperty);
- assertTrue("stringProperty type",
- stringProperty instanceof String);
- assertEquals("stringProperty value",
- "This is a string",
- (String) stringProperty);
-
- }
-
- /**
- * Test normal case column names (i.e. not converted to lower case)
- */
- public void testIteratorResultsNormalCase() {
- ResultSetDynaClass dynaClass = null;
- try {
- dynaClass = new ResultSetDynaClass(TestResultSet.createProxy(), false);
- } catch (final Exception e) {
- fail("Error creating ResultSetDynaClass: " + e);
- }
-
- // Grab the third row
- final Iterator rows = dynaClass.iterator();
- rows.next();
- rows.next();
- final DynaBean row = rows.next();
-
- // Invalid argument test
- try {
- row.get("unknownProperty");
- fail("Did not throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- // Expected result
- }
-
- // Verify property values
-
- final Object bigDecimalProperty = row.get("bigDecimalProperty");
- assertNotNull("bigDecimalProperty exists", bigDecimalProperty);
- assertTrue("bigDecimalProperty type",
- bigDecimalProperty instanceof BigDecimal);
- assertEquals("bigDecimalProperty value",
- 123.45,
- ((BigDecimal) bigDecimalProperty).doubleValue(),
- 0.005);
-
- final Object intProperty = row.get("intProperty");
- assertNotNull("intProperty exists", intProperty);
- assertTrue("intProperty type",
- intProperty instanceof Integer);
- assertEquals("intProperty value",
- 103,
- ((Integer) intProperty).intValue());
-
- final Object nullProperty = row.get("nullProperty");
- assertNull("nullProperty null", nullProperty);
-
- final Object stringProperty = row.get("stringProperty");
- assertNotNull("stringProperty exists", stringProperty);
- assertTrue("stringProperty type",
- stringProperty instanceof String);
- assertEquals("stringProperty value",
- "This is a string",
- (String) stringProperty);
-
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaRowSetTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaRowSetTestCase.java
deleted file mode 100644
index 77608335a..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/DynaRowSetTestCase.java
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.math.BigDecimal;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Test accessing RowSets via DynaBeans.
- *
- */
-
-public class DynaRowSetTestCase extends TestCase {
-
-
-
- /**
- * The mock result set DynaClass to be tested.
- */
- protected RowSetDynaClass dynaClass = null;
-
- /**
- * Names of the columns for this test. Must match the order they are
- * defined in {@link TestResultSetMetaData}, and must be all lower case.
- */
- protected String[] columns =
- { "bigdecimalproperty", "booleanproperty",
- "byteproperty", "dateproperty",
- "doubleproperty", "floatproperty",
- "intproperty", "longproperty",
- "nullproperty", "shortproperty",
- "stringproperty", "timeproperty",
- "timestampproperty" };
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public DynaRowSetTestCase(final String name) {
-
- super(name);
-
- }
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
-
- dynaClass = new RowSetDynaClass(TestResultSet.createProxy());
-
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
-
- return new TestSuite(DynaRowSetTestCase.class);
-
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
-
- dynaClass = null;
-
- }
-
-
-
- public void testGetName() {
-
- assertEquals("DynaClass name",
- "org.apache.commons.beanutils2.RowSetDynaClass",
- dynaClass.getName());
-
- }
-
- public void testGetDynaProperty() {
-
- // Invalid argument test
- try {
- dynaClass.getDynaProperty(null);
- fail("Did not throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- // Expected result
- }
-
- // Negative test
- DynaProperty dynaProp = dynaClass.getDynaProperty("unknownProperty");
- assertTrue("unknown property returns null",
- dynaProp == null);
-
- // Positive test
- dynaProp = dynaClass.getDynaProperty("stringproperty");
- assertNotNull("string property exists", dynaProp);
- assertEquals("string property name", "stringproperty",
- dynaProp.getName());
- assertEquals("string property class", String.class,
- dynaProp.getType());
-
- }
-
- public void testGetDynaProperties() {
-
- final DynaProperty[] dynaProps = dynaClass.getDynaProperties();
- assertNotNull("dynaProps exists", dynaProps);
- assertEquals("dynaProps length", columns.length, dynaProps.length);
- for (int i = 0; i < columns.length; i++) {
- assertEquals("Property " + columns[i],
- columns[i], dynaProps[i].getName());
- }
-
- }
-
- public void testNewInstance() {
-
- try {
- dynaClass.newInstance();
- fail("Did not throw UnsupportedOperationException()");
- } catch (final UnsupportedOperationException e) {
- // Expected result
- } catch (final Exception e) {
- fail("Threw exception " + e);
- }
-
- }
-
- public void testListCount() {
-
- final List rows = dynaClass.getRows();
- assertNotNull("list exists", rows);
- assertEquals("list row count", 5, rows.size());
-
- }
-
- public void testListResults() {
-
- // Grab the third row
- final List rows = dynaClass.getRows();
- final DynaBean row = rows.get(2);
-
- // Invalid argument test
- try {
- row.get("unknownProperty");
- fail("Did not throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- // Expected result
- }
-
- // Verify property values
-
- final Object bigDecimalProperty = row.get("bigdecimalproperty");
- assertNotNull("bigDecimalProperty exists", bigDecimalProperty);
- assertTrue("bigDecimalProperty type",
- bigDecimalProperty instanceof BigDecimal);
- assertEquals("bigDecimalProperty value",
- 123.45,
- ((BigDecimal) bigDecimalProperty).doubleValue(),
- 0.005);
-
- final Object intProperty = row.get("intproperty");
- assertNotNull("intProperty exists", intProperty);
- assertTrue("intProperty type",
- intProperty instanceof Integer);
- assertEquals("intProperty value",
- 103,
- ((Integer) intProperty).intValue());
-
- final Object nullProperty = row.get("nullproperty");
- assertNull("nullProperty null", nullProperty);
-
- final Object stringProperty = row.get("stringproperty");
- assertNotNull("stringProperty exists", stringProperty);
- assertTrue("stringProperty type",
- stringProperty instanceof String);
- assertEquals("stringProperty value",
- "This is a string",
- (String) stringProperty);
-
- }
-
- /**
- * Test normal case column names (i.e. not converted to lower case)
- */
- public void testListResultsNormalCase() {
- RowSetDynaClass dynaClass = null;
- try {
- dynaClass = new RowSetDynaClass(TestResultSet.createProxy(), false);
- } catch (final Exception e) {
- fail("Error creating RowSetDynaClass: " + e);
- }
-
- // Grab the third row
- final List rows = dynaClass.getRows();
- final DynaBean row = rows.get(2);
-
- // Invalid argument test
- try {
- row.get("unknownProperty");
- fail("Did not throw IllegalArgumentException");
- } catch (final IllegalArgumentException e) {
- // Expected result
- }
-
- // Verify property values
-
- final Object bigDecimalProperty = row.get("bigDecimalProperty");
- assertNotNull("bigDecimalProperty exists", bigDecimalProperty);
- assertTrue("bigDecimalProperty type",
- bigDecimalProperty instanceof BigDecimal);
- assertEquals("bigDecimalProperty value",
- 123.45,
- ((BigDecimal) bigDecimalProperty).doubleValue(),
- 0.005);
-
- final Object intProperty = row.get("intProperty");
- assertNotNull("intProperty exists", intProperty);
- assertTrue("intProperty type",
- intProperty instanceof Integer);
- assertEquals("intProperty value",
- 103,
- ((Integer) intProperty).intValue());
-
- final Object nullProperty = row.get("nullProperty");
- assertNull("nullProperty null", nullProperty);
-
- final Object stringProperty = row.get("stringProperty");
- assertNotNull("stringProperty exists", stringProperty);
- assertTrue("stringProperty type",
- stringProperty instanceof String);
- assertEquals("stringProperty value",
- "This is a string",
- (String) stringProperty);
-
- }
-
- public void testLimitedRows() throws Exception {
-
- // created one with low limit
- final RowSetDynaClass limitedDynaClass = new RowSetDynaClass(TestResultSet.createProxy(), 3);
- final List rows = limitedDynaClass.getRows();
- assertNotNull("list exists", rows);
- assertEquals("limited row count", 3, rows.size());
-
- }
-
- /**
- * Test issues associated with Oracle JDBC driver.
- *
- * See issue# https://issues.apache.org/jira/browse/BEANUTILS-142
- *
- * @throws Exception if an error occurs
- */
- public void testInconsistentOracleDriver() throws Exception {
-
- final ResultSetMetaData metaData = TestResultSetMetaData.createProxy(new TestResultSetMetaDataInconsistent());
- final ResultSet resultSet = TestResultSet.createProxy(new TestResultSetInconsistent(metaData));
-
- // Date Column returns "java.sql.Timestamp" for the column class name but ResultSet getObject
- // returns a java.sql.Date value
- final int dateColIdx = 4;
- assertEquals("Date Meta Name", "dateProperty", metaData.getColumnName(dateColIdx));
- assertEquals("Date Meta Class", "java.sql.Timestamp", metaData.getColumnClassName(dateColIdx));
- assertEquals("Date Meta Type", java.sql.Types.DATE, metaData.getColumnType(dateColIdx));
- assertEquals("Date ResultSet Value", java.sql.Date.class, resultSet.getObject("dateProperty").getClass());
-
- // Timestamp column class returns a custom Timestamp impl for the column class name and ResultSet getObject
- final int timestampColIdx = 13;
- assertEquals("Timestamp Meta Name", "timestampProperty", metaData.getColumnName(timestampColIdx));
- assertEquals("Timestamp Meta Class", CustomTimestamp.class.getName(), metaData.getColumnClassName(timestampColIdx));
- assertEquals("Timestamp Meta Type", java.sql.Types.TIMESTAMP, metaData.getColumnType(timestampColIdx));
- assertEquals("Timestamp ResultSet Value", CustomTimestamp.class, resultSet.getObject("timestampProperty").getClass());
-
- final RowSetDynaClass inconsistentDynaClass = new RowSetDynaClass(resultSet);
- final DynaBean firstRow = inconsistentDynaClass.getRows().get(0);
- Class> expectedType = null;
- DynaProperty property = null;
-
- // Test Date
- property = firstRow.getDynaClass().getDynaProperty("dateproperty");
- expectedType = java.sql.Date.class;
- assertEquals("Date Class", expectedType, property.getType());
- assertEquals("Date Value", expectedType, firstRow.get(property.getName()).getClass());
-
- // Test Timestamp
- property = firstRow.getDynaClass().getDynaProperty("timestampproperty");
- expectedType = java.sql.Timestamp.class;
- assertEquals("Timestamp Class", expectedType, property.getType());
- assertEquals("Timestamp Value", expectedType, firstRow.get(property.getName()).getClass());
- }
-
- /**
- * A proxy ResultSet implementation that returns Timstamp for a date column.
- *
- * See issue# https://issues.apache.org/jira/browse/BEANUTILS-142
- */
- private static class TestResultSetInconsistent extends TestResultSet {
-
- public TestResultSetInconsistent(final ResultSetMetaData metaData) {
- super(metaData);
- }
- /**
- * Get an columns's value
- * @param columnName Name of the column
- * @return the column value
- * @throws SQLException if an error occurs
- */
- @Override
- public Object getObject(final String columnName) throws SQLException {
- if ("timestampProperty".equals(columnName)) {
- return new CustomTimestamp();
- }
- return super.getObject(columnName);
- }
-
- }
-
- /**
- * A proxy ResultSetMetaData implementation that returns a class name that
- * is inconsistent with the type returned by the ResultSet.getObject() method.
- *
- * See issue# https://issues.apache.org/jira/browse/BEANUTILS-142
- */
- private static class TestResultSetMetaDataInconsistent extends TestResultSetMetaData {
-
- /**
- * This method substitues class names of "java.sql.Timestamp" with
- * "java.sql.Date" to test inconsistent JDBC drivers.
- *
- * @param columnIndex The column index
- * @return The column class name
- * @throws SQLException if an error occurs
- */
- @Override
- public String getColumnClassName(final int columnIndex) throws SQLException {
- final String columnName = getColumnName(columnIndex);
- if (columnName.equals("dateProperty")) {
- return java.sql.Timestamp.class.getName();
- } else if (columnName.equals("timestampProperty")) {
- return CustomTimestamp.class.getName();
- } else {
- return super.getColumnClassName(columnIndex);
- }
- }
- }
- private static class CustomTimestamp {
- private final long timestamp = new java.util.Date().getTime();
- @Override
- public String toString() {
- return "CustomTimestamp[" + timestamp + "]";
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/ExtendMapBean.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/ExtendMapBean.java
deleted file mode 100644
index f2b13d17d..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/ExtendMapBean.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.util.Hashtable;
-
-/**
- * Used to test
- *
- */
-
-public class ExtendMapBean extends Hashtable {
-
- private String dbName = "[UNSET]";
-
- public ExtendMapBean() {}
-
- public String getUnusuallyNamedProperty()
- {
- return dbName;
- }
-
- public void setUnusuallyNamedProperty(final String dbName)
- {
- this.dbName = dbName;
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/FluentIntrospectionTestBean.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/FluentIntrospectionTestBean.java
deleted file mode 100644
index 7c368c6ff..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/FluentIntrospectionTestBean.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-/**
- * A bean class used for tests of introspection.
- *
- */
-public class FluentIntrospectionTestBean extends AlphaBean {
- private String stringProperty;
-
- private String fluentGetProperty;
-
- public String getStringProperty() {
- return stringProperty;
- }
-
- public void setStringProperty(final String stringProperty) {
- this.stringProperty = stringProperty;
- }
-
- public FluentIntrospectionTestBean setFluentProperty(final String value) {
- setStringProperty(value);
- return this;
- }
-
- public String getFluentGetProperty() {
- return fluentGetProperty;
- }
-
- public FluentIntrospectionTestBean setFluentGetProperty(
- final String fluentGetProperty) {
- this.fluentGetProperty = fluentGetProperty;
- return this;
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/FluentPropertyBeanIntrospectorTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/FluentPropertyBeanIntrospectorTestCase.java
deleted file mode 100644
index 3722de67d..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/FluentPropertyBeanIntrospectorTestCase.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.beans.IntrospectionException;
-import java.beans.PropertyDescriptor;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-/**
- * Test class for {@code FluentPropertyBeanIntrospector}.
- *
- */
-public class FluentPropertyBeanIntrospectorTestCase extends TestCase {
- /**
- * Puts all property descriptors into a map so that they can be accessed by
- * property name.
- *
- * @param descs the array with descriptors
- * @return a map with property names as keys
- */
- private static Map createDescriptorMap(
- final PropertyDescriptor[] descs) {
- final Map map = new HashMap<>();
- for (final PropertyDescriptor pd : descs) {
- map.put(pd.getName(), pd);
- }
- return map;
- }
-
- /**
- * Convenience method for obtaining a specific property descriptor and
- * checking whether it exists.
- *
- * @param props the map with property descriptors
- * @param name the name of the desired descriptor
- * @return the descriptor from the map
- */
- private static PropertyDescriptor fetchDescriptor(
- final Map props, final String name) {
- assertTrue("Property not found: " + name, props.containsKey(name));
- return props.get(name);
- }
-
- /**
- * Tries to create an instance without a prefix for write methods.
- */
- public void testInitNoPrefix() {
- try {
- new FluentPropertyBeanIntrospector(null);
- fail("Missing prefix for write methods not detected!");
- } catch (final IllegalArgumentException iex) {
- // ok
- }
- }
-
- /**
- * Tests whether correct property descriptors are detected.
- */
- public void testIntrospection() throws IntrospectionException {
- final PropertyUtilsBean pu = new PropertyUtilsBean();
- final FluentPropertyBeanIntrospector introspector = new FluentPropertyBeanIntrospector();
- pu.addBeanIntrospector(introspector);
- final Map props = createDescriptorMap(pu
- .getPropertyDescriptors(FluentIntrospectionTestBean.class));
- PropertyDescriptor pd = fetchDescriptor(props, "name");
- assertNotNull("No read method for name", pd.getReadMethod());
- assertNotNull("No write method for name", pd.getWriteMethod());
- fetchDescriptor(props, "stringProperty");
- pd = fetchDescriptor(props, "fluentProperty");
- assertNull("Read method for fluentProperty", pd.getReadMethod());
- assertNotNull("No write method for fluentProperty", pd.getWriteMethod());
- pd = fetchDescriptor(props, "fluentGetProperty");
- assertNotNull("No read method for fluentGetProperty",
- pd.getReadMethod());
- assertNotNull("No write method for fluentGetProperty",
- pd.getWriteMethod());
- }
-
- public void testIntrospectionCaps() throws Exception {
- final PropertyUtilsBean pu = new PropertyUtilsBean();
-
- final FluentPropertyBeanIntrospector introspector = new FluentPropertyBeanIntrospector();
-
- pu.addBeanIntrospector(introspector);
-
- final Map props = createDescriptorMap(
- pu.getPropertyDescriptors(CapsBean.class));
-
- final PropertyDescriptor aDescriptor = fetchDescriptor(props, "URI");
-
- assertNotNull("missing property", aDescriptor);
-
- assertNotNull("No read method for uri", aDescriptor.getReadMethod());
- assertNotNull("No write method for uri", aDescriptor.getWriteMethod());
-
- assertNull("Should not find mis-capitalized property", props.get("uRI"));
- }
-
- public static final class CapsBean {
- private URI mURI;
-
- public URI getURI() {
- return mURI;
- }
-
- public void setURI(final URI theURI) {
- mURI = theURI;
- }
- }
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/IndexedPropertyTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/IndexedPropertyTestCase.java
deleted file mode 100644
index 96a4f7f49..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/IndexedPropertyTestCase.java
+++ /dev/null
@@ -1,449 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assume.assumeTrue;
-
-import java.beans.IndexedPropertyDescriptor;
-import java.beans.PropertyDescriptor;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.beanutils2.bugs.other.Jira492IndexedListsSupport;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- *
Test Case for the Indexed Properties.
- *
- */
-
-public class IndexedPropertyTestCase {
-
-
-
- /**
- * The test bean for each test.
- */
- private IndexedTestBean bean = null;
- private BeanUtilsBean beanUtilsBean;
- private PropertyUtilsBean propertyUtilsBean;
- private String[] testArray;
- private String[] newArray;
- private List testList;
- private List newList;
- private ArrayList arrayList;
-
-
-
- /**
- * Set up instance variables required by this test case.
- */
- @Before
- public void setUp() {
-
- // BeanUtils
- beanUtilsBean = new BeanUtilsBean();
- propertyUtilsBean = beanUtilsBean.getPropertyUtils();
-
- // initialize Arrays and Lists
- testArray= new String[] {"array-0", "array-1", "array-2"};
- newArray = new String[] {"newArray-0", "newArray-1", "newArray-2"};
-
- testList = new ArrayList<>();
- testList.add("list-0");
- testList.add("list-1");
- testList.add("list-2");
-
- newList = new ArrayList<>();
- newList.add("newList-0");
- newList.add("newList-1");
- newList.add("newList-2");
-
- arrayList = new ArrayList<>();
- arrayList.add("arrayList-0");
- arrayList.add("arrayList-1");
- arrayList.add("arrayList-2");
-
- // initialize Test Bean properties
- bean = new IndexedTestBean();
- bean.setStringArray(testArray);
- bean.setStringList(testList);
- bean.setArrayList(arrayList);
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @After
- public void tearDown() {
- bean = null;
- }
-
-
-
- /**
- * Test IndexedPropertyDescriptor for an Array
- */
- @Test
- public void testArrayIndexedPropertyDescriptor() throws Exception {
- final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
- assertNotNull("No Array Descriptor", descriptor);
- assertEquals("Not IndexedPropertyDescriptor",
- IndexedPropertyDescriptor.class,
- descriptor.getClass());
- assertEquals("PropertyDescriptor Type invalid",
- testArray.getClass(),
- descriptor.getPropertyType());
- }
-
- /**
- * Test IndexedPropertyDescriptor for a List
- */
- @Test
- public void testListIndexedPropertyDescriptor() throws Exception {
- final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
- assertNotNull("No List Descriptor", descriptor);
- if (Jira492IndexedListsSupport.supportsIndexedLists()) {
- // BEANUTILS-492 - can't assume lists are handled as arrays in Java 8+
- assertEquals("Not IndexedPropertyDescriptor",
- IndexedPropertyDescriptor.class, descriptor.getClass());
- }
- assertEquals("PropertyDescriptor Type invalid",
- List.class,
- descriptor.getPropertyType());
- }
-
- /**
- * Test IndexedPropertyDescriptor for an ArrayList
- */
- @Test
- public void testArrayListIndexedPropertyDescriptor() throws Exception {
- final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "arrayList");
- assertNotNull("No ArrayList Descriptor", descriptor);
- if (Jira492IndexedListsSupport.supportsIndexedLists()) {
- assertEquals("Not IndexedPropertyDescriptor",
- IndexedPropertyDescriptor.class, descriptor.getClass());
- }
- assertEquals("PropertyDescriptor Type invalid",
- ArrayList.class,
- descriptor.getPropertyType());
- }
-
- /**
- * Test Read Method for an Array
- */
- @Test
- public void testArrayReadMethod() throws Exception {
- final PropertyDescriptor descriptor =
- propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
- assertNotNull("No Array Read Method", descriptor.getReadMethod());
- }
-
- /**
- * Test Write Method for an Array
- */
- @Test
- public void testArrayWriteMethod() throws Exception {
- final PropertyDescriptor descriptor =
- propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
- assertNotNull("No Array Write Method", descriptor.getWriteMethod());
- }
-
- /**
- * Test Indexed Read Method for an Array
- */
- @Test
- public void testArrayIndexedReadMethod() throws Exception {
- final IndexedPropertyDescriptor descriptor =
- (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
- assertNotNull("No Array Indexed Read Method", descriptor.getIndexedReadMethod());
- }
-
- /**
- * Test Indexed Write Method for an Array
- */
- @Test
- public void testArrayIndexedWriteMethod() throws Exception {
- final IndexedPropertyDescriptor descriptor =
- (IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringArray");
- assertNotNull("No Array Indexed Write Method", descriptor.getIndexedWriteMethod());
- }
-
- /**
- * Test Read Method for a List
- *
- * JDK 1.3.1_04: Test Passes
- * JDK 1.4.2_05: Test Fails - getter which returns java.util.List not returned
- * by IndexedPropertyDescriptor.getReadMethod();
- */
- @Test
- public void testListReadMethod() throws Exception {
- final PropertyDescriptor descriptor =
- propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
- assertNotNull("No List Read Method", descriptor.getReadMethod());
- }
-
- /**
- * Test Write Method for a List
- *
- * JDK 1.3.1_04: Test Passes
- * JDK 1.4.2_05: Test Fails - setter which java.util.List argument not returned
- * by IndexedPropertyDescriptor.getWriteMethod();
- */
- @Test
- public void testListWriteMethod() throws Exception {
- final PropertyDescriptor descriptor =
- propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
- assertNotNull("No List Write Method", descriptor.getWriteMethod());
- }
-
- /**
- * Test Indexed Read Method for a List
- */
- @Test
- public void testListIndexedReadMethod() throws Exception {
- final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
- assertNotNull("stringList descriptor not found", descriptor);
- assumeTrue("JDK does not support index bean properties on java.util.List",
- Jira492IndexedListsSupport.supportsIndexedLists());
- assertNotNull("No List Indexed Read Method", ((IndexedPropertyDescriptor)descriptor).getIndexedReadMethod());
- }
-
- /**
- * Test Indexed Write Method for a List
- */
- @Test
- public void testListIndexedWriteMethod() throws Exception {
- final PropertyDescriptor descriptor = propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
- assertNotNull("stringList descriptor not found", descriptor);
- assumeTrue("JDK does not support index bean properties on java.util.List",
- Jira492IndexedListsSupport.supportsIndexedLists());
- assertNotNull("No List Indexed Write Method", ((IndexedPropertyDescriptor)descriptor).getIndexedWriteMethod());
- }
-
- /**
- * Test Read Method for an ArrayList
- */
- @Test
- public void testArrayListReadMethod() throws Exception {
- final PropertyDescriptor descriptor =
- propertyUtilsBean.getPropertyDescriptor(bean, "arrayList");
- assertNotNull("No ArrayList Read Method", descriptor.getReadMethod());
- }
-
- /**
- * Test Write Method for an ArrayList
- */
- @Test
- public void testArrayListWriteMethod() throws Exception {
- final PropertyDescriptor descriptor =
- propertyUtilsBean.getPropertyDescriptor(bean, "arrayList");
- assertNotNull("No ArrayList Write Method", descriptor.getWriteMethod());
- }
-
- /**
- * Test getting an array property
- */
- @Test
- public void testGetArray() throws Exception {
- assertEquals(testArray,
- propertyUtilsBean.getProperty(bean, "stringArray"));
- }
-
- /**
- * Test getting an array property as a String
- *
- * NOTE: Why does retrieving array just return the first element in the array, whereas
- * retrieving a List returns a comma separated list of all the elements?
- */
- @Test
- public void testGetArrayAsString() throws Exception {
- assertEquals("array-0",
- beanUtilsBean.getProperty(bean, "stringArray"));
- }
-
- /**
- * Test getting an indexed item of an Array using getProperty("name[x]")
- */
- @Test
- public void testGetArrayItemA() throws Exception {
- assertEquals("array-1",
- beanUtilsBean.getProperty(bean, "stringArray[1]"));
- }
-
- /**
- * Test getting an indexed item of an Array using getIndexedProperty("name")
- */
- @Test
- public void testGetArrayItemB() throws Exception {
- assertEquals("array-1",
- beanUtilsBean.getIndexedProperty(bean, "stringArray", 1));
- }
-
- /**
- * Test getting a List
- *
- * JDK 1.3.1_04: Test Passes
- * JDK 1.4.2_05: Test Fails - fails NoSuchMethodException, i.e. reason as testListReadMethod()
- * failed.
- */
- @Test
- public void testGetList() throws Exception {
- assertEquals(testList,
- propertyUtilsBean.getProperty(bean, "stringList"));
- }
-
- /**
- * Test getting a List property as a String
- *
- * JDK 1.3.1_04: Test Passes
- * JDK 1.4.2_05: Test Fails - fails NoSuchMethodException, i.e. reason as testListReadMethod()
- * failed.
- */
- @Test
- public void testGetListAsString() throws Exception {
- assertEquals("list-0",
- beanUtilsBean.getProperty(bean, "stringList"));
- }
-
- /**
- * Test getting an indexed item of a List using getProperty("name[x]")
- */
- @Test
- public void testGetListItemA() throws Exception {
- assertEquals("list-1",
- beanUtilsBean.getProperty(bean, "stringList[1]"));
- }
-
- /**
- * Test getting an indexed item of a List using getIndexedProperty("name")
- */
- @Test
- public void testGetListItemB() throws Exception {
- assertEquals("list-1",
- beanUtilsBean.getIndexedProperty(bean, "stringList", 1));
- }
-
- /**
- * Test setting an Array property
- *
- * JDK 1.3.1_04 and 1.4.2_05: Test Fails - IllegalArgumentException can't invoke setter, argument type mismatch
- *
- * Fails because of a bug in BeanUtilsBean.setProperty() method. Value is always converted to the array's component
- * type which in this case is a String. Then it calls the setStringArray(String[]) passing a String rather than
- * String[] causing this exception. If there isn't an "index" value then the PropertyType (rather than
- * IndexedPropertyType) should be used.
- *
- */
- @Test
- public void testSetArray() throws Exception {
- beanUtilsBean.setProperty(bean, "stringArray", newArray);
- final Object value = bean.getStringArray();
- assertEquals("Type is different", newArray.getClass(), value.getClass());
- final String[] array = (String[])value;
- assertEquals("Array Length is different", newArray.length, array.length);
- for (int i = 0; i < array.length; i++) {
- assertEquals("Element " + i + " is different", newArray[i], array[i]);
- }
- }
-
- /**
- * Test setting an indexed item of an Array using setProperty("name[x]", value)
- */
- @Test
- public void testSetArrayItemA() throws Exception {
- beanUtilsBean.setProperty(bean, "stringArray[1]", "modified-1");
- assertEquals("modified-1", bean.getStringArray(1));
- }
-
- /**
- * Test setting an indexed item of an Array using setIndexedProperty("name", value)
- */
- @Test
- public void testSetArrayItemB() throws Exception {
- propertyUtilsBean.setIndexedProperty(bean, "stringArray", 1, "modified-1");
- assertEquals("modified-1", bean.getStringArray(1));
- }
-
- /**
- * Test setting a List property
- *
- * JDK 1.3.1_04: Test Passes
- * JDK 1.4.2_05: Test Fails - setter which returns java.util.List not returned
- * by IndexedPropertyDescriptor.getWriteMethod() - therefore
- * setProperty does nothing and values remain unchanged.
- */
- @Test
- public void testSetList() throws Exception {
- beanUtilsBean.setProperty(bean, "stringList", newList);
- final Object value = bean.getStringList();
- assertEquals("Type is different", newList.getClass(), value.getClass());
- final List> list = (List>)value;
- assertEquals("List size is different", newList.size(), list.size());
- for (int i = 0; i < list.size(); i++) {
- assertEquals("Element " + i + " is different", newList.get(i), list.get(i));
- }
- }
-
- /**
- * Test setting an indexed item of a List using setProperty("name[x]", value)
- */
- @Test
- public void testSetListItemA() throws Exception {
- beanUtilsBean.setProperty(bean, "stringList[1]", "modified-1");
- assertEquals("modified-1", bean.getStringList(1));
- }
-
- /**
- * Test setting an indexed item of a List using setIndexedProperty("name", value)
- */
- @Test
- public void testSetListItemB() throws Exception {
- propertyUtilsBean.setIndexedProperty(bean, "stringList", 1, "modified-1");
- assertEquals("modified-1", bean.getStringList(1));
- }
-
- /**
- * Test getting an ArrayList
- */
- @Test
- public void testGetArrayList() throws Exception {
- assertEquals(arrayList,
- propertyUtilsBean.getProperty(bean, "arrayList"));
- }
-
- /**
- * Test setting an ArrayList property
- */
- @Test
- public void testSetArrayList() throws Exception {
- beanUtilsBean.setProperty(bean, "arrayList", newList);
- final Object value = bean.getArrayList();
- assertEquals("Type is different", newList.getClass(), value.getClass());
- final List> list = (List>)value;
- assertEquals("List size is different", newList.size(), list.size());
- for (int i = 0; i < list.size(); i++) {
- assertEquals("Element " + i + " is different", newList.get(i), list.get(i));
- }
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/IndexedTestBean.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/IndexedTestBean.java
deleted file mode 100644
index e90199e88..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/IndexedTestBean.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.commons.beanutils2;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Indexed Properties Test bean for JUnit tests for the "beanutils" component.
- *
- */
-public class IndexedTestBean {
-
- private String[] stringArray;
- private List stringList;
- private ArrayList arrayList;
-
-
-
- /**
- * Default Constructor.
- */
- public IndexedTestBean() {
- }
-
- /**
- * Getter for the String[] property.
- */
- public String[] getStringArray() {
- return stringArray;
- }
-
- /**
- * Setter for the String[] property.
- */
- public void setStringArray(final String[] stringArray) {
- this.stringArray = stringArray;
- }
-
- /**
- * Indexed Getter for the String[] property.
- */
- public String getStringArray(final int index) {
- return stringArray[index];
- }
-
- /**
- * Indexed Setter for the String[] property.
- */
- public void setStringArray(final int index, final String value) {
- stringArray[index] = value;
- }
-
- /**
- * Getter for the java.util.List property.
- */
- public List getStringList() {
- return stringList;
- }
-
- /**
- * Setter for the java.util.List property.
- */
- public void setStringList(final List stringList) {
- this.stringList = stringList;
- }
-
- /**
- * Indexed Getter for the java.util.List property.
- */
- public String getStringList(final int index) {
- return stringList.get(index);
- }
-
- /**
- * Indexed Setter for the java.util.List property.
- */
- public void setStringList(final int index, final String value) {
- stringList.add(index, value);
- }
-
- /**
- * Getter for the java.util.ArrayList property.
- */
- public ArrayList getArrayList() {
- return arrayList;
- }
-
- /**
- * Setter for the java.util.ArrayList property.
- */
- public void setArrayList(final ArrayList arrayList) {
- this.arrayList = arrayList;
- }
-
- /**
- * Indexed Getter for the java.util.ArrayList property.
- */
- public Object getArrayList(final int index) {
- return arrayList.get(index);
- }
-
- /**
- * Indexed Setter for the java.util.ArrayList property.
- */
- public void setArrayList(final int index, final Object value) {
- arrayList.add(index, value);
- }
-
-}
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/LazyDynaBeanTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/LazyDynaBeanTestCase.java
deleted file mode 100644
index 1e4a33870..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/LazyDynaBeanTestCase.java
+++ /dev/null
@@ -1,501 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.TreeMap;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
Test Case for the {@code LazyDynaBean} implementation class.
- *
- */
-public class LazyDynaBeanTestCase extends TestCase {
-
- protected LazyDynaBean bean = null;
- protected LazyDynaClass dynaClass = null;
- protected String testProperty = "myProperty";
- protected String testPropertyA = "myProperty-A";
- protected String testPropertyB = "myProperty-B";
- protected String testString1 = "myStringValue-1";
- protected String testString2 = "myStringValue-2";
- protected Integer testInteger1 = new Integer(30);
- protected Integer testInteger2 = new Integer(40);
- protected String testKey = "myKey";
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public LazyDynaBeanTestCase(final String name) {
- super(name);
- }
-
-
-
- /**
- * Run thus Test
- */
- public static void main(final String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
- return new TestSuite(LazyDynaBeanTestCase.class);
- }
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
- bean = new LazyDynaBean();
- dynaClass = (LazyDynaClass)bean.getDynaClass();
- dynaClass.setReturnNull(true);
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- bean = null;
- }
-
-
-
- /**
- * Test Getting/Setting a Simple Property
- */
- public void testSimpleProperty() {
-
- // Check the property & value doesn't exist
- assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Value is null", bean.get(testProperty));
-
- // Set a new property - should add new property and set value
- bean.set(testProperty, testInteger1);
- assertEquals("Check First Value is correct", testInteger1, bean.get(testProperty));
- assertEquals("Check Property type is correct", Integer.class, dynaClass.getDynaProperty(testProperty).getType());
-
- // Set the property again - should set the new value
- bean.set(testProperty, testInteger2);
- assertEquals("Check Second Value is correct", testInteger2, bean.get(testProperty));
-
- // Set the property again - with a different type, should fail
- try {
- bean.set(testProperty, testString1);
- fail("expected ConversionException trying to set an Integer property to a String");
- } catch (final ConversionException expected) {
- // expected result
- }
-
- }
-
- /**
- * Test Getting/Setting a 'null' Property
- */
- public void testNullProperty() {
-
- // Check the property & value doesn't exist
- assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Value is null", bean.get(testProperty));
-
- // Set a new property to null
- bean.set(testProperty, null);
- assertNull("Check Value is still null", bean.get(testProperty));
-
- }
-
- /**
- * Test Setting a Simple Property when MutableDynaClass is set to restricted
- */
- public void testSimplePropertyRestricted() {
-
- // Set the MutableDyanClass to 'restricted' (i.e. no new properties cab be added
- dynaClass.setRestricted(true);
- assertTrue("Check MutableDynaClass is restricted", dynaClass.isRestricted());
-
- // Check the property & value doesn't exist
- assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Value is null", bean.get(testProperty));
-
- // Set the property - should fail because property doesn't exist and MutableDynaClass is restricted
- try {
- bean.set(testProperty, testString1);
- fail("expected IllegalArgumentException trying to add new property to restricted DynaClass");
- } catch (final IllegalArgumentException expected) {
- // expected result
- }
-
- }
-
- /**
- * Test Getting/Setting a 'Mapped' Property - default HashMap property
- */
- public void testMappedPropertyDefault() {
-
- // Check the property & value doesn't exist
- assertNull("Check Mapped Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Map is null", bean.get(testProperty));
- assertNull("Check Mapped Value is null", bean.get(testProperty, testKey));
-
- // Set a new mapped property - should add new HashMap property and set the mapped value
- bean.set(testProperty, testKey, testInteger1);
- assertEquals("Check Mapped Property exists", HashMap.class, bean.get(testProperty).getClass());
- assertEquals("Check First Mapped Value is correct(a)", testInteger1, bean.get(testProperty, testKey));
- assertEquals("Check First Mapped Value is correct(b)", testInteger1, ((HashMap, ?>)bean.get(testProperty)).get(testKey));
-
- // Set the property again - should set the new value
- bean.set(testProperty, testKey, testInteger2);
- assertEquals("Check Second Mapped Value is correct(a)", testInteger2, bean.get(testProperty, testKey));
- assertEquals("Check Second Mapped Value is correct(b)", testInteger2, ((HashMap, ?>)bean.get(testProperty)).get(testKey));
- }
-
- /**
- * Test Getting/Setting a 'Mapped' Property - use TreeMap property
- */
- public void testMappedPropertyTreeMap() {
-
- // Check the property & value doesn't exist
- assertNull("Check Mapped Property doesn't exist", dynaClass.getDynaProperty(testProperty));
-
- // Add a 'TreeMap' property to the DynaClass
- dynaClass.add(testProperty, TreeMap.class);
- assertTrue("Check Property is mapped", dynaClass.getDynaProperty(testProperty).isMapped());
- assertEquals("Check Property is correct type", TreeMap.class, dynaClass.getDynaProperty(testProperty).getType());
- assertEquals("Check Mapped Property exists", TreeMap.class, bean.get(testProperty).getClass());
-// assertNull("Check mapped property is null", bean.get(testProperty));
-
- // Set a new mapped property - should instantiate a new TreeMap property and set the mapped value
- bean.set(testProperty, testKey, testInteger1);
- assertEquals("Check Mapped Property exists", TreeMap.class, bean.get(testProperty).getClass());
- assertEquals("Check First Mapped Value is correct(a)", testInteger1, bean.get(testProperty, testKey));
- assertEquals("Check First Mapped Value is correct(b)", testInteger1, ((TreeMap, ?>)bean.get(testProperty)).get(testKey));
-
- // Set the property again - should set the new value
- bean.set(testProperty, testKey, testInteger2);
- assertEquals("Check Second Mapped Value is correct(a)", testInteger2, bean.get(testProperty, testKey));
- assertEquals("Check Second Mapped Value is correct(b)", testInteger2, ((TreeMap, ?>)bean.get(testProperty)).get(testKey));
- }
-
- /**
- * Test Setting a 'Mapped' Property using PropertyUtils
- */
- public void testMappedPropertyUtils() {
-
- dynaClass.setReturnNull(false);
-
- // Check the property & value doesn't exist
- assertFalse("Check Mapped Property doesn't exist", dynaClass.isDynaProperty(testProperty));
- assertNull("Check Map is null", bean.get(testProperty));
- assertNull("Check Mapped Value is null", bean.get(testProperty, testKey));
-
- // Set the mapped property using PropertyUtils
- try {
- PropertyUtils.setProperty(bean, testProperty+"("+testKey+")", testString1);
- }
- catch (final NoSuchMethodException ex) {
- fail("testIndexedPropertyUtils threw "+ex);
- }
- catch (final InvocationTargetException ex) {
- fail("testIndexedPropertyUtils threw "+ex);
- }
- catch (final IllegalAccessException ex) {
- fail("testIndexedPropertyUtils threw "+ex);
- }
-
- // Check property value correctly set
- assertEquals("Check Mapped Bean Value is correct", testString1, bean.get(testProperty, testKey));
-
- }
-
- /**
- * Test Setting a Mapped Property when MutableDynaClass is set to restricted
- */
- public void testMappedPropertyRestricted() {
-
- // Set the MutableDyanClass to 'restricted' (i.e. no new properties cab be added
- dynaClass.setRestricted(true);
- assertTrue("Check MutableDynaClass is restricted", dynaClass.isRestricted());
-
- // Check the property & value doesn't exist
- assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Value is null", bean.get(testProperty));
-
- // Set the property - should fail because property doesn't exist and MutableDynaClass is restricted
- try {
- bean.set(testProperty, testKey, testInteger1);
- fail("expected IllegalArgumentException trying to add new property to restricted MutableDynaClass");
- } catch (final IllegalArgumentException expected) {
- // expected result
- }
-
- }
-
- /**
- * Test setting mapped property for type which is not Map
- */
- public void testMappedInvalidType() {
- dynaClass.add(testProperty, String.class);
- assertFalse("Check Property is not mapped", dynaClass.getDynaProperty(testProperty).isMapped());
- try {
- bean.set(testProperty, testKey, testInteger1);
- fail("set(property, key, value) should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected result
- }
- }
-
- /**
- * Test Getting/Setting an 'Indexed' Property - default ArrayList property
- */
- public void testIndexedPropertyDefault() {
-
- int index = 3;
-
- // Check the property & value doesn't exist
- assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Indexed Property is null", bean.get(testProperty));
- assertNull("Check Indexed value is null", bean.get(testProperty, index));
-
- // Set the property, should create new ArrayList and set appropriate indexed value
- bean.set(testProperty, index, testInteger1);
- assertNotNull("Check Indexed Property is not null", bean.get(testProperty));
- assertEquals("Check Indexed Property is correct type", ArrayList.class, bean.get(testProperty).getClass());
- assertEquals("Check First Indexed Value is correct", testInteger1, bean.get(testProperty, index));
- assertEquals("Check First Array length is correct", new Integer(index+1), new Integer(((ArrayList>)bean.get(testProperty)).size()));
-
- // Set a second indexed value, should automatically grow the ArrayList and set appropriate indexed value
- index = index + 2;
- bean.set(testProperty, index, testString1);
- assertEquals("Check Second Indexed Value is correct", testString1, bean.get(testProperty, index));
- assertEquals("Check Second Array length is correct", new Integer(index+1), new Integer(((ArrayList>)bean.get(testProperty)).size()));
- }
-
- /**
- * Test Getting/Setting a List 'Indexed' Property - use alternative List (LinkedList)
- */
- public void testIndexedLinkedList() {
-
- int index = 3;
-
- // Check the property & value doesn't exist
- assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Indexed Property is null", bean.get(testProperty));
-
- // Add a 'LinkedList' property to the DynaClass
- dynaClass.add(testProperty, LinkedList.class);
- assertTrue("Check Property is indexed", dynaClass.getDynaProperty(testProperty).isIndexed());
- assertEquals("Check Property is correct type", LinkedList.class, dynaClass.getDynaProperty(testProperty).getType());
- assertEquals("Check Property type is correct", LinkedList.class, bean.get(testProperty).getClass());
-
- // Set the property, should instantiate a new LinkedList and set appropriate indexed value
- bean.set(testProperty, index, testString1);
- assertEquals("Check Property type is correct", LinkedList.class, bean.get(testProperty).getClass());
- assertEquals("Check First Indexed Value is correct", testString1, bean.get(testProperty, index));
- assertEquals("Check First Array length is correct", new Integer(index+1), new Integer(((LinkedList>)bean.get(testProperty)).size()));
-
- // Set a second indexed value, should automatically grow the LinkedList and set appropriate indexed value
- index = index + 2;
- bean.set(testProperty, index, testInteger1);
- assertEquals("Check Second Indexed Value is correct", testInteger1, bean.get(testProperty, index));
- assertEquals("Check Second Array length is correct", new Integer(index+1), new Integer(((LinkedList>)bean.get(testProperty)).size()));
- }
-
- /**
- * Test Getting/Setting a primitive array 'Indexed' Property - use int[]
- */
- public void testIndexedPrimitiveArray() {
-
- int index = 3;
- final int[] primitiveArray = new int[0];
-
- // Check the property & value doesn't exist
- assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Indexed Property is null", bean.get(testProperty));
-
- // Add a DynaProperty of type int[]
- dynaClass.add(testProperty, primitiveArray.getClass());
- assertEquals("Check Indexed Property exists", primitiveArray.getClass(), dynaClass.getDynaProperty(testProperty).getType());
- assertEquals("Check Indexed Property is correct type", primitiveArray.getClass(), bean.get(testProperty).getClass());
-
- // Set an indexed value
- bean.set(testProperty, index, testInteger1);
- assertNotNull("Check Indexed Property is not null", bean.get(testProperty));
- assertEquals("Check Indexed Property is correct type", primitiveArray.getClass(), bean.get(testProperty).getClass());
- assertEquals("Check First Indexed Value is correct(a)", testInteger1, bean.get(testProperty, index));
- assertEquals("Check First Indexed Value is correct(b)", testInteger1, new Integer(((int[])bean.get(testProperty))[index]));
- assertEquals("Check Array length is correct", new Integer(index+1), new Integer(((int[])bean.get(testProperty)).length));
-
- // Set a second indexed value, should automatically grow the int[] and set appropriate indexed value
- index = index + 2;
- bean.set(testProperty, index, testInteger2);
- assertEquals("Check Second Indexed Value is correct(a)", testInteger2, bean.get(testProperty, index));
- assertEquals("Check Second Indexed Value is correct(b)", testInteger2, new Integer(((int[])bean.get(testProperty))[index]));
- assertEquals("Check Second Array length is correct", new Integer(index+1), new Integer(((int[])bean.get(testProperty)).length));
-
- }
-
- /**
- * Test Getting/Setting an Object array 'Indexed' Property - use String[]
- */
- public void testIndexedObjectArray() {
-
- int index = 3;
- final Object objectArray = new String[0];
-
- // Check the property & value doesn't exist
- assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Indexed Property is null", bean.get(testProperty));
-
- // Add a DynaProperty of type String[]
- dynaClass.add(testProperty, objectArray.getClass());
- assertEquals("Check Indexed Property exists", objectArray.getClass(), dynaClass.getDynaProperty(testProperty).getType());
- assertEquals("Check Indexed Property is correct type", objectArray.getClass(), bean.get(testProperty).getClass());
-
- // Set an indexed value
- bean.set(testProperty, index, testString1);
- assertNotNull("Check Indexed Property is not null", bean.get(testProperty));
- assertEquals("Check Indexed Property is correct type", objectArray.getClass(), bean.get(testProperty).getClass());
- assertEquals("Check First Indexed Value is correct(a)", testString1, bean.get(testProperty, index));
- assertEquals("Check First Indexed Value is correct(b)", testString1, ((String[])bean.get(testProperty))[index]);
- assertEquals("Check Array length is correct", new Integer(index+1), new Integer(((String[])bean.get(testProperty)).length));
-
- // Set a second indexed value, should automatically grow the String[] and set appropriate indexed value
- index = index + 2;
- bean.set(testProperty, index, testString2);
- assertEquals("Check Second Indexed Value is correct(a)", testString2, bean.get(testProperty, index));
- assertEquals("Check Second Indexed Value is correct(b)", testString2, ((String[])bean.get(testProperty))[index]);
- assertEquals("Check Second Array length is correct", new Integer(index+1), new Integer(((String[])bean.get(testProperty)).length));
- }
-
- /**
- * Test Getting/Setting an DynaBean[] array
- */
- public void testIndexedDynaBeanArray() {
-
- final int index = 3;
- final Object objectArray = new LazyDynaMap[0];
-
- // Check the property & value doesn't exist
- assertNull("Check Indexed Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Indexed Property is null", bean.get(testProperty));
-
- // Add a DynaProperty of type String[]
- dynaClass.add(testProperty, objectArray.getClass());
- assertEquals("Check Indexed Property exists", objectArray.getClass(), dynaClass.getDynaProperty(testProperty).getType());
- assertEquals("Check Indexed Property is correct type", objectArray.getClass(), bean.get(testProperty).getClass());
-
- // Retrieving from Array should initialize DynaBean
- for (int i = index; i >= 0; i--) {
- assertEquals("Check Array Components initialized", LazyDynaMap.class, bean.get(testProperty, index).getClass());
- }
-
- dynaClass.add(testPropertyB, objectArray.getClass());
- final LazyDynaMap newMap = new LazyDynaMap();
- newMap.set(testPropertyB, testString2);
- bean.set(testPropertyA, index, newMap);
- assertEquals("Check Indexed Value is correct(a)", testString2, ((DynaBean)bean.get(testPropertyA, index)).get(testPropertyB));
-
- }
-
- /**
- * Test Setting an 'Indexed' Property using PropertyUtils
- */
- public void testIndexedPropertyUtils() {
-
- final int index = 3;
- dynaClass.setReturnNull(false);
-
- // Check the property & value doesn't exist
- assertFalse("Check Indexed Property doesn't exist", dynaClass.isDynaProperty(testProperty));
- assertNull("Check Indexed Property is null", bean.get(testProperty));
- assertNull("Check Indexed value is null", bean.get(testProperty, index));
-
- // Use PropertyUtils to set the indexed value
- try {
- PropertyUtils.setProperty(bean, testProperty+"["+index+"]", testString1);
- }
- catch (final NoSuchMethodException ex) {
- fail("testIndexedPropertyUtils threw "+ex);
- }
- catch (final InvocationTargetException ex) {
- fail("testIndexedPropertyUtils threw "+ex);
- }
- catch (final IllegalAccessException ex) {
- fail("testIndexedPropertyUtils threw "+ex);
- }
-
- // Check property value correctly set
- assertEquals("Check Indexed Bean Value is correct", testString1, bean.get(testProperty, index));
-
- }
-
- /**
- * Test Setting an Indexed Property when MutableDynaClass is set to restricted
- */
- public void testIndexedPropertyRestricted() {
-
- final int index = 3;
-
- // Set the MutableDyanClass to 'restricted' (i.e. no new properties cab be added
- dynaClass.setRestricted(true);
- assertTrue("Check MutableDynaClass is restricted", dynaClass.isRestricted());
-
- // Check the property & value doesn't exist
- assertNull("Check Property doesn't exist", dynaClass.getDynaProperty(testProperty));
- assertNull("Check Value is null", bean.get(testProperty));
-
- // Set the property - should fail because property doesn't exist and MutableDynaClass is restricted
- try {
- bean.set(testProperty, index, testInteger1);
- fail("expected IllegalArgumentException trying to add new property to restricted MutableDynaClass");
- } catch (final IllegalArgumentException expected) {
- // expected result
- }
-
- }
-
- /**
- * Test setting indexed property for type which is not List or Array
- */
- public void testIndexedInvalidType() {
- final int index = 3;
- dynaClass.add(testProperty, String.class);
- assertFalse("Check Property is not indexed", dynaClass.getDynaProperty(testProperty).isIndexed());
- try {
- bean.set(testProperty, index, testString1);
- fail("set(property, index, value) should have thrown IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected result
- }
- }
-
-}
\ No newline at end of file
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/LazyDynaClassTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/LazyDynaClassTestCase.java
deleted file mode 100644
index 9eceb4724..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/LazyDynaClassTestCase.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
Test Case for the {@code LazyDynaClass} implementation class.
- *
- */
-public class LazyDynaClassTestCase extends TestCase {
-
- protected LazyDynaClass dynaClass = null;
- protected String testProperty = "myProperty";
-
-
-
- /**
- * Construct a new instance of this test case.
- *
- * @param name Name of the test case
- */
- public LazyDynaClassTestCase(final String name) {
- super(name);
- }
-
-
-
- /**
- * Run this Test
- */
- public static void main(final String[] args) {
- junit.textui.TestRunner.run(suite());
- }
-
- /**
- * Set up instance variables required by this test case.
- */
- @Override
- public void setUp() throws Exception {
- dynaClass = new LazyDynaClass();
- }
-
- /**
- * Return the tests included in this test suite.
- */
- public static Test suite() {
- return new TestSuite(LazyDynaClassTestCase.class);
- }
-
- /**
- * Tear down instance variables required by this test case.
- */
- @Override
- public void tearDown() {
- dynaClass = null;
- }
-
-
-
- /**
- * Test add(name) method
- */
- public void testAddProperty1() {
- dynaClass.add(testProperty);
- final DynaProperty dynaProperty = dynaClass.getDynaProperty(testProperty);
- assertEquals("name is correct", testProperty, dynaProperty.getName());
- assertEquals("type is correct", Object.class, dynaProperty.getType());
- }
-
- /**
- * Test add(name, type) method
- */
- public void testAddProperty2() {
- dynaClass.add(testProperty, String.class);
- final DynaProperty dynaProperty = dynaClass.getDynaProperty(testProperty);
- assertEquals("name is correct", testProperty, dynaProperty.getName());
- assertEquals("type is correct", String.class, dynaProperty.getType());
- }
-
- /**
- * Test add(name, type, readable, writable) method
- */
- public void testAddProperty3() {
- try {
- dynaClass.add(testProperty, String.class, true, true);
- fail("add(name, type, readable, writable) did not throw UnsupportedOperationException");
- } catch (final UnsupportedOperationException expected) {
- // expected result
- }
- }
-
- /**
- * Test add(name) method with 'null' name
- */
- public void testAddPropertyNullName1() {
- try {
- dynaClass.add((String)null);
- fail("null property name not prevented");
- } catch (final IllegalArgumentException expected) {
- // expected result
- }
- }
-
- /**
- * Test add(name, type) method with 'null' name
- */
- public void testAddPropertyNullName2() {
- try {
- dynaClass.add(null, String.class);
- fail("null property name not prevented");
- } catch (final IllegalArgumentException expected) {
- // expected result
- }
- }
-
- /**
- * Test add(name, type, readable, writable) method with 'null' name
- */
- public void testAddPropertyNullName3() {
- try {
- dynaClass.add(null, String.class, true, true);
- fail("add(name, type, readable, writable) did not throw UnsupportedOperationException");
- } catch (final UnsupportedOperationException expected) {
- // expected result
- }
- }
-
- /**
- * Test add(name) method when restricted is set to 'true'
- */
- public void testAddPropertyRestricted1() {
- dynaClass.setRestricted(true);
- assertTrue("MutableDynaClass is restricted", dynaClass.isRestricted());
- try {
- dynaClass.add(testProperty);
- fail("add(name) did not throw IllegalStateException");
- } catch (final IllegalStateException expected) {
- // expected result
- }
- }
-
- /**
- * Test add(name, type) method when restricted is set to 'true'
- */
- public void testAddPropertyRestricted2() {
- dynaClass.setRestricted(true);
- assertTrue("MutableDynaClass is restricted", dynaClass.isRestricted());
- try {
- dynaClass.add(testProperty, String.class);
- fail("add(name, type) did not throw IllegalStateException");
- } catch (final IllegalStateException expected) {
- // expected result
- }
- }
-
- /**
- * Test add(name, type, readable, writable) method when restricted is set to 'true'
- */
- public void testAddPropertyRestricted3() {
- dynaClass.setRestricted(true);
- assertTrue("MutableDynaClass is restricted", dynaClass.isRestricted());
- try {
- dynaClass.add(testProperty, String.class, true, true);
- fail("add(name, type, readable, writable) did not throw UnsupportedOperationException");
- } catch (final UnsupportedOperationException t) {
- // expected result
- }
- }
-
- /**
- * Test retrieving a property which doesn't exist (returnNull is 'false')
- */
- public void testGetPropertyDoesntExist1() {
- dynaClass.setReturnNull(false);
- assertFalse("returnNull is 'false'", dynaClass.isReturnNull());
- final DynaProperty dynaProperty = dynaClass.getDynaProperty(testProperty);
- assertEquals("name is correct", testProperty, dynaProperty.getName());
- assertEquals("type is correct", Object.class, dynaProperty.getType());
- assertFalse("property doesnt exist", dynaClass.isDynaProperty(testProperty));
- }
-
- /**
- * Test retrieving a property which doesn't exist (returnNull is 'true')
- */
- public void testGetPropertyDoesntExist2() {
- dynaClass.setReturnNull(true);
- assertTrue("returnNull is 'true'", dynaClass.isReturnNull());
- assertNull("property is null", dynaClass.getDynaProperty(testProperty));
- }
-
- /**
- * Test removing a property
- */
- public void testRemoveProperty() {
- dynaClass.setReturnNull(true);
- dynaClass.add(testProperty);
- assertTrue("Property exists", dynaClass.isDynaProperty(testProperty));
- assertNotNull("property is Not null", dynaClass.getDynaProperty(testProperty));
- dynaClass.remove(testProperty);
- assertFalse("Property doesn't exist", dynaClass.isDynaProperty(testProperty));
- assertNull("property is null", dynaClass.getDynaProperty(testProperty));
- }
-
- /**
- * Test removing a property, name is null
- */
- public void testRemovePropertyNullName() {
- try {
- dynaClass.remove(null);
- fail("remove(null) did not throw IllegalArgumentException");
- } catch (final IllegalArgumentException expected) {
- // expected result
- }
- }
-
- /**
- * Test removing a property, DynaClass is restricted
- */
- public void testRemovePropertyRestricted() {
- dynaClass.add(testProperty);
- assertTrue("Property exists", dynaClass.isDynaProperty(testProperty));
- dynaClass.setRestricted(true);
- assertTrue("MutableDynaClass is restricted", dynaClass.isRestricted());
- try {
- dynaClass.remove(testProperty);
- fail("remove property when MutableDynaClassis restricted did not throw IllegalStateException");
- } catch (final IllegalStateException expected) {
- // expected result
- }
- }
-
- /**
- * Test removing a property which doesn't exist
- */
- public void testRemovePropertyDoesntExist() {
- assertFalse("property doesn't exist", dynaClass.isDynaProperty(testProperty));
- dynaClass.remove(testProperty);
- assertFalse("property still doesn't exist", dynaClass.isDynaProperty(testProperty));
- }
-}
\ No newline at end of file
diff --git a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/LazyDynaListTestCase.java b/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/LazyDynaListTestCase.java
deleted file mode 100644
index a6c7b60d4..000000000
--- a/safety/Java/commons-beanutils/src/src/test/java/org/apache/commons/beanutils2/LazyDynaListTestCase.java
+++ /dev/null
@@ -1,611 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.beanutils2;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- *
Test Case for the {@code LazyDynaList}class.
- *
- */
-public class LazyDynaListTestCase extends TestCase {
-
- private static final String BASIC_PROP1 = "BasicDynaClass_Property1";
- private static final String BASIC_PROP2 = "BasicDynaClass_Property2";
-
- protected DynaProperty[] properties = new DynaProperty[] {
- new DynaProperty(BASIC_PROP1, String.class),
- new DynaProperty(BASIC_PROP2, HashMap.class)};
-
- protected DynaClass treeMapDynaClass = new LazyDynaMap(new TreeMap());
- protected DynaClass hashMapDynaClass = new LazyDynaMap(new HashMap