Class identity comparisons wherever possible
Issue: SPR-12926
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -517,12 +517,12 @@ public abstract class BeanUtils {
|
||||
* @return whether the given type represents a "simple" value type
|
||||
*/
|
||||
public static boolean isSimpleValueType(Class<?> clazz) {
|
||||
return ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.isEnum() ||
|
||||
return (ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.isEnum() ||
|
||||
CharSequence.class.isAssignableFrom(clazz) ||
|
||||
Number.class.isAssignableFrom(clazz) ||
|
||||
Date.class.isAssignableFrom(clazz) ||
|
||||
clazz.equals(URI.class) || clazz.equals(URL.class) ||
|
||||
clazz.equals(Locale.class) || clazz.equals(Class.class);
|
||||
URI.class == clazz || URL.class == clazz ||
|
||||
Locale.class == clazz || Class.class == clazz);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ public class CachedIntrospectionResults {
|
||||
// This call is slow so we do it once.
|
||||
PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors();
|
||||
for (PropertyDescriptor pd : pds) {
|
||||
if (Class.class.equals(beanClass) &&
|
||||
if (Class.class == beanClass &&
|
||||
("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) {
|
||||
// Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those
|
||||
continue;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -153,7 +153,7 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||
int nParams = parameterTypes.length;
|
||||
return (methodName.length() > 3 && methodName.startsWith("set") && Modifier.isPublic(method.getModifiers()) &&
|
||||
(!void.class.isAssignableFrom(method.getReturnType()) || Modifier.isStatic(method.getModifiers())) &&
|
||||
(nParams == 1 || (nParams == 2 && parameterTypes[0].equals(int.class))));
|
||||
(nParams == 1 || (nParams == 2 && int.class == parameterTypes[0])));
|
||||
}
|
||||
|
||||
private void handleCandidateWriteMethod(Method method) throws IntrospectionException {
|
||||
|
||||
@@ -201,7 +201,7 @@ class TypeConverterDelegate {
|
||||
// Try to apply some standard type conversion rules if appropriate.
|
||||
|
||||
if (convertedValue != null) {
|
||||
if (Object.class.equals(requiredType)) {
|
||||
if (Object.class == requiredType) {
|
||||
return (T) convertedValue;
|
||||
}
|
||||
else if (requiredType.isArray()) {
|
||||
@@ -227,7 +227,7 @@ class TypeConverterDelegate {
|
||||
convertedValue = Array.get(convertedValue, 0);
|
||||
standardConversion = true;
|
||||
}
|
||||
if (String.class.equals(requiredType) && ClassUtils.isPrimitiveOrWrapper(convertedValue.getClass())) {
|
||||
if (String.class == requiredType && ClassUtils.isPrimitiveOrWrapper(convertedValue.getClass())) {
|
||||
// We can stringify any primitive value...
|
||||
return (T) convertedValue.toString();
|
||||
}
|
||||
@@ -305,7 +305,7 @@ class TypeConverterDelegate {
|
||||
}
|
||||
|
||||
if (conversionAttemptEx != null) {
|
||||
if (editor == null && !standardConversion && requiredType != null && !Object.class.equals(requiredType)) {
|
||||
if (editor == null && !standardConversion && requiredType != null && Object.class != requiredType) {
|
||||
throw conversionAttemptEx;
|
||||
}
|
||||
logger.debug("Original ConversionService attempt failed - ignored since " +
|
||||
@@ -318,7 +318,7 @@ class TypeConverterDelegate {
|
||||
private Object attemptToConvertStringToEnum(Class<?> requiredType, String trimmedValue, Object currentConvertedValue) {
|
||||
Object convertedValue = currentConvertedValue;
|
||||
|
||||
if (Enum.class.equals(requiredType)) {
|
||||
if (Enum.class == requiredType) {
|
||||
// target type is declared as raw enum, treat the trimmed value as <enum.fqn>.FIELD_NAME
|
||||
int index = trimmedValue.lastIndexOf(".");
|
||||
if (index > - 1) {
|
||||
@@ -370,7 +370,7 @@ class TypeConverterDelegate {
|
||||
if (requiredType != null) {
|
||||
// No custom editor -> check BeanWrapperImpl's default editors.
|
||||
editor = this.propertyEditorRegistry.getDefaultEditor(requiredType);
|
||||
if (editor == null && !String.class.equals(requiredType)) {
|
||||
if (editor == null && String.class != requiredType) {
|
||||
// No BeanWrapper default editor -> check standard JavaBean editor.
|
||||
editor = BeanUtils.findEditorByConvention(requiredType);
|
||||
}
|
||||
@@ -436,7 +436,7 @@ class TypeConverterDelegate {
|
||||
String newTextValue = (String) convertedValue;
|
||||
return doConvertTextValue(oldValue, newTextValue, editor);
|
||||
}
|
||||
else if (String.class.equals(requiredType)) {
|
||||
else if (String.class == requiredType) {
|
||||
returnValue = convertedValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
||||
MethodParameter methodParam = descriptor.getMethodParameter();
|
||||
if (methodParam != null) {
|
||||
Method method = methodParam.getMethod();
|
||||
if (method == null || void.class.equals(method.getReturnType())) {
|
||||
if (method == null || void.class == method.getReturnType()) {
|
||||
match = checkQualifiers(bdHolder, methodParam.getMethodAnnotations());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -314,7 +314,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
|
||||
Class<?>[] paramTypes = exceptionConstructor.getParameterTypes();
|
||||
Object[] args = new Object[paramTypes.length];
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
if (paramTypes[i].equals(String.class)) {
|
||||
if (String.class == paramTypes[i]) {
|
||||
args[i] = cause.getMessage();
|
||||
}
|
||||
else if (paramTypes[i].isInstance(cause)) {
|
||||
@@ -409,7 +409,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
|
||||
Class<?> serviceLocatorReturnType = interfaceMethod.getReturnType();
|
||||
|
||||
// Check whether the method is a valid service locator.
|
||||
if (paramTypes.length > 1 || void.class.equals(serviceLocatorReturnType)) {
|
||||
if (paramTypes.length > 1 || void.class == serviceLocatorReturnType) {
|
||||
throw new UnsupportedOperationException(
|
||||
"May only call methods with signature '<type> xxx()' or '<type> xxx(<idtype> id)' " +
|
||||
"on factory interface, but tried to call: " + interfaceMethod);
|
||||
|
||||
@@ -603,7 +603,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
|
||||
SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
|
||||
Class<?> predicted = ibp.predictBeanType(targetType, beanName);
|
||||
if (predicted != null && (typesToMatch.length != 1 || !FactoryBean.class.equals(typesToMatch[0]) ||
|
||||
if (predicted != null && (typesToMatch.length != 1 || FactoryBean.class != typesToMatch[0] ||
|
||||
FactoryBean.class.isAssignableFrom(predicted))) {
|
||||
return predicted;
|
||||
}
|
||||
@@ -779,7 +779,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
}
|
||||
}
|
||||
});
|
||||
if (objectType.value != null && !Object.class.equals(objectType.value)) {
|
||||
if (objectType.value != null && Object.class != objectType.value) {
|
||||
return objectType.value;
|
||||
}
|
||||
}
|
||||
@@ -1284,7 +1284,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
PropertyDescriptor pd = bw.getPropertyDescriptor(propertyName);
|
||||
// Don't try autowiring by type for type Object: never makes sense,
|
||||
// even if it technically is a unsatisfied, non-simple property.
|
||||
if (!Object.class.equals(pd.getPropertyType())) {
|
||||
if (Object.class != pd.getPropertyType()) {
|
||||
MethodParameter methodParam = BeanUtils.getWriteMethodParameter(pd);
|
||||
// Do not allow eager init for type matching in case of a prioritized post-processor.
|
||||
boolean eager = !PriorityOrdered.class.isAssignableFrom(bw.getWrappedClass());
|
||||
|
||||
@@ -516,7 +516,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
|
||||
|
||||
Class<?> classToMatch = typeToMatch.getRawClass();
|
||||
Class<?>[] typesToMatch = (FactoryBean.class.equals(classToMatch) ?
|
||||
Class<?>[] typesToMatch = (FactoryBean.class == classToMatch ?
|
||||
new Class<?>[] {classToMatch} : new Class<?>[] {FactoryBean.class, classToMatch});
|
||||
|
||||
// Check decorated bean definition, if any: We assume it'll be easier
|
||||
|
||||
@@ -552,7 +552,7 @@ class ConstructorResolver {
|
||||
"exists and that it is " +
|
||||
(isStatic ? "static" : "non-static") + ".");
|
||||
}
|
||||
else if (void.class.equals(factoryMethodToUse.getReturnType())) {
|
||||
else if (void.class == factoryMethodToUse.getReturnType()) {
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"Invalid factory method '" + mbd.getFactoryMethodName() +
|
||||
"': needs to have a non-void return type!");
|
||||
|
||||
@@ -949,10 +949,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
if (descriptor.getDependencyType().equals(javaUtilOptionalClass)) {
|
||||
return new OptionalDependencyFactory().createOptionalDependency(descriptor, beanName);
|
||||
}
|
||||
else if (descriptor.getDependencyType().equals(ObjectFactory.class)) {
|
||||
else if (ObjectFactory.class == descriptor.getDependencyType()) {
|
||||
return new DependencyObjectFactory(descriptor, beanName);
|
||||
}
|
||||
else if (descriptor.getDependencyType().equals(javaxInjectProviderClass)) {
|
||||
else if (javaxInjectProviderClass == descriptor.getDependencyType()) {
|
||||
return new DependencyProviderFactory().createDependencyProvider(descriptor, beanName);
|
||||
}
|
||||
else {
|
||||
@@ -1031,10 +1031,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
}
|
||||
else if (Map.class.isAssignableFrom(type) && type.isInterface()) {
|
||||
Class<?> keyType = descriptor.getMapKeyType();
|
||||
if (keyType == null || !String.class.isAssignableFrom(keyType)) {
|
||||
if (String.class != keyType) {
|
||||
if (descriptor.isRequired()) {
|
||||
throw new FatalBeanException("Key type [" + keyType + "] of map [" + type.getName() +
|
||||
"] must be assignable to [java.lang.String]");
|
||||
"] must be [java.lang.String]");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" +
|
||||
beanName + "' has more than one parameter - not supported as destroy method");
|
||||
}
|
||||
else if (paramTypes.length == 1 && !paramTypes[0].equals(boolean.class)) {
|
||||
else if (paramTypes.length == 1 && boolean.class != paramTypes[0]) {
|
||||
throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" +
|
||||
beanName + "' has a non-boolean parameter - not supported as destroy method");
|
||||
}
|
||||
|
||||
@@ -159,10 +159,10 @@ public class CustomCollectionEditor extends PropertyEditorSupport {
|
||||
"Could not instantiate collection class [" + collectionType.getName() + "]: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
else if (List.class.equals(collectionType)) {
|
||||
else if (List.class == collectionType) {
|
||||
return new ArrayList<Object>(initialCapacity);
|
||||
}
|
||||
else if (SortedSet.class.equals(collectionType)) {
|
||||
else if (SortedSet.class == collectionType) {
|
||||
return new TreeSet<Object>();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -137,7 +137,7 @@ public class CustomMapEditor extends PropertyEditorSupport {
|
||||
"Could not instantiate map class [" + mapType.getName() + "]: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
else if (SortedMap.class.equals(mapType)) {
|
||||
else if (SortedMap.class == mapType) {
|
||||
return new TreeMap<Object, Object>();
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user