[COLLECTIONS-692] Replace use of deprecated Class#newInstance() #49.
This commit is contained in:
parent
4bcd8c12ed
commit
b1c45ac691
|
@ -27,6 +27,9 @@
|
|||
<action issue="COLLECTIONS-689" dev="ggregory" type="update" due-to="Richard Walker">
|
||||
Link to Javadoc API broken.
|
||||
</action>
|
||||
<action issue="COLLECTIONS-692" dev="ggregory" type="update" due-to="Gary Gregory, ">
|
||||
Replace use of deprecated Class#newInstance() #49.
|
||||
</action>
|
||||
</release>
|
||||
<release version="4.2" date="2018-07-11" description="Update from Java 6 to Java 7, bug fixes, and small changes.">
|
||||
<action issue="COLLECTIONS-681" dev="kinow" type="add" due-to="Stephan Fuhrmann">
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.commons.collections4.list;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -327,21 +329,20 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
|
|||
* @return a new {@link Set} populated with all elements of the provided
|
||||
* {@link List}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Set<E> createSetBasedOnList(final Set<E> set, final List<E> list) {
|
||||
Set<E> subSet;
|
||||
if (set.getClass().equals(HashSet.class)) {
|
||||
subSet = new HashSet<>(list.size());
|
||||
} else {
|
||||
try {
|
||||
subSet = set.getClass().newInstance();
|
||||
} catch (final InstantiationException ie) {
|
||||
subSet = new HashSet<>();
|
||||
} catch (final IllegalAccessException iae) {
|
||||
subSet = set.getClass().getDeclaredConstructor(set.getClass()).newInstance(set);
|
||||
} catch (final InstantiationException
|
||||
| IllegalAccessException
|
||||
| InvocationTargetException
|
||||
| NoSuchMethodException ie) {
|
||||
subSet = new HashSet<>();
|
||||
}
|
||||
}
|
||||
subSet.addAll(list);
|
||||
return subSet;
|
||||
}
|
||||
|
||||
|
|
|
@ -560,7 +560,7 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
|
|||
@Override
|
||||
public T create() {
|
||||
try {
|
||||
return clazz.newInstance();
|
||||
return clazz.getDeclaredConstructor().newInstance();
|
||||
} catch (final Exception ex) {
|
||||
throw new FunctorException("Cannot instantiate class: " + clazz, ex);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue