From 5515112f87c123756e206742f92cfba747d08742 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 7 Aug 2018 21:23:43 +0200 Subject: [PATCH] Polishing --- .../aop/config/AopConfigUtils.java | 19 +++++++++---------- .../aop/config/AopNamespaceUtils.java | 17 ++++++++--------- .../core/annotation/AnnotationUtilsTests.java | 17 ++++++----------- .../caucho/HessianServiceExporter.java | 4 ++-- .../SimpleHttpServerJaxWsServiceExporter.java | 11 ++++++----- .../ConcurrentWebSocketSessionDecorator.java | 2 +- 6 files changed, 32 insertions(+), 38 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java b/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java index c227150060..72b5c62653 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AopConfigUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -31,11 +31,10 @@ import org.springframework.util.Assert; /** * Utility class for handling registration of AOP auto-proxy creators. * - *

Only a single auto-proxy creator can be registered yet multiple concrete - * implementations are available. Therefore this class wraps a simple escalation - * protocol, allowing classes to request a particular auto-proxy creator and know - * that class, {@code or a subclass thereof}, will eventually be resident - * in the application context. + *

Only a single auto-proxy creator should be registered yet multiple concrete + * implementations are available. This class provides a simple escalation protocol, + * allowing a caller to request a particular auto-proxy creator and know that creator, + * or a more capable variant thereof, will be registered as a post-processor. * * @author Rob Harrop * @author Juergen Hoeller @@ -54,12 +53,10 @@ public abstract class AopConfigUtils { /** * Stores the auto proxy creator classes in escalation order. */ - private static final List> APC_PRIORITY_LIST = new ArrayList>(); + private static final List> APC_PRIORITY_LIST = new ArrayList>(3); - /** - * Setup the escalation list. - */ static { + // Set up the escalation list... APC_PRIORITY_LIST.add(InfrastructureAdvisorAutoProxyCreator.class); APC_PRIORITY_LIST.add(AspectJAwareAdvisorAutoProxyCreator.class); APC_PRIORITY_LIST.add(AnnotationAwareAspectJAutoProxyCreator.class); @@ -107,6 +104,7 @@ public abstract class AopConfigUtils { private static BeanDefinition registerOrEscalateApcAsRequired(Class cls, BeanDefinitionRegistry registry, Object source) { Assert.notNull(registry, "BeanDefinitionRegistry must not be null"); + if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) { BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME); if (!cls.getName().equals(apcDefinition.getBeanClassName())) { @@ -118,6 +116,7 @@ public abstract class AopConfigUtils { } return null; } + RootBeanDefinition beanDefinition = new RootBeanDefinition(cls); beanDefinition.setSource(source); beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE); diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java b/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java index bf02fb4045..5c8e7ce94e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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,11 +27,11 @@ import org.springframework.beans.factory.xml.ParserContext; * Utility class for handling registration of auto-proxy creators used internally * by the '{@code aop}' namespace tags. * - *

Only a single auto-proxy creator can be registered and multiple tags may wish - * to register different concrete implementations. As such this class delegates to - * {@link AopConfigUtils} which wraps a simple escalation protocol. Therefore classes - * may request a particular auto-proxy creator and know that class, or a subclass - * thereof, will eventually be resident in the application context. + *

Only a single auto-proxy creator should be registered and multiple configuration + * elements may wish to register different concrete implementations. As such this class + * delegates to {@link AopConfigUtils} which provides a simple escalation protocol. + * Callers may request a particular auto-proxy creator and know that creator, + * or a more capable variant thereof, will be registered as a post-processor. * * @author Rob Harrop * @author Juergen Hoeller @@ -94,9 +94,8 @@ public abstract class AopNamespaceUtils { private static void registerComponentIfNecessary(BeanDefinition beanDefinition, ParserContext parserContext) { if (beanDefinition != null) { - BeanComponentDefinition componentDefinition = - new BeanComponentDefinition(beanDefinition, AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME); - parserContext.registerComponent(componentDefinition); + parserContext.registerComponent( + new BeanComponentDefinition(beanDefinition, AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME)); } } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java index 620668bf97..e7cbd72744 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java @@ -144,12 +144,7 @@ public class AnnotationUtilsTests { assertNull(getAnnotation(bridgeMethod, Order.class)); assertNotNull(findAnnotation(bridgeMethod, Order.class)); - // As of OpenJDK 8 b99, invoking getAnnotation() on a bridge method actually finds - // an annotation on its 'bridged' method. This differs from the previous behavior - // of JDK 5 through 7 and from the current behavior of the Eclipse compiler; - // however, we need to ensure that the tests pass in the Gradle build. So we - // comment out the following assertion. - // assertNull(bridgeMethod.getAnnotation(Transactional.class)); + assertNotNull(bridgeMethod.getAnnotation(Transactional.class)); assertNotNull(getAnnotation(bridgeMethod, Transactional.class)); assertNotNull(findAnnotation(bridgeMethod, Transactional.class)); } @@ -285,7 +280,7 @@ public class AnnotationUtilsTests { } @Test - public void findAnnotationDeclaringClassForAllScenarios() throws Exception { + public void findAnnotationDeclaringClassForAllScenarios() { // no class-level annotation assertNull(findAnnotationDeclaringClass(Transactional.class, NonAnnotatedInterface.class)); assertNull(findAnnotationDeclaringClass(Transactional.class, NonAnnotatedClass.class)); @@ -394,7 +389,7 @@ public class AnnotationUtilsTests { } @Test - public void isAnnotationInheritedForAllScenarios() throws Exception { + public void isAnnotationInheritedForAllScenarios() { // no class-level annotation assertFalse(isAnnotationInherited(Transactional.class, NonAnnotatedInterface.class)); assertFalse(isAnnotationInherited(Transactional.class, NonAnnotatedClass.class)); @@ -503,7 +498,7 @@ public class AnnotationUtilsTests { } @Test - public void getDefaultValueFromNonPublicAnnotation() throws Exception { + public void getDefaultValueFromNonPublicAnnotation() { Annotation[] declaredAnnotations = NonPublicAnnotatedClass.class.getDeclaredAnnotations(); assertEquals(1, declaredAnnotations.length); Annotation annotation = declaredAnnotations[0]; @@ -514,7 +509,7 @@ public class AnnotationUtilsTests { } @Test - public void getDefaultValueFromAnnotationType() throws Exception { + public void getDefaultValueFromAnnotationType() { assertEquals(Ordered.LOWEST_PRECEDENCE, getDefaultValue(Order.class, VALUE)); assertEquals(Ordered.LOWEST_PRECEDENCE, getDefaultValue(Order.class)); } @@ -546,7 +541,7 @@ public class AnnotationUtilsTests { } @Test - public void getRepeatableAnnotationsDeclaredOnClassWithAttributeAliases() throws Exception { + public void getRepeatableAnnotationsDeclaredOnClassWithAttributeAliases() { final List expectedLocations = asList("A", "B"); Set annotations = getRepeatableAnnotations(ConfigHierarchyTestCase.class, ContextConfig.class, null); diff --git a/spring-web/src/main/java/org/springframework/remoting/caucho/HessianServiceExporter.java b/spring-web/src/main/java/org/springframework/remoting/caucho/HessianServiceExporter.java index 314aadaaa9..1b55b45136 100644 --- a/spring-web/src/main/java/org/springframework/remoting/caucho/HessianServiceExporter.java +++ b/spring-web/src/main/java/org/springframework/remoting/caucho/HessianServiceExporter.java @@ -63,10 +63,10 @@ public class HessianServiceExporter extends HessianExporter implements HttpReque response.setContentType(CONTENT_TYPE_HESSIAN); try { - invoke(request.getInputStream(), response.getOutputStream()); + invoke(request.getInputStream(), response.getOutputStream()); } catch (Throwable ex) { - throw new NestedServletException("Hessian skeleton invocation failed", ex); + throw new NestedServletException("Hessian skeleton invocation failed", ex); } } diff --git a/spring-web/src/main/java/org/springframework/remoting/jaxws/SimpleHttpServerJaxWsServiceExporter.java b/spring-web/src/main/java/org/springframework/remoting/jaxws/SimpleHttpServerJaxWsServiceExporter.java index 5b5414158f..2ebebf980f 100644 --- a/spring-web/src/main/java/org/springframework/remoting/jaxws/SimpleHttpServerJaxWsServiceExporter.java +++ b/spring-web/src/main/java/org/springframework/remoting/jaxws/SimpleHttpServerJaxWsServiceExporter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -157,11 +157,12 @@ public class SimpleHttpServerJaxWsServiceExporter extends AbstractJaxWsServiceEx if (this.server == null) { InetSocketAddress address = (this.hostname != null ? new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); - this.server = HttpServer.create(address, this.backlog); - if (this.logger.isInfoEnabled()) { - this.logger.info("Starting HttpServer at address " + address); + HttpServer server = HttpServer.create(address, this.backlog); + if (logger.isInfoEnabled()) { + logger.info("Starting HttpServer at address " + address); } - this.server.start(); + server.start(); + this.server = server; this.localServer = true; } super.afterPropertiesSet(); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java b/spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java index 69e946c8b3..b4753918b9 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java @@ -156,7 +156,7 @@ public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorat } finally { this.sendStartTime = 0; - flushLock.unlock(); + this.flushLock.unlock(); } return true; }