Skip to content

Commit ac80ac6

Browse files
committed
Consistent instanceof/casting of Class references
1 parent 7627c38 commit ac80ac6

File tree

13 files changed

+35
-39
lines changed

13 files changed

+35
-39
lines changed

spring-beans-groovy/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure callable)
458458
private GroovyBeanDefinitionWrapper invokeBeanDefiningMethod(String beanName, Object[] args) {
459459
boolean hasClosureArgument = args[args.length - 1] instanceof Closure;
460460
if (args[0] instanceof Class) {
461-
Class<?> beanClass = (args[0] instanceof Class ? (Class) args[0] : args[0].getClass());
461+
Class<?> beanClass = (args[0] instanceof Class ? (Class<?>) args[0] : args[0].getClass());
462462
if (args.length >= 1) {
463463
if (hasClosureArgument) {
464464
if (args.length-1 != 1) {

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,17 @@
3737
import org.apache.commons.logging.LogFactory;
3838

3939
import org.springframework.beans.BeanUtils;
40-
import org.springframework.beans.factory.Aware;
41-
import org.springframework.beans.factory.BeanClassLoaderAware;
4240
import org.springframework.beans.factory.BeanDefinitionStoreException;
43-
import org.springframework.beans.factory.BeanFactory;
44-
import org.springframework.beans.factory.BeanFactoryAware;
4541
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
4642
import org.springframework.beans.factory.config.BeanDefinition;
4743
import org.springframework.beans.factory.config.BeanDefinitionHolder;
48-
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
4944
import org.springframework.beans.factory.parsing.Location;
5045
import org.springframework.beans.factory.parsing.Problem;
5146
import org.springframework.beans.factory.parsing.ProblemReporter;
5247
import org.springframework.beans.factory.support.AbstractBeanDefinition;
5348
import org.springframework.beans.factory.support.BeanDefinitionReader;
5449
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
5550
import org.springframework.beans.factory.support.BeanNameGenerator;
56-
import org.springframework.context.EnvironmentAware;
57-
import org.springframework.context.ResourceLoaderAware;
5851
import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase;
5952
import org.springframework.core.NestedIOException;
6053
import org.springframework.core.annotation.AnnotationAttributes;
@@ -724,7 +717,7 @@ private class SourceClass {
724717

725718
public SourceClass(Object source) {
726719
this.source = source;
727-
if (source instanceof Class<?>) {
720+
if (source instanceof Class) {
728721
this.metadata = new StandardAnnotationMetadata((Class<?>) source, true);
729722
}
730723
else {
@@ -737,7 +730,7 @@ public final AnnotationMetadata getMetadata() {
737730
}
738731

739732
public Class<?> loadClass() throws ClassNotFoundException {
740-
if (this.source instanceof Class<?>) {
733+
if (this.source instanceof Class) {
741734
return (Class<?>) this.source;
742735
}
743736
String className = ((MetadataReader) this.source).getClassMetadata().getClassName();
@@ -752,15 +745,15 @@ public boolean isAssignable(Class<?> clazz) throws IOException {
752745
}
753746

754747
public ConfigurationClass asConfigClass(ConfigurationClass importedBy) throws IOException {
755-
if (this.source instanceof Class<?>) {
748+
if (this.source instanceof Class) {
756749
return new ConfigurationClass((Class<?>) this.source, importedBy);
757750
}
758751
return new ConfigurationClass((MetadataReader) this.source, importedBy);
759752
}
760753

761754
public Collection<SourceClass> getMemberClasses() throws IOException {
762755
Object sourceToProcess = this.source;
763-
if (sourceToProcess instanceof Class<?>) {
756+
if (sourceToProcess instanceof Class) {
764757
Class<?> sourceClass = (Class<?>) sourceToProcess;
765758
try {
766759
Class<?>[] declaredClasses = sourceClass.getDeclaredClasses();
@@ -797,15 +790,15 @@ public Collection<SourceClass> getMemberClasses() throws IOException {
797790
}
798791

799792
public SourceClass getSuperClass() throws IOException {
800-
if (this.source instanceof Class<?>) {
793+
if (this.source instanceof Class) {
801794
return asSourceClass(((Class<?>) this.source).getSuperclass());
802795
}
803796
return asSourceClass(((MetadataReader) this.source).getClassMetadata().getSuperClassName());
804797
}
805798

806799
public Set<SourceClass> getInterfaces() throws IOException {
807800
Set<SourceClass> result = new LinkedHashSet<>();
808-
if (this.source instanceof Class<?>) {
801+
if (this.source instanceof Class) {
809802
Class<?> sourceClass = (Class<?>) this.source;
810803
for (Class<?> ifcClass : sourceClass.getInterfaces()) {
811804
result.add(asSourceClass(ifcClass));
@@ -847,7 +840,7 @@ public Collection<SourceClass> getAnnotationAttributes(String annotationType, St
847840
}
848841

849842
private SourceClass getRelated(String className) throws IOException {
850-
if (this.source instanceof Class<?>) {
843+
if (this.source instanceof Class) {
851844
try {
852845
Class<?> clazz = ((Class<?>) this.source).getClassLoader().loadClass(className);
853846
return asSourceClass(clazz);

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,10 +1078,10 @@ static Object adaptValue(Object annotatedElement, Object value, boolean classVal
10781078
boolean nestedAnnotationsAsMap) {
10791079

10801080
if (classValuesAsString) {
1081-
if (value instanceof Class<?>) {
1081+
if (value instanceof Class) {
10821082
return ((Class<?>) value).getName();
10831083
}
1084-
else if (value instanceof Class<?>[]) {
1084+
else if (value instanceof Class[]) {
10851085
Class<?>[] clazzArray = (Class<?>[]) value;
10861086
String[] classNames = new String[clazzArray.length];
10871087
for (int i = 0; i < clazzArray.length; i++) {

spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationReadingVisitorUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ else if (value instanceof Type[]) {
8080
value = convArray;
8181
}
8282
else if (classValuesAsString) {
83-
if (value instanceof Class<?>) {
83+
if (value instanceof Class) {
8484
value = ((Class<?>) value).getName();
8585
}
86-
else if (value instanceof Class<?>[]) {
86+
else if (value instanceof Class[]) {
8787
Class<?>[] clazzArray = (Class<?>[]) value;
8888
String[] newValue = new String[clazzArray.length];
8989
for (int i = 0; i < clazzArray.length; i++) {

spring-core/src/main/java/org/springframework/util/TypeUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -48,19 +48,19 @@ public static boolean isAssignable(Type lhsType, Type rhsType) {
4848
return true;
4949
}
5050

51-
if (lhsType instanceof Class<?>) {
51+
if (lhsType instanceof Class) {
5252
Class<?> lhsClass = (Class<?>) lhsType;
5353

5454
// just comparing two classes
55-
if (rhsType instanceof Class<?>) {
55+
if (rhsType instanceof Class) {
5656
return ClassUtils.isAssignable(lhsClass, (Class<?>) rhsType);
5757
}
5858

5959
if (rhsType instanceof ParameterizedType) {
6060
Type rhsRaw = ((ParameterizedType) rhsType).getRawType();
6161

6262
// a parameterized type is always assignable to its raw class type
63-
if (rhsRaw instanceof Class<?>) {
63+
if (rhsRaw instanceof Class) {
6464
return ClassUtils.isAssignable(lhsClass, (Class<?>) rhsRaw);
6565
}
6666
}
@@ -73,10 +73,10 @@ else if (lhsClass.isArray() && rhsType instanceof GenericArrayType) {
7373

7474
// parameterized types are only assignable to other parameterized types and class types
7575
if (lhsType instanceof ParameterizedType) {
76-
if (rhsType instanceof Class<?>) {
76+
if (rhsType instanceof Class) {
7777
Type lhsRaw = ((ParameterizedType) lhsType).getRawType();
7878

79-
if (lhsRaw instanceof Class<?>) {
79+
if (lhsRaw instanceof Class) {
8080
return ClassUtils.isAssignable((Class<?>) lhsRaw, (Class<?>) rhsType);
8181
}
8282
}
@@ -88,7 +88,7 @@ else if (rhsType instanceof ParameterizedType) {
8888
if (lhsType instanceof GenericArrayType) {
8989
Type lhsComponent = ((GenericArrayType) lhsType).getGenericComponentType();
9090

91-
if (rhsType instanceof Class<?>) {
91+
if (rhsType instanceof Class) {
9292
Class<?> rhsClass = (Class<?>) rhsType;
9393

9494
if (rhsClass.isArray()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public BooleanTypedValue getValueInternal(ExpressionState state) throws Evaluati
5959
Object leftValue = left.getValue();
6060
Object rightValue = right.getValue();
6161
BooleanTypedValue result = null;
62-
if (rightValue == null || !(rightValue instanceof Class<?>)) {
62+
if (rightValue == null || !(rightValue instanceof Class)) {
6363
throw new SpelEvaluationException(getRightOperand().getStartPosition(),
6464
SpelMessage.INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND,
6565
(rightValue == null ? "null" : rightValue.getClass().getName()));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,12 +1464,12 @@ else if (method.getName().equals("hashCode")) {
14641464
return System.identityHashCode(proxy);
14651465
}
14661466
else if (method.getName().equals("unwrap")) {
1467-
if (((Class) args[0]).isInstance(proxy)) {
1467+
if (((Class<?>) args[0]).isInstance(proxy)) {
14681468
return proxy;
14691469
}
14701470
}
14711471
else if (method.getName().equals("isWrapperFor")) {
1472-
if (((Class) args[0]).isInstance(proxy)) {
1472+
if (((Class<?>) args[0]).isInstance(proxy)) {
14731473
return true;
14741474
}
14751475
}

spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJackson2MessageConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ else if (conversionHint instanceof JsonView) {
472472
return extractViewClass((JsonView) conversionHint, conversionHint);
473473
}
474474
else if (conversionHint instanceof Class) {
475-
return (Class) conversionHint;
475+
return (Class<?>) conversionHint;
476476
}
477477
else {
478478
return null;

spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
5050

5151
private static final Mono<Object[]> NO_ARGS = Mono.just(new Object[0]);
5252

53-
private final static Object NO_VALUE = new Object();
53+
private static final Object NO_VALUE = new Object();
5454

5555

5656
private List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
@@ -101,8 +101,8 @@ public Mono<HandlerResult> invokeForRequest(ServerWebExchange exchange,
101101
return Mono.error(ex.getTargetException());
102102
}
103103
catch (Throwable ex) {
104-
String s = getInvocationErrorMessage(args);
105-
return Mono.error(new IllegalStateException(s));
104+
String msg = getInvocationErrorMessage(args);
105+
return Mono.error(new IllegalStateException(msg));
106106
}
107107
});
108108
}

spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handler
198198
*/
199199
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
200200
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
201-
RequestCondition<?> condition = (element instanceof Class<?> ?
201+
RequestCondition<?> condition = (element instanceof Class ?
202202
getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element));
203203
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
204204
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected <T> Object readWithMessageConverters(HttpInputMessage inputMessage, Me
171171
}
172172

173173
Class<?> contextClass = (param != null ? param.getContainingClass() : null);
174-
Class<T> targetClass = (targetType instanceof Class<?> ? (Class<T>) targetType : null);
174+
Class<T> targetClass = (targetType instanceof Class ? (Class<T>) targetType : null);
175175
if (targetClass == null) {
176176
ResolvableType resolvableType = (param != null ?
177177
ResolvableType.forMethodParameter(param) : ResolvableType.forType(targetType));

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handler
203203
*/
204204
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
205205
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
206-
RequestCondition<?> condition = (element instanceof Class<?> ?
206+
RequestCondition<?> condition = (element instanceof Class ?
207207
getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element));
208208
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
209209
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* a method argument that provides access to the response stream.
5252
*
5353
* @author Rossen Stoyanchev
54+
* @author Juergen Hoeller
5455
* @since 3.1
5556
*/
5657
public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
@@ -81,6 +82,7 @@ public ServletInvocableHandlerMethod(HandlerMethod handlerMethod) {
8182
initResponseStatus();
8283
}
8384

85+
8486
private void initResponseStatus() {
8587
ResponseStatus annotation = getMethodAnnotation(ResponseStatus.class);
8688
if (annotation == null) {
@@ -92,7 +94,6 @@ private void initResponseStatus() {
9294
}
9395
}
9496

95-
9697
/**
9798
* Register {@link HandlerMethodReturnValueHandler} instances to use to
9899
* handle return values.
@@ -101,8 +102,9 @@ public void setHandlerMethodReturnValueHandlers(HandlerMethodReturnValueHandlerC
101102
this.returnValueHandlers = returnValueHandlers;
102103
}
103104

105+
104106
/**
105-
* Invokes the method and handles the return value through one of the
107+
* Invoke the method and handle the return value through one of the
106108
* configured {@link HandlerMethodReturnValueHandler}s.
107109
* @param webRequest the current request
108110
* @param mavContainer the ModelAndViewContainer for this request
@@ -151,7 +153,7 @@ private void setResponseStatus(ServletWebRequest webRequest) throws IOException
151153
else {
152154
webRequest.getResponse().setStatus(this.responseStatus.value());
153155
}
154-
// to be picked up by the RedirectView
156+
// To be picked up by RedirectView
155157
webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, this.responseStatus);
156158
}
157159

@@ -214,6 +216,7 @@ else if (result instanceof Throwable) {
214216
return result;
215217
}
216218
}, CALLABLE_METHOD);
219+
217220
setHandlerMethodReturnValueHandlers(ServletInvocableHandlerMethod.this.returnValueHandlers);
218221
this.returnType = returnType;
219222
}

0 commit comments

Comments
 (0)