Skip to content

Commit 33b5bc2

Browse files
committed
Polishing
1 parent 22aba8b commit 33b5bc2

File tree

8 files changed

+60
-54
lines changed

8 files changed

+60
-54
lines changed

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

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,40 @@ protected Class<?> resolveTargetType(TypedStringValue value) throws ClassNotFoun
281281
return value.resolveTargetType(this.beanFactory.getBeanClassLoader());
282282
}
283283

284+
/**
285+
* Resolve a reference to another bean in the factory.
286+
*/
287+
@Nullable
288+
private Object resolveReference(Object argName, RuntimeBeanReference ref) {
289+
try {
290+
Object bean;
291+
String refName = ref.getBeanName();
292+
refName = String.valueOf(doEvaluate(refName));
293+
if (ref.isToParent()) {
294+
if (this.beanFactory.getParentBeanFactory() == null) {
295+
throw new BeanCreationException(
296+
this.beanDefinition.getResourceDescription(), this.beanName,
297+
"Can't resolve reference to bean '" + refName +
298+
"' in parent factory: no parent factory available");
299+
}
300+
bean = this.beanFactory.getParentBeanFactory().getBean(refName);
301+
}
302+
else {
303+
bean = this.beanFactory.getBean(refName);
304+
this.beanFactory.registerDependentBean(refName, this.beanName);
305+
}
306+
if (bean instanceof NullBean) {
307+
bean = null;
308+
}
309+
return bean;
310+
}
311+
catch (BeansException ex) {
312+
throw new BeanCreationException(
313+
this.beanDefinition.getResourceDescription(), this.beanName,
314+
"Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex);
315+
}
316+
}
317+
284318
/**
285319
* Resolve an inner bean definition.
286320
* @param argName the name of the argument that the inner bean is defined for
@@ -345,40 +379,6 @@ private String adaptInnerBeanName(String innerBeanName) {
345379
return actualInnerBeanName;
346380
}
347381

348-
/**
349-
* Resolve a reference to another bean in the factory.
350-
*/
351-
@Nullable
352-
private Object resolveReference(Object argName, RuntimeBeanReference ref) {
353-
try {
354-
Object bean;
355-
String refName = ref.getBeanName();
356-
refName = String.valueOf(doEvaluate(refName));
357-
if (ref.isToParent()) {
358-
if (this.beanFactory.getParentBeanFactory() == null) {
359-
throw new BeanCreationException(
360-
this.beanDefinition.getResourceDescription(), this.beanName,
361-
"Can't resolve reference to bean '" + refName +
362-
"' in parent factory: no parent factory available");
363-
}
364-
bean = this.beanFactory.getParentBeanFactory().getBean(refName);
365-
}
366-
else {
367-
bean = this.beanFactory.getBean(refName);
368-
this.beanFactory.registerDependentBean(refName, this.beanName);
369-
}
370-
if (bean instanceof NullBean) {
371-
bean = null;
372-
}
373-
return bean;
374-
}
375-
catch (BeansException ex) {
376-
throw new BeanCreationException(
377-
this.beanDefinition.getResourceDescription(), this.beanName,
378-
"Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex);
379-
}
380-
}
381-
382382
/**
383383
* For each element in the managed array, resolve reference if necessary.
384384
*/

spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public void multicastEvent(ApplicationEvent event) {
130130
@Override
131131
public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType) {
132132
ResolvableType type = (eventType != null ? eventType : resolveDefaultEventType(event));
133-
for (final ApplicationListener<?> listener : getApplicationListeners(event, type)) {
134-
Executor executor = getTaskExecutor();
133+
Executor executor = getTaskExecutor();
134+
for (ApplicationListener<?> listener : getApplicationListeners(event, type)) {
135135
if (executor != null) {
136136
executor.execute(() -> invokeListener(listener, event));
137137
}

spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -658,6 +658,9 @@ public boolean equals(Object other) {
658658
if (this == other) {
659659
return true;
660660
}
661+
if (!(other instanceof MethodCacheKey)) {
662+
return false;
663+
}
661664
MethodCacheKey otherKey = (MethodCacheKey) other;
662665
return (this.name.equals(otherKey.name) && Arrays.equals(this.parameterTypes, otherKey.parameterTypes));
663666
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public <T extends Enum> Converter<Integer, T> getConverter(Class<T> targetType)
3535
}
3636

3737

38-
private class IntegerToEnum<T extends Enum> implements Converter<Integer, T> {
38+
private static class IntegerToEnum<T extends Enum> implements Converter<Integer, T> {
3939

4040
private final Class<T> enumType;
4141

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public <T extends Enum> Converter<String, T> getConverter(Class<T> targetType) {
3535
}
3636

3737

38-
private class StringToEnum<T extends Enum> implements Converter<String, T> {
38+
private static class StringToEnum<T extends Enum> implements Converter<String, T> {
3939

4040
private final Class<T> enumType;
4141

spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import org.springframework.util.NumberUtils;
2727

2828
/**
29-
* A simple basic {@link TypeComparator} implementation.
30-
* It supports comparison of Numbers and types implementing Comparable.
29+
* A basic {@link TypeComparator} implementation: supports comparison of
30+
* {@link Number} types as well as types implementing {@link Comparable}.
3131
*
3232
* @author Andy Clement
3333
* @author Juergen Hoeller
@@ -89,10 +89,10 @@ else if (leftNumber instanceof Integer || rightNumber instanceof Integer) {
8989
return Integer.compare(leftNumber.intValue(), rightNumber.intValue());
9090
}
9191
else if (leftNumber instanceof Short || rightNumber instanceof Short) {
92-
return leftNumber.shortValue() - rightNumber.shortValue();
92+
return Short.compare(leftNumber.shortValue(), rightNumber.shortValue());
9393
}
9494
else if (leftNumber instanceof Byte || rightNumber instanceof Byte) {
95-
return leftNumber.byteValue() - rightNumber.byteValue();
95+
return Byte.compare(leftNumber.byteValue(), rightNumber.byteValue());
9696
}
9797
else {
9898
// Unknown Number subtypes -> best guess is double multiplication

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -522,7 +522,8 @@ protected boolean destinationEquals(DestinationCacheKey otherKey) {
522522
public boolean equals(Object other) {
523523
// Effectively checking object equality as well as toString equality.
524524
// On WebSphere MQ, Destination objects do not implement equals...
525-
return (this == other || destinationEquals((DestinationCacheKey) other));
525+
return (this == other || (other instanceof DestinationCacheKey &&
526+
destinationEquals((DestinationCacheKey) other)));
526527
}
527528

528529
@Override
@@ -577,6 +578,9 @@ public boolean equals(Object other) {
577578
if (this == other) {
578579
return true;
579580
}
581+
if (!(other instanceof ConsumerCacheKey)) {
582+
return false;
583+
}
580584
ConsumerCacheKey otherKey = (ConsumerCacheKey) other;
581585
return (destinationEquals(otherKey) &&
582586
ObjectUtils.nullSafeEquals(this.selector, otherKey.selector) &&

spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -38,6 +38,7 @@
3838

3939
/**
4040
* {@code HandlerMapping} implementation that supports {@link RouterFunction RouterFunctions}.
41+
*
4142
* <p>If no {@link RouterFunction} is provided at
4243
* {@linkplain #RouterFunctionMapping(RouterFunction) construction time}, this mapping
4344
* will detect all router functions in the application context, and consult them in
@@ -56,8 +57,8 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini
5657

5758
/**
5859
* Create an empty {@code RouterFunctionMapping}.
59-
* <p>If this constructor is used, this mapping will detect all {@link RouterFunction} instances
60-
* available in the application context.
60+
* <p>If this constructor is used, this mapping will detect all
61+
* {@link RouterFunction} instances available in the application context.
6162
*/
6263
public RouterFunctionMapping() {
6364
}
@@ -154,20 +155,18 @@ protected Mono<?> getHandlerInternal(ServerWebExchange exchange) {
154155
}
155156

156157
@SuppressWarnings("unchecked")
157-
private void setAttributes(Map<String, Object> attributes, ServerRequest serverRequest,
158-
HandlerFunction<?> handlerFunction) {
158+
private void setAttributes(
159+
Map<String, Object> attributes, ServerRequest serverRequest, HandlerFunction<?> handlerFunction) {
159160

160161
attributes.put(RouterFunctions.REQUEST_ATTRIBUTE, serverRequest);
161162
attributes.put(BEST_MATCHING_HANDLER_ATTRIBUTE, handlerFunction);
162163

163-
PathPattern matchingPattern =
164-
(PathPattern) attributes.get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
164+
PathPattern matchingPattern = (PathPattern) attributes.get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
165165
if (matchingPattern != null) {
166166
attributes.put(BEST_MATCHING_PATTERN_ATTRIBUTE, matchingPattern);
167167
}
168168
Map<String, String> uriVariables =
169-
(Map<String, String>) attributes
170-
.get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
169+
(Map<String, String>) attributes.get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
171170
if (uriVariables != null) {
172171
attributes.put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables);
173172
}

0 commit comments

Comments
 (0)