Use consistent class design
Update all classes so that inner classes are always last. Also ensure that utility classes are always final and have a private constructor and make exceptions final whenever possible. Issue: SPR-16968
This commit is contained in:
committed by
Juergen Hoeller
parent
0ad0f341bd
commit
eeebd51f57
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -31,13 +31,13 @@ import org.springframework.lang.Nullable;
|
||||
@SuppressWarnings("serial")
|
||||
public class BeanInstantiationException extends FatalBeanException {
|
||||
|
||||
private Class<?> beanClass;
|
||||
private final Class<?> beanClass;
|
||||
|
||||
@Nullable
|
||||
private Constructor<?> constructor;
|
||||
private final Constructor<?> constructor;
|
||||
|
||||
@Nullable
|
||||
private Method constructingMethod;
|
||||
private final Method constructingMethod;
|
||||
|
||||
|
||||
/**
|
||||
@@ -58,6 +58,8 @@ public class BeanInstantiationException extends FatalBeanException {
|
||||
public BeanInstantiationException(Class<?> beanClass, String msg, @Nullable Throwable cause) {
|
||||
super("Failed to instantiate [" + beanClass.getName() + "]: " + msg, cause);
|
||||
this.beanClass = beanClass;
|
||||
this.constructor = null;
|
||||
this.constructingMethod = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,6 +73,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
||||
super("Failed to instantiate [" + constructor.getDeclaringClass().getName() + "]: " + msg, cause);
|
||||
this.beanClass = constructor.getDeclaringClass();
|
||||
this.constructor = constructor;
|
||||
this.constructingMethod = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,6 +87,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
||||
public BeanInstantiationException(Method constructingMethod, String msg, @Nullable Throwable cause) {
|
||||
super("Failed to instantiate [" + constructingMethod.getReturnType().getName() + "]: " + msg, cause);
|
||||
this.beanClass = constructingMethod.getReturnType();
|
||||
this.constructor = null;
|
||||
this.constructingMethod = constructingMethod;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ import org.springframework.util.StringUtils;
|
||||
* @see #clearClassLoader(ClassLoader)
|
||||
* @see #forClass(Class)
|
||||
*/
|
||||
public class CachedIntrospectionResults {
|
||||
public final class CachedIntrospectionResults {
|
||||
|
||||
/**
|
||||
* System property that instructs Spring to use the {@link Introspector#IGNORE_ALL_BEANINFO}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -28,9 +28,9 @@ import org.springframework.lang.Nullable;
|
||||
@SuppressWarnings("serial")
|
||||
public class InvalidPropertyException extends FatalBeanException {
|
||||
|
||||
private Class<?> beanClass;
|
||||
private final Class<?> beanClass;
|
||||
|
||||
private String propertyName;
|
||||
private final String propertyName;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.lang.Nullable;
|
||||
public class NotWritablePropertyException extends InvalidPropertyException {
|
||||
|
||||
@Nullable
|
||||
private String[] possibleMatches;
|
||||
private final String[] possibleMatches;
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,6 +42,7 @@ public class NotWritablePropertyException extends InvalidPropertyException {
|
||||
super(beanClass, propertyName,
|
||||
"Bean property '" + propertyName + "' is not writable or has an invalid setter method: " +
|
||||
"Does the return type of the getter match the parameter type of the setter?");
|
||||
this.possibleMatches = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,6 +53,7 @@ public class NotWritablePropertyException extends InvalidPropertyException {
|
||||
*/
|
||||
public NotWritablePropertyException(Class<?> beanClass, String propertyName, String msg) {
|
||||
super(beanClass, propertyName, msg);
|
||||
this.possibleMatches = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,6 +65,7 @@ public class NotWritablePropertyException extends InvalidPropertyException {
|
||||
*/
|
||||
public NotWritablePropertyException(Class<?> beanClass, String propertyName, String msg, Throwable cause) {
|
||||
super(beanClass, propertyName, msg, cause);
|
||||
this.possibleMatches = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -31,7 +31,7 @@ import org.springframework.lang.Nullable;
|
||||
public abstract class PropertyAccessException extends BeansException {
|
||||
|
||||
@Nullable
|
||||
private transient PropertyChangeEvent propertyChangeEvent;
|
||||
private final PropertyChangeEvent propertyChangeEvent;
|
||||
|
||||
|
||||
/**
|
||||
@@ -52,6 +52,7 @@ public abstract class PropertyAccessException extends BeansException {
|
||||
*/
|
||||
public PropertyAccessException(String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.propertyChangeEvent = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.util.ObjectUtils;
|
||||
public class PropertyBatchUpdateException extends BeansException {
|
||||
|
||||
/** List of PropertyAccessException objects. */
|
||||
private PropertyAccessException[] propertyAccessExceptions;
|
||||
private final PropertyAccessException[] propertyAccessExceptions;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -30,7 +30,12 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class PropertyDescriptorUtils {
|
||||
final class PropertyDescriptorUtils {
|
||||
|
||||
|
||||
private PropertyDescriptorUtils() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See {@link java.beans.FeatureDescriptor}.
|
||||
|
||||
@@ -517,7 +517,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* Holder for a registered custom editor with property name.
|
||||
* Keeps the PropertyEditor itself plus the type it was registered for.
|
||||
*/
|
||||
private static class CustomEditorHolder {
|
||||
private static final class CustomEditorHolder {
|
||||
|
||||
private final PropertyEditor propertyEditor;
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ import org.springframework.lang.Nullable;
|
||||
public class BeanCreationException extends FatalBeanException {
|
||||
|
||||
@Nullable
|
||||
private String beanName;
|
||||
private final String beanName;
|
||||
|
||||
@Nullable
|
||||
private String resourceDescription;
|
||||
private final String resourceDescription;
|
||||
|
||||
@Nullable
|
||||
private List<Throwable> relatedCauses;
|
||||
@@ -50,6 +50,8 @@ public class BeanCreationException extends FatalBeanException {
|
||||
*/
|
||||
public BeanCreationException(String msg) {
|
||||
super(msg);
|
||||
this.beanName = null;
|
||||
this.resourceDescription = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,6 +61,8 @@ public class BeanCreationException extends FatalBeanException {
|
||||
*/
|
||||
public BeanCreationException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.beanName = null;
|
||||
this.resourceDescription = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,6 +73,7 @@ public class BeanCreationException extends FatalBeanException {
|
||||
public BeanCreationException(String beanName, String msg) {
|
||||
super("Error creating bean with name '" + beanName + "': " + msg);
|
||||
this.beanName = beanName;
|
||||
this.resourceDescription = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,6 +99,7 @@ public class BeanCreationException extends FatalBeanException {
|
||||
(resourceDescription != null ? " defined in " + resourceDescription : "") + ": " + msg);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = beanName;
|
||||
this.relatedCauses = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -31,10 +31,10 @@ import org.springframework.lang.Nullable;
|
||||
public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
|
||||
@Nullable
|
||||
private String resourceDescription;
|
||||
private final String resourceDescription;
|
||||
|
||||
@Nullable
|
||||
private String beanName;
|
||||
private final String beanName;
|
||||
|
||||
|
||||
/**
|
||||
@@ -43,6 +43,8 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
*/
|
||||
public BeanDefinitionStoreException(String msg) {
|
||||
super(msg);
|
||||
this.resourceDescription = null;
|
||||
this.beanName = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,6 +54,8 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
*/
|
||||
public BeanDefinitionStoreException(String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.resourceDescription = null;
|
||||
this.beanName = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +66,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg) {
|
||||
super(msg);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,6 +78,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||
public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg, @Nullable Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.resourceDescription = resourceDescription;
|
||||
this.beanName = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,13 +29,13 @@ import org.springframework.util.ClassUtils;
|
||||
public class BeanNotOfRequiredTypeException extends BeansException {
|
||||
|
||||
/** The name of the instance that was of the wrong type. */
|
||||
private String beanName;
|
||||
private final String beanName;
|
||||
|
||||
/** The required type. */
|
||||
private Class<?> requiredType;
|
||||
private final Class<?> requiredType;
|
||||
|
||||
/** The offending type. */
|
||||
private Class<?> actualType;
|
||||
private final Class<?> actualType;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -30,13 +30,13 @@ import org.springframework.lang.Nullable;
|
||||
public class CannotLoadBeanClassException extends FatalBeanException {
|
||||
|
||||
@Nullable
|
||||
private String resourceDescription;
|
||||
private final String resourceDescription;
|
||||
|
||||
@Nullable
|
||||
private String beanName;
|
||||
private final String beanName;
|
||||
|
||||
@Nullable
|
||||
private String beanClassName;
|
||||
private final String beanClassName;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -36,10 +36,10 @@ import org.springframework.lang.Nullable;
|
||||
public class NoSuchBeanDefinitionException extends BeansException {
|
||||
|
||||
@Nullable
|
||||
private String beanName;
|
||||
private final String beanName;
|
||||
|
||||
@Nullable
|
||||
private ResolvableType resolvableType;
|
||||
private final ResolvableType resolvableType;
|
||||
|
||||
|
||||
/**
|
||||
@@ -49,6 +49,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
|
||||
public NoSuchBeanDefinitionException(String name) {
|
||||
super("No bean named '" + name + "' available");
|
||||
this.beanName = name;
|
||||
this.resolvableType = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,6 +60,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
|
||||
public NoSuchBeanDefinitionException(String name, String message) {
|
||||
super("No bean named '" + name + "' available: " + message);
|
||||
this.beanName = name;
|
||||
this.resolvableType = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,6 +87,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
|
||||
*/
|
||||
public NoSuchBeanDefinitionException(ResolvableType type) {
|
||||
super("No qualifying bean of type '" + type + "' available");
|
||||
this.beanName = null;
|
||||
this.resolvableType = type;
|
||||
}
|
||||
|
||||
@@ -96,6 +99,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
|
||||
*/
|
||||
public NoSuchBeanDefinitionException(ResolvableType type, String message) {
|
||||
super("No qualifying bean of type '" + type + "' available: " + message);
|
||||
this.beanName = null;
|
||||
this.resolvableType = type;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -33,10 +33,10 @@ import org.springframework.util.StringUtils;
|
||||
@SuppressWarnings("serial")
|
||||
public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionException {
|
||||
|
||||
private int numberOfBeansFound;
|
||||
private final int numberOfBeansFound;
|
||||
|
||||
@Nullable
|
||||
private Collection<String> beanNamesFound;
|
||||
private final Collection<String> beanNamesFound;
|
||||
|
||||
|
||||
/**
|
||||
@@ -48,6 +48,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
|
||||
public NoUniqueBeanDefinitionException(Class<?> type, int numberOfBeansFound, String message) {
|
||||
super(type, message);
|
||||
this.numberOfBeansFound = numberOfBeansFound;
|
||||
this.beanNamesFound = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,8 +57,9 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
|
||||
* @param beanNamesFound the names of all matching beans (as a Collection)
|
||||
*/
|
||||
public NoUniqueBeanDefinitionException(Class<?> type, Collection<String> beanNamesFound) {
|
||||
this(type, beanNamesFound.size(), "expected single matching bean but found " + beanNamesFound.size() + ": " +
|
||||
super(type, "expected single matching bean but found " + beanNamesFound.size() + ": " +
|
||||
StringUtils.collectionToCommaDelimitedString(beanNamesFound));
|
||||
this.numberOfBeansFound = beanNamesFound.size();
|
||||
this.beanNamesFound = beanNamesFound;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -33,7 +33,7 @@ import org.springframework.util.StringUtils;
|
||||
public class UnsatisfiedDependencyException extends BeanCreationException {
|
||||
|
||||
@Nullable
|
||||
private InjectionPoint injectionPoint;
|
||||
private final InjectionPoint injectionPoint;
|
||||
|
||||
|
||||
/**
|
||||
@@ -49,6 +49,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException {
|
||||
super(resourceDescription, beanName,
|
||||
"Unsatisfied dependency expressed through bean property '" + propertyName + "'" +
|
||||
(StringUtils.hasLength(msg) ? ": " + msg : ""));
|
||||
this.injectionPoint = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -250,7 +250,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
|
||||
}
|
||||
|
||||
|
||||
private class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver {
|
||||
private final class PropertyPlaceholderConfigurerResolver implements PlaceholderResolver {
|
||||
|
||||
private final Properties props;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -34,7 +34,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
*/
|
||||
public class BeanDefinitionBuilder {
|
||||
public final class BeanDefinitionBuilder {
|
||||
|
||||
/**
|
||||
* Create a new {@code BeanDefinitionBuilder} used to construct a {@link GenericBeanDefinition}.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -35,7 +35,7 @@ import org.springframework.util.StringUtils;
|
||||
* @see PropertiesBeanDefinitionReader
|
||||
* @see org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader
|
||||
*/
|
||||
public class BeanDefinitionReaderUtils {
|
||||
public final class BeanDefinitionReaderUtils {
|
||||
|
||||
/**
|
||||
* Separator for generated bean names. If a class name or parent name is not
|
||||
@@ -44,6 +44,10 @@ public class BeanDefinitionReaderUtils {
|
||||
public static final String GENERATED_BEAN_NAME_SEPARATOR = BeanFactoryUtils.GENERATED_BEAN_NAME_SEPARATOR;
|
||||
|
||||
|
||||
private BeanDefinitionReaderUtils() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new GenericBeanDefinition for the given parent name and class name,
|
||||
* eagerly loading the bean class if a ClassLoader has been specified.
|
||||
|
||||
Reference in New Issue
Block a user