Skip to content

Commit 11806b9

Browse files
committed
Class identity comparisons wherever possible (and further polishing)
Issue: SPR-12926
1 parent 4261f34 commit 11806b9

File tree

29 files changed

+127
-109
lines changed

29 files changed

+127
-109
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ private boolean equalsAdviceClasses(Advisor a, Advisor b) {
922922
if (aa == null || ba == null) {
923923
return (aa == ba);
924924
}
925-
return aa.getClass().equals(ba.getClass());
925+
return (aa.getClass() == ba.getClass());
926926
}
927927

928928
private boolean equalsPointcuts(Advisor a, Advisor b) {

spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public boolean equals(Object other) {
165165
if (this == other) {
166166
return true;
167167
}
168-
if (other == null || !getClass().equals(other.getClass())) {
168+
if (other == null || getClass() != other.getClass()) {
169169
return false;
170170
}
171171
AbstractBeanFactoryBasedTargetSource otherTargetSource = (AbstractBeanFactoryBasedTargetSource) other;

spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void setWrappedInstance(Object object) {
203203
*/
204204
public void setWrappedInstance(Object object, String nestedPath, Object rootObject) {
205205
Assert.notNull(object, "Target object must not be null");
206-
if (object.getClass().equals(javaUtilOptionalClass)) {
206+
if (object.getClass() == javaUtilOptionalClass) {
207207
this.object = OptionalUnwrapper.unwrap(object);
208208
}
209209
else {
@@ -834,7 +834,7 @@ private AbstractNestablePropertyAccessor getNestedPropertyAccessor(String nested
834834
PropertyTokenHolder tokens = getPropertyNameTokens(nestedProperty);
835835
String canonicalName = tokens.canonicalName;
836836
Object value = getPropertyValue(tokens);
837-
if (value == null || (value.getClass().equals(javaUtilOptionalClass) && OptionalUnwrapper.isEmpty(value))) {
837+
if (value == null || (value.getClass() == javaUtilOptionalClass && OptionalUnwrapper.isEmpty(value))) {
838838
if (isAutoGrowNestedPaths()) {
839839
value = setDefaultValue(tokens);
840840
}
@@ -846,7 +846,7 @@ private AbstractNestablePropertyAccessor getNestedPropertyAccessor(String nested
846846
// Lookup cached sub-PropertyAccessor, create new one if not found.
847847
AbstractNestablePropertyAccessor nestedPa = this.nestedPropertyAccessors.get(canonicalName);
848848
if (nestedPa == null || nestedPa.getWrappedInstance() !=
849-
(value.getClass().equals(javaUtilOptionalClass) ? OptionalUnwrapper.unwrap(value) : value)) {
849+
(value.getClass() == javaUtilOptionalClass ? OptionalUnwrapper.unwrap(value) : value)) {
850850
if (logger.isTraceEnabled()) {
851851
logger.trace("Creating new nested " + getClass().getSimpleName() + " for property '" + canonicalName + "'");
852852
}

spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -105,7 +105,7 @@ public void clear(PropertyValues pvs) {
105105

106106

107107
public static boolean needsRefresh(InjectionMetadata metadata, Class<?> clazz) {
108-
return (metadata == null || !metadata.targetClass.equals(clazz));
108+
return (metadata == null || metadata.targetClass != clazz);
109109
}
110110

111111

spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public RootBeanDefinition getBeanDefinition() {
174174

175175
@Override
176176
public boolean equals(Object other) {
177-
return (getClass().equals(other.getClass()) &&
177+
return (getClass() == other.getClass() &&
178178
this.beanDefinition.equals(((CglibIdentitySupport) other).beanDefinition));
179179
}
180180

spring-context/src/main/java/org/springframework/validation/DataBinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public DataBinder(Object target) {
184184
* @param objectName the name of the target object
185185
*/
186186
public DataBinder(Object target, String objectName) {
187-
if (target != null && target.getClass().equals(javaUtilOptionalClass)) {
187+
if (target != null && target.getClass() == javaUtilOptionalClass) {
188188
this.target = OptionalUnwrapper.unwrap(target);
189189
}
190190
else {

spring-context/src/main/java/org/springframework/validation/ObjectError.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,7 +78,7 @@ public boolean equals(Object other) {
7878
if (this == other) {
7979
return true;
8080
}
81-
if (!(getClass().equals(other.getClass())) || !super.equals(other)) {
81+
if (getClass() != other.getClass() || !super.equals(other)) {
8282
return false;
8383
}
8484
ObjectError otherError = (ObjectError) other;

spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public CachedMethodExecutor(MethodExecutor methodExecutor, Class<?> staticClass,
376376
}
377377

378378
public boolean isSuitable(Object value, TypeDescriptor target, List<TypeDescriptor> argumentTypes) {
379-
return ((this.staticClass == null || this.staticClass.equals(value)) &&
379+
return ((this.staticClass == null || this.staticClass == value) &&
380380
this.target.equals(target) && this.argumentTypes.equals(argumentTypes));
381381
}
382382

spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void setMappedClass(Class<T> mappedClass) {
131131
initialize(mappedClass);
132132
}
133133
else {
134-
if (!this.mappedClass.equals(mappedClass)) {
134+
if (this.mappedClass != mappedClass) {
135135
throw new InvalidDataAccessApiUsageException("The mapped class can not be reassigned to map to " +
136136
mappedClass + " since it is already providing mapping for " + this.mappedClass);
137137
}

spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private class Jms2MessageProducerInvocationHandler implements InvocationHandler
276276
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
277277
try {
278278
if (method.getName().equals("send") && args != null &&
279-
completionListenerClass.equals(method.getParameterTypes()[args.length - 1])) {
279+
completionListenerClass == method.getParameterTypes()[args.length - 1]) {
280280
switch (args.length) {
281281
case 2: // send(message, completionListener)
282282
return sendWithCompletionListenerMethod.invoke(

0 commit comments

Comments
 (0)