Skip to content

Commit be0e0f6

Browse files
committed
Minor internal refinements (backported from master)
1 parent d1a01f2 commit be0e0f6

File tree

8 files changed

+51
-42
lines changed

8 files changed

+51
-42
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
@@ -625,7 +625,6 @@ else if (!this.allowRawInjectionDespiteWrapping && hasDependentBean(beanName)) {
625625
@Nullable
626626
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) {
627627
Class<?> targetType = determineTargetType(beanName, mbd, typesToMatch);
628-
629628
// Apply SmartInstantiationAwareBeanPostProcessors to predict the
630629
// eventual type after a before-instantiation shortcut.
631630
if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
@@ -1288,34 +1287,28 @@ protected void populateBean(String beanName, RootBeanDefinition mbd, @Nullable B
12881287
// Give any InstantiationAwareBeanPostProcessors the opportunity to modify the
12891288
// state of the bean before properties are set. This can be used, for example,
12901289
// to support styles of field injection.
1291-
boolean continueWithPropertyPopulation = true;
1292-
12931290
if (!mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
12941291
for (BeanPostProcessor bp : getBeanPostProcessors()) {
12951292
if (bp instanceof InstantiationAwareBeanPostProcessor) {
12961293
InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp;
12971294
if (!ibp.postProcessAfterInstantiation(bw.getWrappedInstance(), beanName)) {
1298-
continueWithPropertyPopulation = false;
1299-
break;
1295+
return;
13001296
}
13011297
}
13021298
}
13031299
}
13041300

1305-
if (!continueWithPropertyPopulation) {
1306-
return;
1307-
}
1308-
13091301
PropertyValues pvs = (mbd.hasPropertyValues() ? mbd.getPropertyValues() : null);
13101302

1311-
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_NAME || mbd.getResolvedAutowireMode() == AUTOWIRE_BY_TYPE) {
1303+
int resolvedAutowireMode = mbd.getResolvedAutowireMode();
1304+
if (resolvedAutowireMode == AUTOWIRE_BY_NAME || resolvedAutowireMode == AUTOWIRE_BY_TYPE) {
13121305
MutablePropertyValues newPvs = new MutablePropertyValues(pvs);
13131306
// Add property values based on autowire by name if applicable.
1314-
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_NAME) {
1307+
if (resolvedAutowireMode == AUTOWIRE_BY_NAME) {
13151308
autowireByName(beanName, mbd, bw, newPvs);
13161309
}
13171310
// Add property values based on autowire by type if applicable.
1318-
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_TYPE) {
1311+
if (resolvedAutowireMode == AUTOWIRE_BY_TYPE) {
13191312
autowireByType(beanName, mbd, bw, newPvs);
13201313
}
13211314
pvs = newPvs;
@@ -1411,7 +1404,7 @@ protected void autowireByType(
14111404
if (Object.class != pd.getPropertyType()) {
14121405
MethodParameter methodParam = BeanUtils.getWriteMethodParameter(pd);
14131406
// Do not allow eager init for type matching in case of a prioritized post-processor.
1414-
boolean eager = !PriorityOrdered.class.isInstance(bw.getWrappedInstance());
1407+
boolean eager = !(bw.getWrappedInstance() instanceof PriorityOrdered);
14151408
DependencyDescriptor desc = new AutowireByTypeDependencyDescriptor(methodParam, eager);
14161409
Object autowiredArgument = resolveDependency(desc, beanName, autowiredBeanNames, converter);
14171410
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-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.
@@ -793,6 +793,7 @@ public void handleIt(TestEvent event) {
793793

794794
@EventListener
795795
@Async
796+
@Override
796797
public void handleAsync(AnotherTestEvent event) {
797798
assertTrue(!Thread.currentThread().getName().equals(event.content));
798799
this.eventCollector.addEvent(this, event);
@@ -819,6 +820,7 @@ public void handleIt(TestEvent event) {
819820

820821
@EventListener
821822
@Async
823+
@Override
822824
public void handleAsync(AnotherTestEvent event) {
823825
assertTrue(!Thread.currentThread().getName().equals(event.content));
824826
this.eventCollector.addEvent(this, event);
@@ -901,7 +903,6 @@ public void handleString(GenericEventPojo<String> value) {
901903
}
902904

903905

904-
905906
@EventListener
906907
@Retention(RetentionPolicy.RUNTIME)
907908
public @interface ConditionalEvent {
@@ -933,18 +934,20 @@ public void handle(TestEvent event) {
933934
super.handle(event);
934935
}
935936

936-
@Override
937937
@EventListener(condition = "#payload.startsWith('OK')")
938+
@Override
938939
public void handleString(String payload) {
939940
super.handleString(payload);
940941
}
941942

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

947949
@ConditionalEvent("@conditionEvaluator.valid(#p0)")
950+
@Override
948951
public void handleRatio(Double ratio) {
949952
collectEvent(ratio);
950953
}

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: 7 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.
@@ -40,9 +40,11 @@
4040
import org.springframework.web.util.JavaScriptUtils;
4141

4242
/**
43-
* An HTTP {@link TransportHandler} that uses a famous browser document.domain technique:
44-
* <a href="https://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do">
45-
* https://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do</a>
43+
* An HTTP {@link TransportHandler} that uses a famous browser
44+
* {@code document.domain technique}. See <a href=
45+
* "https://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do">
46+
* stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do</a>
47+
* for details.
4648
*
4749
* @author Rossen Stoyanchev
4850
* @since 4.0
@@ -91,7 +93,7 @@ protected MediaType getContentType() {
9193

9294
@Override
9395
public boolean checkSessionType(SockJsSession session) {
94-
return session instanceof HtmlFileStreamingSockJsSession;
96+
return (session instanceof HtmlFileStreamingSockJsSession);
9597
}
9698

9799
@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.
@@ -106,7 +106,7 @@ public boolean isRunning() {
106106

107107
@Override
108108
public boolean checkSessionType(SockJsSession session) {
109-
return session instanceof WebSocketServerSockJsSession;
109+
return (session instanceof WebSocketServerSockJsSession);
110110
}
111111

112112
@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)