Backported refinements and polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -203,7 +203,7 @@ public abstract class CollectionFactory {
|
||||
try {
|
||||
return (Collection<E>) collectionType.newInstance();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalArgumentException(
|
||||
"Could not instantiate Collection type: " + collectionType.getName(), ex);
|
||||
}
|
||||
@@ -318,7 +318,7 @@ public abstract class CollectionFactory {
|
||||
try {
|
||||
return (Map<K, V>) mapType.newInstance();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalArgumentException("Could not instantiate Map type: " + mapType.getName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,6 @@ import java.io.InputStream;
|
||||
import java.io.NotSerializableException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectStreamClass;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -101,7 +100,7 @@ public class ConfigurableObjectInputStream extends ObjectInputStream {
|
||||
}
|
||||
}
|
||||
try {
|
||||
return Proxy.getProxyClass(this.classLoader, resolvedInterfaces);
|
||||
return ClassUtils.createCompositeInterface(resolvedInterfaces, this.classLoader);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
throw new ClassNotFoundException(null, ex);
|
||||
@@ -117,7 +116,7 @@ public class ConfigurableObjectInputStream extends ObjectInputStream {
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
resolvedInterfaces[i] = resolveFallbackIfPossible(interfaces[i], ex);
|
||||
}
|
||||
return Proxy.getProxyClass(getFallbackClassLoader(), resolvedInterfaces);
|
||||
return ClassUtils.createCompositeInterface(resolvedInterfaces, getFallbackClassLoader());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,8 +138,9 @@ public class ConfigurableObjectInputStream extends ObjectInputStream {
|
||||
|
||||
/**
|
||||
* Return the fallback ClassLoader to use when no ClassLoader was specified
|
||||
* and ObjectInputStream's own default ClassLoader failed.
|
||||
* <p>The default implementation simply returns {@code null}.
|
||||
* and ObjectInputStream's own default class loader failed.
|
||||
* <p>The default implementation simply returns {@code null}, indicating
|
||||
* that no specific fallback is available.
|
||||
*/
|
||||
protected ClassLoader getFallbackClassLoader() throws IOException {
|
||||
return null;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class AnnotationAttributes extends LinkedHashMap<String, Object> {
|
||||
/**
|
||||
* Create a new, empty {@link AnnotationAttributes} instance for the
|
||||
* specified {@code annotationType}.
|
||||
* @param annotationType the type of annotation represented by this
|
||||
* @param annotationType the annotation type name represented by this
|
||||
* {@code AnnotationAttributes} instance; never {@code null}
|
||||
* @param classLoader the ClassLoader to try to load the annotation type on,
|
||||
* or {@code null} to just store the annotation type name
|
||||
|
||||
@@ -1268,8 +1268,8 @@ public abstract class AnnotationUtils {
|
||||
(annotatedElement != null ? annotatedElement.toString() : "unknown element");
|
||||
throw new AnnotationConfigurationException(String.format(
|
||||
"In AnnotationAttributes for annotation [%s] declared on %s, " +
|
||||
"attribute '%s' and its alias '%s' are declared with values of [%s] and [%s], " +
|
||||
"but only one is permitted.", annotationType.getName(), elementAsString,
|
||||
"attribute '%s' and its alias '%s' are declared with values of [%s] and [%s], " +
|
||||
"but only one is permitted.", annotationType.getName(), elementAsString,
|
||||
attributeName, aliasedAttributeName, ObjectUtils.nullSafeToString(value),
|
||||
ObjectUtils.nullSafeToString(aliasedValue)));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -72,7 +72,7 @@ public abstract class AbstractFileResolvingResource extends AbstractResource {
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation returns a File reference for the underlying class path
|
||||
* This implementation returns a File reference for the given URI-identified
|
||||
* resource, provided that it refers to a file in the file system.
|
||||
* @see org.springframework.util.ResourceUtils#getFile(java.net.URI, String)
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -182,8 +182,8 @@ public class PathResource extends AbstractResource implements WritableResource {
|
||||
return this.path.toFile();
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
// only Paths on the default file system can be converted to a File
|
||||
// do exception translation for cases where conversion is not possible
|
||||
// Only paths on the default file system can be converted to a File:
|
||||
// Do exception translation for cases where conversion is not possible.
|
||||
throw new FileNotFoundException(this.path + " cannot be resolved to " + "absolute file path");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,7 +47,7 @@ import java.net.URL;
|
||||
public interface Resource extends InputStreamSource {
|
||||
|
||||
/**
|
||||
* Return whether this resource actually exists in physical form.
|
||||
* Determine whether this resource actually exists in physical form.
|
||||
* <p>This method performs a definitive existence check, whereas the
|
||||
* existence of a {@code Resource} handle only guarantees a
|
||||
* valid descriptor handle.
|
||||
@@ -55,8 +55,8 @@ public interface Resource extends InputStreamSource {
|
||||
boolean exists();
|
||||
|
||||
/**
|
||||
* Return whether the contents of this resource can be read,
|
||||
* e.g. via {@link #getInputStream()} or {@link #getFile()}.
|
||||
* Indicate whether the contents of this resource can be read via
|
||||
* {@link #getInputStream()}.
|
||||
* <p>Will be {@code true} for typical resource descriptors;
|
||||
* note that actual content reading may still fail when attempted.
|
||||
* However, a value of {@code false} is a definitive indication
|
||||
@@ -66,8 +66,8 @@ public interface Resource extends InputStreamSource {
|
||||
boolean isReadable();
|
||||
|
||||
/**
|
||||
* Return whether this resource represents a handle with an open
|
||||
* stream. If true, the InputStream cannot be read multiple times,
|
||||
* Indicate whether this resource represents a handle with an open stream.
|
||||
* If {@code true}, the InputStream cannot be read multiple times,
|
||||
* and must be read and closed to avoid resource leaks.
|
||||
* <p>Will be {@code false} for typical resource descriptors.
|
||||
*/
|
||||
@@ -84,6 +84,7 @@ public interface Resource extends InputStreamSource {
|
||||
* Return a URI handle for this resource.
|
||||
* @throws IOException if the resource cannot be resolved as URI,
|
||||
* i.e. if the resource is not available as descriptor
|
||||
* @since 2.5
|
||||
*/
|
||||
URI getURI() throws IOException;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -61,6 +61,7 @@ public class UrlResource extends AbstractFileResolvingResource {
|
||||
* Create a new {@code UrlResource} based on the given URI object.
|
||||
* @param uri a URI
|
||||
* @throws MalformedURLException if the given URL path is not valid
|
||||
* @since 2.5
|
||||
*/
|
||||
public UrlResource(URI uri) throws MalformedURLException {
|
||||
Assert.notNull(uri, "URI must not be null");
|
||||
|
||||
@@ -139,7 +139,7 @@ public abstract class SpringFactoriesLoader {
|
||||
return (T) constructor.newInstance();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalArgumentException("Cannot instantiate factory class: " + factoryClass.getName(), ex);
|
||||
throw new IllegalArgumentException("Unable to instantiate factory class: " + factoryClass.getName(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,7 +82,7 @@ public class ToStringCreator {
|
||||
* @return this, to support call-chaining
|
||||
*/
|
||||
public ToStringCreator append(String fieldName, byte value) {
|
||||
return append(fieldName, new Byte(value));
|
||||
return append(fieldName, Byte.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ public class ToStringCreator {
|
||||
* @return this, to support call-chaining
|
||||
*/
|
||||
public ToStringCreator append(String fieldName, short value) {
|
||||
return append(fieldName, new Short(value));
|
||||
return append(fieldName, Short.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,7 @@ public class ToStringCreator {
|
||||
* @return this, to support call-chaining
|
||||
*/
|
||||
public ToStringCreator append(String fieldName, int value) {
|
||||
return append(fieldName, new Integer(value));
|
||||
return append(fieldName, Integer.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ public class ToStringCreator {
|
||||
* @return this, to support call-chaining
|
||||
*/
|
||||
public ToStringCreator append(String fieldName, long value) {
|
||||
return append(fieldName, new Long(value));
|
||||
return append(fieldName, Long.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +122,7 @@ public class ToStringCreator {
|
||||
* @return this, to support call-chaining
|
||||
*/
|
||||
public ToStringCreator append(String fieldName, float value) {
|
||||
return append(fieldName, new Float(value));
|
||||
return append(fieldName, Float.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ public class ToStringCreator {
|
||||
* @return this, to support call-chaining
|
||||
*/
|
||||
public ToStringCreator append(String fieldName, double value) {
|
||||
return append(fieldName, new Double(value));
|
||||
return append(fieldName, Double.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -263,13 +263,16 @@ public class AutoPopulatingList<E> implements List<E>, Serializable {
|
||||
public ElementInstantiationException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public ElementInstantiationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reflective implementation of the ElementFactory interface,
|
||||
* using {@code Class.newInstance()} on a given element class.
|
||||
* @see Class#newInstance()
|
||||
*/
|
||||
private static class ReflectiveElementFactory<E> implements ElementFactory<E>, Serializable {
|
||||
|
||||
@@ -288,12 +291,12 @@ public class AutoPopulatingList<E> implements List<E>, Serializable {
|
||||
return this.elementClass.newInstance();
|
||||
}
|
||||
catch (InstantiationException ex) {
|
||||
throw new ElementInstantiationException("Unable to instantiate element class [" +
|
||||
this.elementClass.getName() + "]. Root cause is " + ex);
|
||||
throw new ElementInstantiationException(
|
||||
"Unable to instantiate element class: " + this.elementClass.getName(), ex);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
throw new ElementInstantiationException("Cannot access element class [" +
|
||||
this.elementClass.getName() + "]. Root cause is " + ex);
|
||||
throw new ElementInstantiationException(
|
||||
"Could not access element constructor: " + this.elementClass.getName(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1158,7 +1158,6 @@ public abstract class ClassUtils {
|
||||
*/
|
||||
public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) {
|
||||
Assert.notEmpty(interfaces, "Interfaces must not be empty");
|
||||
Assert.notNull(classLoader, "ClassLoader must not be null");
|
||||
return Proxy.getProxyClass(classLoader, interfaces);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -235,6 +235,7 @@ public abstract class ResourceUtils {
|
||||
* @return a corresponding File object
|
||||
* @throws FileNotFoundException if the URL cannot be resolved to
|
||||
* a file in the file system
|
||||
* @since 2.5
|
||||
*/
|
||||
public static File getFile(URI resourceUri) throws FileNotFoundException {
|
||||
return getFile(resourceUri, "URI");
|
||||
@@ -249,6 +250,7 @@ public abstract class ResourceUtils {
|
||||
* @return a corresponding File object
|
||||
* @throws FileNotFoundException if the URL cannot be resolved to
|
||||
* a file in the file system
|
||||
* @since 2.5
|
||||
*/
|
||||
public static File getFile(URI resourceUri, String description) throws FileNotFoundException {
|
||||
Assert.notNull(resourceUri, "Resource URI must not be null");
|
||||
|
||||
Reference in New Issue
Block a user