Skip to content

Commit e4c57a9

Browse files
committed
Minor internal refinements (backported from master)
1 parent b0d8a66 commit e4c57a9

File tree

8 files changed

+46
-39
lines changed

8 files changed

+46
-39
lines changed

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@ else if (!this.allowRawInjectionDespiteWrapping && hasDependentBean(beanName)) {
645645
@Nullable
646646
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) {
647647
Class<?> targetType = determineTargetType(beanName, mbd, typesToMatch);
648-
649648
// Apply SmartInstantiationAwareBeanPostProcessors to predict the
650649
// eventual type after a before-instantiation shortcut.
651650
if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
@@ -1364,34 +1363,28 @@ protected void populateBean(String beanName, RootBeanDefinition mbd, @Nullable B
13641363
// Give any InstantiationAwareBeanPostProcessors the opportunity to modify the
13651364
// state of the bean before properties are set. This can be used, for example,
13661365
// to support styles of field injection.
1367-
boolean continueWithPropertyPopulation = true;
1368-
13691366
if (!mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
13701367
for (BeanPostProcessor bp : getBeanPostProcessors()) {
13711368
if (bp instanceof InstantiationAwareBeanPostProcessor) {
13721369
InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp;
13731370
if (!ibp.postProcessAfterInstantiation(bw.getWrappedInstance(), beanName)) {
1374-
continueWithPropertyPopulation = false;
1375-
break;
1371+
return;
13761372
}
13771373
}
13781374
}
13791375
}
13801376

1381-
if (!continueWithPropertyPopulation) {
1382-
return;
1383-
}
1384-
13851377
PropertyValues pvs = (mbd.hasPropertyValues() ? mbd.getPropertyValues() : null);
13861378

1387-
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_NAME || mbd.getResolvedAutowireMode() == AUTOWIRE_BY_TYPE) {
1379+
int resolvedAutowireMode = mbd.getResolvedAutowireMode();
1380+
if (resolvedAutowireMode == AUTOWIRE_BY_NAME || resolvedAutowireMode == AUTOWIRE_BY_TYPE) {
13881381
MutablePropertyValues newPvs = new MutablePropertyValues(pvs);
13891382
// Add property values based on autowire by name if applicable.
1390-
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_NAME) {
1383+
if (resolvedAutowireMode == AUTOWIRE_BY_NAME) {
13911384
autowireByName(beanName, mbd, bw, newPvs);
13921385
}
13931386
// Add property values based on autowire by type if applicable.
1394-
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_TYPE) {
1387+
if (resolvedAutowireMode == AUTOWIRE_BY_TYPE) {
13951388
autowireByType(beanName, mbd, bw, newPvs);
13961389
}
13971390
pvs = newPvs;
@@ -1495,7 +1488,7 @@ protected void autowireByType(
14951488
if (Object.class != pd.getPropertyType()) {
14961489
MethodParameter methodParam = BeanUtils.getWriteMethodParameter(pd);
14971490
// Do not allow eager init for type matching in case of a prioritized post-processor.
1498-
boolean eager = !PriorityOrdered.class.isInstance(bw.getWrappedInstance());
1491+
boolean eager = !(bw.getWrappedInstance() instanceof PriorityOrdered);
14991492
DependencyDescriptor desc = new AutowireByTypeDependencyDescriptor(methodParam, eager);
15001493
Object autowiredArgument = resolveDependency(desc, beanName, autowiredBeanNames, converter);
15011494
if (autowiredArgument != null) {

spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java

Lines changed: 19 additions & 7 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.
@@ -237,6 +237,7 @@ protected PropertiesHolder getMergedProperties(Locale locale) {
237237
if (mergedHolder != null) {
238238
return mergedHolder;
239239
}
240+
240241
Properties mergedProps = newProperties();
241242
long latestTimestamp = -1;
242243
String[] basenames = StringUtils.toStringArray(getBasenameSet());
@@ -253,6 +254,7 @@ protected PropertiesHolder getMergedProperties(Locale locale) {
253254
}
254255
}
255256
}
257+
256258
mergedHolder = new PropertiesHolder(mergedProps, latestTimestamp);
257259
PropertiesHolder existing = this.cachedMergedProperties.putIfAbsent(locale, mergedHolder);
258260
if (existing != null) {
@@ -279,18 +281,28 @@ protected List<String> calculateAllFilenames(String basename, Locale locale) {
279281
return filenames;
280282
}
281283
}
284+
285+
// Filenames for given Locale
282286
List<String> filenames = new ArrayList<>(7);
283287
filenames.addAll(calculateFilenamesForLocale(basename, locale));
284-
if (isFallbackToSystemLocale() && !locale.equals(Locale.getDefault())) {
285-
List<String> fallbackFilenames = calculateFilenamesForLocale(basename, Locale.getDefault());
286-
for (String fallbackFilename : fallbackFilenames) {
287-
if (!filenames.contains(fallbackFilename)) {
288-
// Entry for fallback locale that isn't already in filenames list.
289-
filenames.add(fallbackFilename);
288+
289+
// Filenames for default Locale, if any
290+
if (isFallbackToSystemLocale()) {
291+
Locale defaultLocale = Locale.getDefault();
292+
if (!locale.equals(defaultLocale)) {
293+
List<String> fallbackFilenames = calculateFilenamesForLocale(basename, defaultLocale);
294+
for (String fallbackFilename : fallbackFilenames) {
295+
if (!filenames.contains(fallbackFilename)) {
296+
// Entry for fallback locale that isn't already in filenames list.
297+
filenames.add(fallbackFilename);
298+
}
290299
}
291300
}
292301
}
302+
303+
// Filename for default bundle file
293304
filenames.add(basename);
305+
294306
if (localeMap == null) {
295307
localeMap = new ConcurrentHashMap<>();
296308
Map<Locale, List<String>> existing = this.cachedFilenames.putIfAbsent(basename, localeMap);

spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java

Lines changed: 6 additions & 3 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.
@@ -794,6 +794,7 @@ public void handleIt(TestEvent event) {
794794

795795
@EventListener
796796
@Async
797+
@Override
797798
public void handleAsync(AnotherTestEvent event) {
798799
assertTrue(!Thread.currentThread().getName().equals(event.content));
799800
this.eventCollector.addEvent(this, event);
@@ -820,6 +821,7 @@ public void handleIt(TestEvent event) {
820821

821822
@EventListener
822823
@Async
824+
@Override
823825
public void handleAsync(AnotherTestEvent event) {
824826
assertTrue(!Thread.currentThread().getName().equals(event.content));
825827
this.eventCollector.addEvent(this, event);
@@ -902,7 +904,6 @@ public void handleString(GenericEventPojo<String> value) {
902904
}
903905

904906

905-
906907
@EventListener
907908
@Retention(RetentionPolicy.RUNTIME)
908909
public @interface ConditionalEvent {
@@ -934,18 +935,20 @@ public void handle(TestEvent event) {
934935
super.handle(event);
935936
}
936937

937-
@Override
938938
@EventListener(condition = "#payload.startsWith('OK')")
939+
@Override
939940
public void handleString(String payload) {
940941
super.handleString(payload);
941942
}
942943

943944
@ConditionalEvent("#root.event.timestamp > #p0")
945+
@Override
944946
public void handleTimestamp(Long timestamp) {
945947
collectEvent(timestamp);
946948
}
947949

948950
@ConditionalEvent("@conditionEvaluator.valid(#p0)")
951+
@Override
949952
public void handleRatio(Double ratio) {
950953
collectEvent(ratio);
951954
}

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/EventSourceTransportHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -30,7 +30,7 @@
3030
import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSession;
3131

3232
/**
33-
* A TransportHandler for sending messages via Server-Sent events:
33+
* A TransportHandler for sending messages via Server-Sent Events:
3434
* <a href="https://dev.w3.org/html5/eventsource/">https://dev.w3.org/html5/eventsource/</a>.
3535
*
3636
* @author Rossen Stoyanchev
@@ -50,7 +50,7 @@ protected MediaType getContentType() {
5050

5151
@Override
5252
public boolean checkSessionType(SockJsSession session) {
53-
return session instanceof EventSourceStreamingSockJsSession;
53+
return (session instanceof EventSourceStreamingSockJsSession);
5454
}
5555

5656
@Override
@@ -66,7 +66,7 @@ protected SockJsFrameFormat getFrameFormat(ServerHttpRequest request) {
6666
}
6767

6868

69-
private class EventSourceStreamingSockJsSession extends StreamingSockJsSession {
69+
private static class EventSourceStreamingSockJsSession extends StreamingSockJsSession {
7070

7171
public EventSourceStreamingSockJsSession(String sessionId, SockJsServiceConfig config,
7272
WebSocketHandler wsHandler, Map<String, Object> attributes) {
@@ -76,7 +76,7 @@ public EventSourceStreamingSockJsSession(String sessionId, SockJsServiceConfig c
7676

7777
@Override
7878
protected byte[] getPrelude(ServerHttpRequest request) {
79-
return new byte[] { '\r', '\n' };
79+
return new byte[] {'\r', '\n'};
8080
}
8181
}
8282

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java

Lines changed: 2 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.
@@ -93,7 +93,7 @@ protected MediaType getContentType() {
9393

9494
@Override
9595
public boolean checkSessionType(SockJsSession session) {
96-
return session instanceof HtmlFileStreamingSockJsSession;
96+
return (session instanceof HtmlFileStreamingSockJsSession);
9797
}
9898

9999
@Override

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java

Lines changed: 2 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.
@@ -107,7 +107,7 @@ public boolean isRunning() {
107107

108108
@Override
109109
public boolean checkSessionType(SockJsSession session) {
110-
return session instanceof WebSocketServerSockJsSession;
110+
return (session instanceof WebSocketServerSockJsSession);
111111
}
112112

113113
@Override

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrPollingTransportHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -54,7 +54,7 @@ protected SockJsFrameFormat getFrameFormat(ServerHttpRequest request) {
5454

5555
@Override
5656
public boolean checkSessionType(SockJsSession session) {
57-
return session instanceof PollingSockJsSession;
57+
return (session instanceof PollingSockJsSession);
5858
}
5959

6060
@Override

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrStreamingTransportHandler.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -17,6 +17,7 @@
1717
package org.springframework.web.socket.sockjs.transport.handler;
1818

1919
import java.nio.charset.StandardCharsets;
20+
import java.util.Arrays;
2021
import java.util.Map;
2122

2223
import org.springframework.http.MediaType;
@@ -41,9 +42,7 @@ public class XhrStreamingTransportHandler extends AbstractHttpSendingTransportHa
4142
private static final byte[] PRELUDE = new byte[2049];
4243

4344
static {
44-
for (int i = 0; i < 2048; i++) {
45-
PRELUDE[i] = 'h';
46-
}
45+
Arrays.fill(PRELUDE, (byte) 'h');
4746
PRELUDE[2048] = '\n';
4847
}
4948

@@ -60,7 +59,7 @@ protected MediaType getContentType() {
6059

6160
@Override
6261
public boolean checkSessionType(SockJsSession session) {
63-
return session instanceof XhrStreamingSockJsSession;
62+
return (session instanceof XhrStreamingSockJsSession);
6463
}
6564

6665
@Override

0 commit comments

Comments
 (0)