From e1f950764ea3bce108c6984a3ad8766cdaece6b6 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Nov 2019 18:11:44 +0100 Subject: [PATCH] Minor internal refinements (backported from master) --- .../AbstractAutowireCapableBeanFactory.java | 23 +++++----------- ...ReloadableResourceBundleMessageSource.java | 26 ++++++++++++++----- .../AnnotationDrivenEventListenerTests.java | 9 ++++--- .../handler/EventSourceTransportHandler.java | 11 ++++---- .../handler/HtmlFileTransportHandler.java | 13 +++++----- .../handler/WebSocketTransportHandler.java | 4 +-- .../handler/XhrPollingTransportHandler.java | 5 ++-- .../handler/XhrStreamingTransportHandler.java | 5 ++-- 8 files changed, 49 insertions(+), 47 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index 4804e64536..b7e3e62f11 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -605,7 +605,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac @Override protected Class predictBeanType(String beanName, RootBeanDefinition mbd, Class... typesToMatch) { Class targetType = determineTargetType(beanName, mbd, typesToMatch); - // Apply SmartInstantiationAwareBeanPostProcessors to predict the // eventual type after a before-instantiation shortcut. if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { @@ -1221,43 +1220,33 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac // Give any InstantiationAwareBeanPostProcessors the opportunity to modify the // state of the bean before properties are set. This can be used, for example, // to support styles of field injection. - boolean continueWithPropertyPopulation = true; - if (!mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) { for (BeanPostProcessor bp : getBeanPostProcessors()) { if (bp instanceof InstantiationAwareBeanPostProcessor) { InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp; if (!ibp.postProcessAfterInstantiation(bw.getWrappedInstance(), beanName)) { - continueWithPropertyPopulation = false; - break; + return; } } } } - if (!continueWithPropertyPopulation) { - return; - } - - if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME || - mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) { + int resolvedAutowireMode = mbd.getResolvedAutowireMode(); + if (resolvedAutowireMode == AUTOWIRE_BY_NAME || resolvedAutowireMode == AUTOWIRE_BY_TYPE) { MutablePropertyValues newPvs = new MutablePropertyValues(pvs); - // Add property values based on autowire by name if applicable. - if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME) { + if (resolvedAutowireMode == AUTOWIRE_BY_NAME) { autowireByName(beanName, mbd, bw, newPvs); } - // Add property values based on autowire by type if applicable. - if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) { + if (resolvedAutowireMode == AUTOWIRE_BY_TYPE) { autowireByType(beanName, mbd, bw, newPvs); } - pvs = newPvs; } boolean hasInstAwareBpps = hasInstantiationAwareBeanPostProcessors(); - boolean needsDepCheck = (mbd.getDependencyCheck() != RootBeanDefinition.DEPENDENCY_CHECK_NONE); + boolean needsDepCheck = (mbd.getDependencyCheck() != AbstractBeanDefinition.DEPENDENCY_CHECK_NONE); if (hasInstAwareBpps || needsDepCheck) { PropertyDescriptor[] filteredPds = filterPropertyDescriptorsForDependencyCheck(bw, mbd.allowCaching); diff --git a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java index 941ad46e63..a2984eb3e2 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -237,6 +237,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased if (mergedHolder != null) { return mergedHolder; } + Properties mergedProps = newProperties(); long latestTimestamp = -1; String[] basenames = StringUtils.toStringArray(getBasenameSet()); @@ -253,6 +254,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased } } } + mergedHolder = new PropertiesHolder(mergedProps, latestTimestamp); PropertiesHolder existing = this.cachedMergedProperties.putIfAbsent(locale, mergedHolder); if (existing != null) { @@ -279,18 +281,28 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased return filenames; } } + + // Filenames for given Locale List filenames = new ArrayList(7); filenames.addAll(calculateFilenamesForLocale(basename, locale)); - if (isFallbackToSystemLocale() && !locale.equals(Locale.getDefault())) { - List fallbackFilenames = calculateFilenamesForLocale(basename, Locale.getDefault()); - for (String fallbackFilename : fallbackFilenames) { - if (!filenames.contains(fallbackFilename)) { - // Entry for fallback locale that isn't already in filenames list. - filenames.add(fallbackFilename); + + // Filenames for default Locale, if any + if (isFallbackToSystemLocale()) { + Locale defaultLocale = Locale.getDefault(); + if (!locale.equals(defaultLocale)) { + List fallbackFilenames = calculateFilenamesForLocale(basename, defaultLocale); + for (String fallbackFilename : fallbackFilenames) { + if (!filenames.contains(fallbackFilename)) { + // Entry for fallback locale that isn't already in filenames list. + filenames.add(fallbackFilename); + } } } } + + // Filename for default bundle file filenames.add(basename); + if (localeMap == null) { localeMap = new ConcurrentHashMap>(); Map> existing = this.cachedFilenames.putIfAbsent(basename, localeMap); diff --git a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java index b3beb177c4..462fe795e2 100644 --- a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -782,6 +782,7 @@ public class AnnotationDrivenEventListenerTests { @EventListener @Async + @Override public void handleAsync(AnotherTestEvent event) { assertTrue(!Thread.currentThread().getName().equals(event.content)); this.eventCollector.addEvent(this, event); @@ -808,6 +809,7 @@ public class AnnotationDrivenEventListenerTests { @EventListener @Async + @Override public void handleAsync(AnotherTestEvent event) { assertTrue(!Thread.currentThread().getName().equals(event.content)); this.eventCollector.addEvent(this, event); @@ -890,7 +892,6 @@ public class AnnotationDrivenEventListenerTests { } - @EventListener @Retention(RetentionPolicy.RUNTIME) public @interface ConditionalEvent { @@ -922,18 +923,20 @@ public class AnnotationDrivenEventListenerTests { super.handle(event); } - @Override @EventListener(condition = "#payload.startsWith('OK')") + @Override public void handleString(String payload) { super.handleString(payload); } @ConditionalEvent("#root.event.timestamp > #p0") + @Override public void handleTimestamp(Long timestamp) { collectEvent(timestamp); } @ConditionalEvent("@conditionEvaluator.valid(#p0)") + @Override public void handleRatio(Double ratio) { collectEvent(ratio); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/EventSourceTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/EventSourceTransportHandler.java index f79f122d09..b8cff7dde8 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/EventSourceTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/EventSourceTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,11 +26,10 @@ import org.springframework.web.socket.sockjs.frame.SockJsFrameFormat; import org.springframework.web.socket.sockjs.transport.SockJsServiceConfig; import org.springframework.web.socket.sockjs.transport.SockJsSession; import org.springframework.web.socket.sockjs.transport.TransportType; -import org.springframework.web.socket.sockjs.transport.session.PollingSockJsSession; import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSession; /** - * A TransportHandler for sending messages via Server-Sent events: + * A TransportHandler for sending messages via Server-Sent Events: * https://dev.w3.org/html5/eventsource/. * * @author Rossen Stoyanchev @@ -50,7 +49,7 @@ public class EventSourceTransportHandler extends AbstractHttpSendingTransportHan @Override public boolean checkSessionType(SockJsSession session) { - return session instanceof EventSourceStreamingSockJsSession; + return (session instanceof EventSourceStreamingSockJsSession); } @Override @@ -66,7 +65,7 @@ public class EventSourceTransportHandler extends AbstractHttpSendingTransportHan } - private class EventSourceStreamingSockJsSession extends StreamingSockJsSession { + private static class EventSourceStreamingSockJsSession extends StreamingSockJsSession { public EventSourceStreamingSockJsSession(String sessionId, SockJsServiceConfig config, WebSocketHandler wsHandler, Map attributes) { @@ -76,7 +75,7 @@ public class EventSourceTransportHandler extends AbstractHttpSendingTransportHan @Override protected byte[] getPrelude(ServerHttpRequest request) { - return new byte[] { '\r', '\n' }; + return new byte[] {'\r', '\n'}; } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java index c03cc9c7f4..9bf51361a2 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,14 +35,15 @@ import org.springframework.web.socket.sockjs.transport.SockJsSession; import org.springframework.web.socket.sockjs.transport.TransportHandler; import org.springframework.web.socket.sockjs.transport.TransportType; import org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession; -import org.springframework.web.socket.sockjs.transport.session.PollingSockJsSession; import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSession; import org.springframework.web.util.JavaScriptUtils; /** - * An HTTP {@link TransportHandler} that uses a famous browser document.domain technique: - * - * https://stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do + * An HTTP {@link TransportHandler} that uses a famous browser + * {@code document.domain technique}. See + * stackoverflow.com/questions/1481251/what-does-document-domain-document-domain-do + * for details. * * @author Rossen Stoyanchev * @since 4.0 @@ -91,7 +92,7 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle @Override public boolean checkSessionType(SockJsSession session) { - return session instanceof HtmlFileStreamingSockJsSession; + return (session instanceof HtmlFileStreamingSockJsSession); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java index 66cf79e01b..22ccdb536f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/WebSocketTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -106,7 +106,7 @@ public class WebSocketTransportHandler extends AbstractTransportHandler @Override public boolean checkSessionType(SockJsSession session) { - return session instanceof WebSocketServerSockJsSession; + return (session instanceof WebSocketServerSockJsSession); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrPollingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrPollingTransportHandler.java index 8c8cee4e4c..c89f563157 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrPollingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrPollingTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ import org.springframework.web.socket.sockjs.frame.SockJsFrameFormat; import org.springframework.web.socket.sockjs.transport.SockJsSession; import org.springframework.web.socket.sockjs.transport.TransportHandler; import org.springframework.web.socket.sockjs.transport.TransportType; -import org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession; import org.springframework.web.socket.sockjs.transport.session.PollingSockJsSession; /** @@ -54,7 +53,7 @@ public class XhrPollingTransportHandler extends AbstractHttpSendingTransportHand @Override public boolean checkSessionType(SockJsSession session) { - return session instanceof PollingSockJsSession; + return (session instanceof PollingSockJsSession); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrStreamingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrStreamingTransportHandler.java index 0ff1bd4b35..fc3704b38d 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrStreamingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/XhrStreamingTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import org.springframework.web.socket.sockjs.transport.SockJsServiceConfig; import org.springframework.web.socket.sockjs.transport.SockJsSession; import org.springframework.web.socket.sockjs.transport.TransportHandler; import org.springframework.web.socket.sockjs.transport.TransportType; -import org.springframework.web.socket.sockjs.transport.session.PollingSockJsSession; import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSession; /** @@ -60,7 +59,7 @@ public class XhrStreamingTransportHandler extends AbstractHttpSendingTransportHa @Override public boolean checkSessionType(SockJsSession session) { - return session instanceof XhrStreamingSockJsSession; + return (session instanceof XhrStreamingSockJsSession); } @Override