Skip to content

Commit 4b06d8e

Browse files
committed
Merge branch '5.1.x'
2 parents 47ff928 + 3f85a7d commit 4b06d8e

File tree

4 files changed

+53
-46
lines changed

4 files changed

+53
-46
lines changed

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

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.util.Optional;
4141
import java.util.Set;
4242
import java.util.concurrent.ConcurrentHashMap;
43+
import java.util.function.Consumer;
44+
import java.util.function.Predicate;
4345
import java.util.stream.Stream;
4446
import javax.inject.Provider;
4547

@@ -946,18 +948,14 @@ else if (!beanDefinition.equals(existingDefinition)) {
946948
updatedDefinitions.addAll(this.beanDefinitionNames);
947949
updatedDefinitions.add(beanName);
948950
this.beanDefinitionNames = updatedDefinitions;
949-
if (this.manualSingletonNames.contains(beanName)) {
950-
Set<String> updatedSingletons = new LinkedHashSet<>(this.manualSingletonNames);
951-
updatedSingletons.remove(beanName);
952-
this.manualSingletonNames = updatedSingletons;
953-
}
951+
removeManualSingletonName(beanName);
954952
}
955953
}
956954
else {
957955
// Still in startup registration phase
958956
this.beanDefinitionMap.put(beanName, beanDefinition);
959957
this.beanDefinitionNames.add(beanName);
960-
this.manualSingletonNames.remove(beanName);
958+
removeManualSingletonName(beanName);
961959
}
962960
this.frozenBeanDefinitionNames = null;
963961
}
@@ -1045,40 +1043,51 @@ protected boolean allowAliasOverriding() {
10451043
@Override
10461044
public void registerSingleton(String beanName, Object singletonObject) throws IllegalStateException {
10471045
super.registerSingleton(beanName, singletonObject);
1046+
updateManualSingletonNames(set -> set.add(beanName), set -> !this.beanDefinitionMap.containsKey(beanName));
1047+
clearByTypeCache();
1048+
}
1049+
1050+
@Override
1051+
public void destroySingletons() {
1052+
super.destroySingletons();
1053+
updateManualSingletonNames(Set::clear, set -> !set.isEmpty());
1054+
clearByTypeCache();
1055+
}
1056+
1057+
@Override
1058+
public void destroySingleton(String beanName) {
1059+
super.destroySingleton(beanName);
1060+
removeManualSingletonName(beanName);
1061+
clearByTypeCache();
1062+
}
1063+
1064+
private void removeManualSingletonName(String beanName) {
1065+
updateManualSingletonNames(set -> set.remove(beanName), set -> set.contains(beanName));
1066+
}
10481067

1068+
/**
1069+
* Update the factory's internal set of manual singleton names.
1070+
* @param action the modification action
1071+
* @param condition a precondition for the modification action
1072+
* (if this condition does not apply, the action can be skipped)
1073+
*/
1074+
private void updateManualSingletonNames(Consumer<Set<String>> action, Predicate<Set<String>> condition) {
10491075
if (hasBeanCreationStarted()) {
10501076
// Cannot modify startup-time collection elements anymore (for stable iteration)
10511077
synchronized (this.beanDefinitionMap) {
1052-
if (!this.beanDefinitionMap.containsKey(beanName)) {
1053-
Set<String> updatedSingletons = new LinkedHashSet<>(this.manualSingletonNames.size() + 1);
1054-
updatedSingletons.addAll(this.manualSingletonNames);
1055-
updatedSingletons.add(beanName);
1078+
if (condition.test(this.manualSingletonNames)) {
1079+
Set<String> updatedSingletons = new LinkedHashSet<>(this.manualSingletonNames);
1080+
action.accept(updatedSingletons);
10561081
this.manualSingletonNames = updatedSingletons;
10571082
}
10581083
}
10591084
}
10601085
else {
10611086
// Still in startup registration phase
1062-
if (!this.beanDefinitionMap.containsKey(beanName)) {
1063-
this.manualSingletonNames.add(beanName);
1087+
if (condition.test(this.manualSingletonNames)) {
1088+
action.accept(this.manualSingletonNames);
10641089
}
10651090
}
1066-
1067-
clearByTypeCache();
1068-
}
1069-
1070-
@Override
1071-
public void destroySingleton(String beanName) {
1072-
super.destroySingleton(beanName);
1073-
this.manualSingletonNames.remove(beanName);
1074-
clearByTypeCache();
1075-
}
1076-
1077-
@Override
1078-
public void destroySingletons() {
1079-
super.destroySingletons();
1080-
this.manualSingletonNames.clear();
1081-
clearByTypeCache();
10821091
}
10831092

10841093
/**

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java

Lines changed: 5 additions & 5 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.
@@ -147,11 +147,11 @@ protected Object[] getMethodArgumentValues(Message<?> message, Object... provide
147147
args[i] = this.resolvers.resolveArgument(parameter, message);
148148
}
149149
catch (Exception ex) {
150-
// Leave stack trace for later, exception may actually be resolved and handled..
150+
// Leave stack trace for later, exception may actually be resolved and handled...
151151
if (logger.isDebugEnabled()) {
152-
String error = ex.getMessage();
153-
if (error != null && !error.contains(parameter.getExecutable().toGenericString())) {
154-
logger.debug(formatArgumentError(parameter, error));
152+
String exMsg = ex.getMessage();
153+
if (exMsg != null && !exMsg.contains(parameter.getExecutable().toGenericString())) {
154+
logger.debug(formatArgumentError(parameter, exMsg));
155155
}
156156
}
157157
throw ex;

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

Lines changed: 5 additions & 5 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.
@@ -166,11 +166,11 @@ protected Object[] getMethodArgumentValues(NativeWebRequest request, @Nullable M
166166
args[i] = this.resolvers.resolveArgument(parameter, mavContainer, request, this.dataBinderFactory);
167167
}
168168
catch (Exception ex) {
169-
// Leave stack trace for later, exception may actually be resolved and handled..
169+
// Leave stack trace for later, exception may actually be resolved and handled...
170170
if (logger.isDebugEnabled()) {
171-
String error = ex.getMessage();
172-
if (error != null && !error.contains(parameter.getExecutable().toGenericString())) {
173-
logger.debug(formatArgumentError(parameter, error));
171+
String exMsg = ex.getMessage();
172+
if (exMsg != null && !exMsg.contains(parameter.getExecutable().toGenericString())) {
173+
logger.debug(formatArgumentError(parameter, exMsg));
174174
}
175175
}
176176
throw ex;

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private Mono<Object[]> getMethodArgumentValues(
200200
try {
201201
argMonos.add(this.resolvers.resolveArgument(parameter, bindingContext, exchange)
202202
.defaultIfEmpty(NO_ARG_VALUE)
203-
.doOnError(cause -> logArgumentErrorIfNecessary(exchange, parameter, cause)));
203+
.doOnError(ex -> logArgumentErrorIfNecessary(exchange, parameter, ex)));
204204
}
205205
catch (Exception ex) {
206206
logArgumentErrorIfNecessary(exchange, parameter, ex);
@@ -211,14 +211,12 @@ private Mono<Object[]> getMethodArgumentValues(
211211
Stream.of(values).map(o -> o != NO_ARG_VALUE ? o : null).toArray());
212212
}
213213

214-
private void logArgumentErrorIfNecessary(
215-
ServerWebExchange exchange, MethodParameter parameter, Throwable cause) {
216-
217-
// Leave stack trace for later, if error is not handled..
218-
String message = cause.getMessage();
219-
if (message != null && !message.contains(parameter.getExecutable().toGenericString())) {
214+
private void logArgumentErrorIfNecessary(ServerWebExchange exchange, MethodParameter parameter, Throwable ex) {
215+
// Leave stack trace for later, if error is not handled...
216+
String exMsg = ex.getMessage();
217+
if (exMsg != null && !exMsg.contains(parameter.getExecutable().toGenericString())) {
220218
if (logger.isDebugEnabled()) {
221-
logger.debug(exchange.getLogPrefix() + formatArgumentError(parameter, message));
219+
logger.debug(exchange.getLogPrefix() + formatArgumentError(parameter, exMsg));
222220
}
223221
}
224222
}

0 commit comments

Comments
 (0)