Skip to content

Commit 0524f3a

Browse files
committed
Class identity comparisons wherever possible
Issue: SPR-12926
1 parent e8417ea commit 0524f3a

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,17 @@ public boolean hasAnnotation(Class<? extends Annotation> annotationType) {
248248
}
249249

250250
/**
251-
* Obtain the annotation of the specified {@code annotationType} that is
252-
* on this type descriptor.
253-
* <p>As of Spring Framework 4.2, this method supports arbitrary levels
254-
* of meta-annotations.
251+
* Obtain the annotation of the specified {@code annotationType} that is on this type descriptor.
252+
* <p>As of Spring Framework 4.2, this method supports arbitrary levels of meta-annotations.
255253
* @param annotationType the annotation type
256254
* @return the annotation, or {@code null} if no such annotation exists on this type descriptor
257255
*/
258256
@SuppressWarnings("unchecked")
259257
public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
260258
// Search in annotations that are "present" (i.e., locally declared or inherited)
261-
//
262259
// NOTE: this unfortunately favors inherited annotations over locally declared composed annotations.
263260
for (Annotation annotation : getAnnotations()) {
264-
if (annotation.annotationType().equals(annotationType)) {
261+
if (annotation.annotationType() == annotationType) {
265262
return (T) annotation;
266263
}
267264
}
@@ -471,7 +468,7 @@ public boolean equals(Object obj) {
471468
return false;
472469
}
473470
for (Annotation ann : getAnnotations()) {
474-
if (other.getAnnotation(ann.annotationType()) == null) {
471+
if (!other.hasAnnotation(ann.annotationType())) {
475472
return false;
476473
}
477474
}

spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,22 @@ private static Constructor<?> getFactoryConstructor(Class<?> targetClass, Class<
144144
return ClassUtils.getConstructorIfAvailable(targetClass, sourceClass);
145145
}
146146

147-
private static boolean hasToMethodOrFactoryMethodOrConstructor(Class<?> targetClass,
148-
Class<?> sourceClass) {
147+
private static boolean hasToMethodOrFactoryMethodOrConstructor(Class<?> targetClass, Class<?> sourceClass) {
149148
return (hasToMethod(targetClass, sourceClass) ||
150149
hasFactoryMethod(targetClass, sourceClass) ||
151150
hasFactoryConstructor(targetClass, sourceClass));
152151
}
153152

154153
static boolean hasToMethod(Class<?> targetClass, Class<?> sourceClass) {
155-
return getToMethod(targetClass, sourceClass) != null;
154+
return (getToMethod(targetClass, sourceClass) != null);
156155
}
157156

158157
static boolean hasFactoryMethod(Class<?> targetClass, Class<?> sourceClass) {
159-
return getFactoryMethod(targetClass, sourceClass) != null;
158+
return (getFactoryMethod(targetClass, sourceClass) != null);
160159
}
161160

162161
static boolean hasFactoryConstructor(Class<?> targetClass, Class<?> sourceClass) {
163-
return getFactoryConstructor(targetClass, sourceClass) != null;
162+
return (getFactoryConstructor(targetClass, sourceClass) != null);
164163
}
165164

166165
}

0 commit comments

Comments
 (0)