From fc64b8040f7c76f2bc85387cf944436424ce408c Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 13 Jun 2017 09:38:39 +0200 Subject: [PATCH] Polish "Replace relevant code with lambda" Closes gh-1454 --- .../aop/aspectj/DeclareParentsAdvisor.java | 2 +- .../beans/ExtendedBeanInfo.java | 5 +- .../AutowiredAnnotationBeanPostProcessor.java | 70 ++++++++--------- ...nitDestroyAnnotationBeanPostProcessor.java | 2 +- .../jcache/interceptor/JCacheInterceptor.java | 2 +- .../AnnotationCacheOperationSource.java | 2 +- .../cache/interceptor/CacheInterceptor.java | 2 +- .../CommonAnnotationBeanPostProcessor.java | 2 +- .../ConfigurationClassPostProcessor.java | 4 +- .../springframework/util/ReflectionUtils.java | 13 ++-- .../CompletableToListenableFutureAdapter.java | 9 +-- .../expression/spel/ast/InlineList.java | 10 +-- .../support/ReflectiveMethodResolver.java | 4 +- .../config/SortedResourcesFactoryBean.java | 3 +- .../support/JdbcBeanDefinitionReader.java | 11 +-- .../stomp/StompBrokerRelayMessageHandler.java | 23 +++--- .../jpa/AbstractEntityManagerFactoryBean.java | 4 +- .../client/match/MockRestRequestMatchers.java | 27 +++---- .../ResourceAdapterApplicationContext.java | 5 +- .../interceptor/TransactionAspectSupport.java | 13 ++-- .../org/springframework/http/MediaType.java | 75 ++++++++++--------- .../request/async/WebAsyncManager.java | 19 ++--- .../ExceptionHandlerMethodResolver.java | 4 +- .../RequestMappingHandlerAdapter.java | 28 +++---- .../client/jetty/JettyWebSocketClient.java | 2 +- .../AnnotatedEndpointConnectionManager.java | 2 +- .../standard/EndpointConnectionManager.java | 2 +- .../config/WebSocketMessageBrokerStats.java | 8 +- .../messaging/WebSocketStompClient.java | 22 +++--- 29 files changed, 186 insertions(+), 189 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java index ecc9b860da..988cadd0dc 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. diff --git a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java index 49b856d01f..c3ebd465e2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java +++ b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -28,7 +28,6 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Set; @@ -139,7 +138,7 @@ class ExtendedBeanInfo implements BeanInfo { // Sort non-void returning write methods to guard against the ill effects of // non-deterministic sorting of methods returned from Class#getDeclaredMethods // under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180 - Collections.sort(matches, (m1, m2) -> m2.toString().compareTo(m1.toString())); + matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString())); return matches; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 9074241201..77c18c1079 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -412,43 +412,43 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean final LinkedList currElements = new LinkedList<>(); ReflectionUtils.doWithLocalFields(targetClass, field -> { - AnnotationAttributes ann = findAutowiredAnnotation(field); - if (ann != null) { - if (Modifier.isStatic(field.getModifiers())) { - if (logger.isWarnEnabled()) { - logger.warn("Autowired annotation is not supported on static fields: " + field); - } - return; - } - boolean required = determineRequiredStatus(ann); - currElements.add(new AutowiredFieldElement(field, required)); - } - }); + AnnotationAttributes ann = findAutowiredAnnotation(field); + if (ann != null) { + if (Modifier.isStatic(field.getModifiers())) { + if (logger.isWarnEnabled()) { + logger.warn("Autowired annotation is not supported on static fields: " + field); + } + return; + } + boolean required = determineRequiredStatus(ann); + currElements.add(new AutowiredFieldElement(field, required)); + } + }); ReflectionUtils.doWithLocalMethods(targetClass, method -> { - Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); - if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) { - return; - } - AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod); - if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { - if (Modifier.isStatic(method.getModifiers())) { - if (logger.isWarnEnabled()) { - logger.warn("Autowired annotation is not supported on static methods: " + method); - } - return; - } - if (method.getParameterCount() == 0) { - if (logger.isWarnEnabled()) { - logger.warn("Autowired annotation should only be used on methods with parameters: " + - method); - } - } - boolean required = determineRequiredStatus(ann); - PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz); - currElements.add(new AutowiredMethodElement(method, required, pd)); - } - }); + Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); + if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) { + return; + } + AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod); + if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { + if (Modifier.isStatic(method.getModifiers())) { + if (logger.isWarnEnabled()) { + logger.warn("Autowired annotation is not supported on static methods: " + method); + } + return; + } + if (method.getParameterCount() == 0) { + if (logger.isWarnEnabled()) { + logger.warn("Autowired annotation should only be used on methods with parameters: " + + method); + } + } + boolean required = determineRequiredStatus(ann); + PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz); + currElements.add(new AutowiredMethodElement(method, required, pd)); + } + }); elements.addAll(0, currElements); targetClass = targetClass.getSuperclass(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java index a85bd1f51c..d937cdfcdc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java index a39426bea6..f478f10e97 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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. diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java index b666822df6..c6fdeaa2af 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java index f2f4521c8e..ab5878293b 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. diff --git a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java index 6c35d21f7d..2efcefaf80 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java @@ -363,7 +363,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean throw new IllegalStateException("@EJB annotation is not supported on static fields"); } currElements.add(new EjbRefElement(field, field, null)); - } + } else if (field.isAnnotationPresent(Resource.class)) { if (Modifier.isStatic(field.getModifiers())) { throw new IllegalStateException("@Resource annotation is not supported on static fields"); diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java index ef5f8ea50c..7093daad98 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java @@ -19,8 +19,6 @@ package org.springframework.context.annotation; import java.beans.PropertyDescriptor; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -280,7 +278,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo } // Sort by previously determined @Order value, if applicable - Collections.sort(configCandidates, (bd1, bd2) -> { + configCandidates.sort((bd1, bd2) -> { int i1 = ConfigurationClassUtils.getOrder(bd1.getBeanDefinition()); int i2 = ConfigurationClassUtils.getOrder(bd2.getBeanDefinition()); return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0; diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java index df768f27c5..73702b67ce 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -47,12 +47,6 @@ import org.springframework.lang.Nullable; */ public abstract class ReflectionUtils { - /** - * Pre-built FieldFilter that matches all non-static, non-final fields. - */ - public static final FieldFilter COPYABLE_FIELDS = - field -> !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())); - /** * Naming prefix for CGLIB-renamed methods. * @see #isCglibRenamedMethod @@ -851,6 +845,13 @@ public abstract class ReflectionUtils { } + /** + * Pre-built FieldFilter that matches all non-static, non-final fields. + */ + public static final FieldFilter COPYABLE_FIELDS = + field -> !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())); + + /** * Pre-built MethodFilter that matches all non-bridge methods. */ diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java b/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java index 36698066cc..44f753db14 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java @@ -21,9 +21,6 @@ import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.function.BiFunction; - -import org.springframework.lang.Nullable; /** * Adapts a {@link CompletableFuture} or {@link CompletionStage} into a @@ -53,9 +50,9 @@ public class CompletableToListenableFutureAdapter implements ListenableFuture */ public CompletableToListenableFutureAdapter(CompletableFuture completableFuture) { this.completableFuture = completableFuture; - this.completableFuture.handle((result, exception) -> { - if (exception != null) { - callbacks.failure(exception); + this.completableFuture.handle((result, ex) -> { + if (ex != null) { + callbacks.failure(ex); } else { callbacks.success(result); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java index f6a348ead2..26a43c5d38 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.springframework.asm.ClassWriter; import org.springframework.asm.MethodVisitor; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; @@ -137,10 +136,11 @@ public class InlineList extends SpelNodeImpl { final String constantFieldName = "inlineList$" + codeflow.nextFieldId(); final String className = codeflow.getClassName(); - codeflow.registerNewField((cw, codeflow1) - -> cw.visitField(ACC_PRIVATE|ACC_STATIC|ACC_FINAL, constantFieldName, "Ljava/util/List;", null, null)); - - codeflow.registerNewClinit((mv1, codeflow12) -> generateClinitCode(className, constantFieldName, mv1, codeflow12, false)); + codeflow.registerNewField((cw, cflow) -> + cw.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, constantFieldName, "Ljava/util/List;", null, null)); + + codeflow.registerNewClinit((mVisitor, cflow) -> + generateClinitCode(className, constantFieldName, mVisitor, cflow, false)); mv.visitFieldInsn(GETSTATIC, className, constantFieldName, "Ljava/util/List;"); codeflow.pushDescriptor("Ljava/util/List"); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java index 959141dd62..ba36b884b0 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java @@ -21,8 +21,6 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; @@ -121,7 +119,7 @@ public class ReflectiveMethodResolver implements MethodResolver { // Sort methods into a sensible order if (methods.size() > 1) { - Collections.sort(methods, (m1, m2) -> { + methods.sort((m1, m2) -> { int m1pl = m1.getParameterCount(); int m2pl = m2.getParameterCount(); // varargs methods go last diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java b/spring-jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java index b944973efa..b5fe9f1243 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -20,7 +20,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Comparator; import java.util.List; import org.springframework.beans.factory.FactoryBean; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java index 9427264111..a1f72bdb74 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java @@ -16,15 +16,12 @@ package org.springframework.jdbc.core.support; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.Properties; import javax.sql.DataSource; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.util.Assert; /** @@ -105,10 +102,10 @@ public class JdbcBeanDefinitionReader { public void loadBeanDefinitions(String sql) { Assert.notNull(this.jdbcTemplate, "Not fully configured - specify DataSource or JdbcTemplate"); final Properties props = new Properties(); - this.jdbcTemplate.query(sql, resultSet -> { - String beanName = resultSet.getString(1); - String property = resultSet.getString(2); - String value = resultSet.getString(3); + this.jdbcTemplate.query(sql, rs -> { + String beanName = rs.getString(1); + String property = rs.getString(2); + String value = rs.getString(3); // Make a properties entry by combining bean name and property. props.setProperty(beanName + '.' + property, value); }); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java index d45eff9eb6..d9bd5c7a66 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java @@ -586,9 +586,9 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler } this.tcpConnection = connection; this.tcpConnection.onReadInactivity(() -> { - if (tcpConnection != null && !isStompConnected) { + if (this.tcpConnection != null && !this.isStompConnected) { handleTcpConnectionFailure("No CONNECTED frame received in " + - MAX_TIME_TO_CONNECTED_FRAME + " ms.", null); + MAX_TIME_TO_CONNECTED_FRAME + " ms.", null); } }, MAX_TIME_TO_CONNECTED_FRAME); connection.send(MessageBuilder.createMessage(EMPTY_PAYLOAD, this.connectHeaders.getMessageHeaders())); @@ -697,18 +697,19 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler long serverReceiveInterval = connectedHeaders.getHeartbeat()[1]; if (clientSendInterval > 0 && serverReceiveInterval > 0) { - long interval = Math.max(clientSendInterval, serverReceiveInterval); + long interval = Math.max(clientSendInterval, serverReceiveInterval); this.tcpConnection.onWriteInactivity(() -> { - TcpConnection conn = tcpConnection; + TcpConnection conn = this.tcpConnection; if (conn != null) { conn.send(HEARTBEAT_MESSAGE).addCallback( - new ListenableFutureCallback() { - public void onSuccess(Void result) { - } - public void onFailure(Throwable ex) { - handleTcpConnectionFailure("Failed to forward heartbeat: " + ex.getMessage(), ex); - } - }); + new ListenableFutureCallback() { + public void onSuccess(Void result) { + } + + public void onFailure(Throwable ex) { + handleTcpConnectionFailure("Failed to forward heartbeat: " + ex.getMessage(), ex); + } + }); } }, interval); } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java index a9980db046..dc5bf08f15 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java @@ -30,7 +30,6 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Properties; import java.util.Set; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import javax.persistence.EntityManager; @@ -350,7 +349,8 @@ public abstract class AbstractEntityManagerFactoryBean implements } if (this.bootstrapExecutor != null) { - this.nativeEntityManagerFactoryFuture = this.bootstrapExecutor.submit(this::buildNativeEntityManagerFactory); + this.nativeEntityManagerFactoryFuture = this.bootstrapExecutor.submit( + this::buildNativeEntityManagerFactory); } else { this.nativeEntityManagerFactory = buildNativeEntityManagerFactory(); diff --git a/spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java b/spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java index c34c3e0fe5..48ff16d7e3 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -25,7 +25,6 @@ import org.hamcrest.Matcher; import org.springframework.http.HttpMethod; import org.springframework.http.client.ClientHttpRequest; -import org.springframework.test.util.AssertionErrors; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.test.web.client.RequestMatcher; import org.springframework.util.Assert; @@ -145,11 +144,12 @@ public abstract class MockRestRequestMatchers { */ @SafeVarargs public static RequestMatcher header(final String name, final Matcher... matchers) { - return request-> { - assertValueCount("header", name, request.getHeaders(), matchers.length); - List headerValues = request.getHeaders().get(name); - Assert.state(headerValues != null, "No header values");for (int i = 0 ; i < matchers.length; i++) { - assertThat("Request header["+name+ "]", headerValues.get(i), matchers[i]); + return request -> { + assertValueCount("header", name, request.getHeaders(), matchers.length); + List headerValues = request.getHeaders().get(name); + Assert.state(headerValues != null, "No header values"); + for (int i = 0; i < matchers.length; i++) { + assertThat("Request header[" + name + "]", headerValues.get(i), matchers[i]); } }; @@ -159,12 +159,13 @@ public abstract class MockRestRequestMatchers { * Assert request header values. */ public static RequestMatcher header(final String name, final String... expectedValues) { - return request-> { - assertValueCount("header", name, request.getHeaders(), expectedValues.length); - List headerValues = request.getHeaders().get(name); - Assert.state(headerValues != null, "No header values");for (int i = 0 ; i < expectedValues.length; i++) { - assertEquals("Request header [" + name + "]", - expectedValues[i], headerValues.get(i)); + return request -> { + assertValueCount("header", name, request.getHeaders(), expectedValues.length); + List headerValues = request.getHeaders().get(name); + Assert.state(headerValues != null, "No header values"); + for (int i = 0; i < expectedValues.length; i++) { + assertEquals("Request header [" + name + "]", + expectedValues[i], headerValues.get(i)); } }; diff --git a/spring-tx/src/main/java/org/springframework/jca/context/ResourceAdapterApplicationContext.java b/spring-tx/src/main/java/org/springframework/jca/context/ResourceAdapterApplicationContext.java index 1f6989ec04..0ee5694ac2 100644 --- a/spring-tx/src/main/java/org/springframework/jca/context/ResourceAdapterApplicationContext.java +++ b/spring-tx/src/main/java/org/springframework/jca/context/ResourceAdapterApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -59,7 +59,8 @@ public class ResourceAdapterApplicationContext extends GenericApplicationContext beanFactory.registerResolvableDependency(BootstrapContext.class, this.bootstrapContext); // JCA WorkManager resolved lazily - may not be available. - beanFactory.registerResolvableDependency(WorkManager.class, (ObjectFactory) bootstrapContext::getWorkManager); + beanFactory.registerResolvableDependency(WorkManager.class, + (ObjectFactory) this.bootstrapContext::getWorkManager); } } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java index dea0203310..3bf1e39bf0 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java @@ -34,7 +34,6 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionSystemException; import org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager; -import org.springframework.transaction.support.TransactionCallback; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; @@ -307,19 +306,23 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init TransactionInfo txInfo = prepareTransactionInfo(tm, txAttr, joinpointIdentification, status); try { return invocation.proceedWithInvocation(); - } catch (Throwable ex) { + } + catch (Throwable ex) { if (txAttr.rollbackOn(ex)) { // A RuntimeException: will lead to a rollback. if (ex instanceof RuntimeException) { throw (RuntimeException) ex; - } else { + } + else { throw new ThrowableHolderException(ex); } - } else { + } + else { // A normal return value: will lead to a commit. return new ThrowableHolder(ex); } - } finally { + } + finally { cleanupTransactionInfo(txInfo); } }); diff --git a/spring-web/src/main/java/org/springframework/http/MediaType.java b/spring-web/src/main/java/org/springframework/http/MediaType.java index 1dd92f6b46..f102c44ce8 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -290,43 +290,6 @@ public class MediaType extends MimeType implements Serializable { */ public final static String APPLICATION_PROBLEM_XML_VALUE = "application/problem+xml"; - /** - * Comparator used by {@link #sortByQualityValue(List)}. - */ - public static final Comparator QUALITY_VALUE_COMPARATOR = (mediaType1, mediaType2) -> { - double quality1 = mediaType1.getQualityValue(); - double quality2 = mediaType2.getQualityValue(); - int qualityComparison = Double.compare(quality2, quality1); - if (qualityComparison != 0) { - return qualityComparison; // audio/*;q=0.7 < audio/*;q=0.3 - } - else if (mediaType1.isWildcardType() && !mediaType2.isWildcardType()) { // */* < audio/* - return 1; - } - else if (mediaType2.isWildcardType() && !mediaType1.isWildcardType()) { // audio/* > */* - return -1; - } - else if (!mediaType1.getType().equals(mediaType2.getType())) { // audio/basic == text/html - return 0; - } - else { // mediaType1.getType().equals(mediaType2.getType()) - if (mediaType1.isWildcardSubtype() && !mediaType2.isWildcardSubtype()) { // audio/* < audio/basic - return 1; - } - else if (mediaType2.isWildcardSubtype() && !mediaType1.isWildcardSubtype()) { // audio/basic > audio/* - return -1; - } - else if (!mediaType1.getSubtype().equals(mediaType2.getSubtype())) { // audio/basic == audio/wave - return 0; - } - else { - int paramsSize1 = mediaType1.getParameters().size(); - int paramsSize2 = mediaType2.getParameters().size(); - return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); // audio/basic;level=1 < audio/basic - } - } - }; - private static final String PARAM_QUALITY_FACTOR = "q"; @@ -687,6 +650,44 @@ public class MediaType extends MimeType implements Serializable { } + /** + * Comparator used by {@link #sortByQualityValue(List)}. + */ + public static final Comparator QUALITY_VALUE_COMPARATOR = (mediaType1, mediaType2) -> { + double quality1 = mediaType1.getQualityValue(); + double quality2 = mediaType2.getQualityValue(); + int qualityComparison = Double.compare(quality2, quality1); + if (qualityComparison != 0) { + return qualityComparison; // audio/*;q=0.7 < audio/*;q=0.3 + } + else if (mediaType1.isWildcardType() && !mediaType2.isWildcardType()) { // */* < audio/* + return 1; + } + else if (mediaType2.isWildcardType() && !mediaType1.isWildcardType()) { // audio/* > */* + return -1; + } + else if (!mediaType1.getType().equals(mediaType2.getType())) { // audio/basic == text/html + return 0; + } + else { // mediaType1.getType().equals(mediaType2.getType()) + if (mediaType1.isWildcardSubtype() && !mediaType2.isWildcardSubtype()) { // audio/* < audio/basic + return 1; + } + else if (mediaType2.isWildcardSubtype() && !mediaType1.isWildcardSubtype()) { // audio/basic > audio/* + return -1; + } + else if (!mediaType1.getSubtype().equals(mediaType2.getSubtype())) { // audio/basic == audio/wave + return 0; + } + else { + int paramsSize1 = mediaType1.getParameters().size(); + int paramsSize2 = mediaType2.getParameters().size(); + return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); // audio/basic;level=1 < audio/basic + } + } + }; + + /** * Comparator used by {@link #sortBySpecificity(List)}. */ diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java index a248ba2ed5..4cbb6f515d 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncManager.java @@ -107,8 +107,8 @@ public final class WebAsyncManager { public void setAsyncWebRequest(final AsyncWebRequest asyncWebRequest) { Assert.notNull(asyncWebRequest, "AsyncWebRequest must not be null"); this.asyncWebRequest = asyncWebRequest; - this.asyncWebRequest.addCompletionHandler(() - -> asyncWebRequest.removeAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST)); + this.asyncWebRequest.addCompletionHandler(() -> asyncWebRequest.removeAttribute( + WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST)); } /** @@ -287,13 +287,14 @@ public final class WebAsyncManager { this.asyncWebRequest.addTimeoutHandler(() -> { logger.debug("Processing timeout"); - Object result = interceptorChain.triggerAfterTimeout(asyncWebRequest, callable); + Object result = interceptorChain.triggerAfterTimeout(this.asyncWebRequest, callable); if (result != CallableProcessingInterceptor.RESULT_NONE) { setConcurrentResultAndDispatch(result); } }); - this.asyncWebRequest.addCompletionHandler(() -> interceptorChain.triggerAfterCompletion(asyncWebRequest, callable)); + this.asyncWebRequest.addCompletionHandler(() -> + interceptorChain.triggerAfterCompletion(this.asyncWebRequest, callable)); interceptorChain.applyBeforeConcurrentHandling(this.asyncWebRequest, callable); startAsyncProcessing(processingContext); @@ -301,14 +302,14 @@ public final class WebAsyncManager { this.taskExecutor.submit(() -> { Object result = null; try { - interceptorChain.applyPreProcess(asyncWebRequest, callable); + interceptorChain.applyPreProcess(this.asyncWebRequest, callable); result = callable.call(); } catch (Throwable ex) { result = ex; } finally { - result = interceptorChain.applyPostProcess(asyncWebRequest, callable, result); + result = interceptorChain.applyPostProcess(this.asyncWebRequest, callable, result); } setConcurrentResultAndDispatch(result); }); @@ -375,7 +376,7 @@ public final class WebAsyncManager { this.asyncWebRequest.addTimeoutHandler(() -> { try { - interceptorChain.triggerAfterTimeout(asyncWebRequest, deferredResult); + interceptorChain.triggerAfterTimeout(this.asyncWebRequest, deferredResult); } catch (Throwable ex) { setConcurrentResultAndDispatch(ex); @@ -383,7 +384,7 @@ public final class WebAsyncManager { }); this.asyncWebRequest.addCompletionHandler(() - -> interceptorChain.triggerAfterCompletion(asyncWebRequest, deferredResult)); + -> interceptorChain.triggerAfterCompletion(this.asyncWebRequest, deferredResult)); interceptorChain.applyBeforeConcurrentHandling(this.asyncWebRequest, deferredResult); startAsyncProcessing(processingContext); @@ -391,7 +392,7 @@ public final class WebAsyncManager { try { interceptorChain.applyPreProcess(this.asyncWebRequest, deferredResult); deferredResult.setResultHandler(result -> { - result = interceptorChain.applyPostProcess(asyncWebRequest, deferredResult, result); + result = interceptorChain.applyPostProcess(this.asyncWebRequest, deferredResult, result); setConcurrentResultAndDispatch(result); }); } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java index 995e17e5e1..569602bbb9 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java @@ -47,8 +47,8 @@ public class ExceptionHandlerMethodResolver { /** * A filter for selecting {@code @ExceptionHandler} methods. */ - public static final MethodFilter EXCEPTION_HANDLER_METHODS = - method -> (AnnotationUtils.findAnnotation(method, ExceptionHandler.class) != null); + public static final MethodFilter EXCEPTION_HANDLER_METHODS = method -> + (AnnotationUtils.findAnnotation(method, ExceptionHandler.class) != null); /** * Arbitrary {@link Method} reference, indicating no method found in the cache. diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java index 0ccd31c5b8..7e28f12f91 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; @@ -117,19 +116,6 @@ import org.springframework.web.util.WebUtils; public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware, InitializingBean { - /** - * MethodFilter that matches {@link InitBinder @InitBinder} methods. - */ - public static final MethodFilter INIT_BINDER_METHODS = - method -> AnnotationUtils.findAnnotation(method, InitBinder.class) != null; - - /** - * MethodFilter that matches {@link ModelAttribute @ModelAttribute} methods. - */ - public static final MethodFilter MODEL_ATTRIBUTE_METHODS = - method -> ((AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) - && (AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null)); - private List customArgumentResolvers; private HandlerMethodArgumentResolverComposite argumentResolvers; @@ -994,4 +980,18 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter return mav; } + + /** + * MethodFilter that matches {@link InitBinder @InitBinder} methods. + */ + public static final MethodFilter INIT_BINDER_METHODS = method -> + AnnotationUtils.findAnnotation(method, InitBinder.class) != null; + + /** + * MethodFilter that matches {@link ModelAttribute @ModelAttribute} methods. + */ + public static final MethodFilter MODEL_ATTRIBUTE_METHODS = method -> + ((AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) && + (AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null)); + } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java index e83019fbe0..251c5e35a5 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/AnnotatedEndpointConnectionManager.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/AnnotatedEndpointConnectionManager.java index aaa6d95d67..1307b8236a 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/AnnotatedEndpointConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/AnnotatedEndpointConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/EndpointConnectionManager.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/EndpointConnectionManager.java index 9790d2fcd1..7b09653ac2 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/EndpointConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/EndpointConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java index a135db9744..885b1548af 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 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. @@ -110,9 +110,9 @@ public class WebSocketMessageBrokerStats { @Nullable private ScheduledFuture initLoggingTask(long initialDelay) { if (logger.isInfoEnabled() && this.loggingPeriod > 0) { - return this.sockJsTaskScheduler.scheduleAtFixedRate(() - -> logger.info(WebSocketMessageBrokerStats.this.toString()), - initialDelay, this.loggingPeriod, TimeUnit.MILLISECONDS); + return this.sockJsTaskScheduler.scheduleAtFixedRate(() -> + logger.info(WebSocketMessageBrokerStats.this.toString()), + initialDelay, this.loggingPeriod, TimeUnit.MILLISECONDS); } return null; } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java index 55671bee1b..33d699e452 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java @@ -402,17 +402,17 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif Assert.state(getTaskScheduler() != null, "No TaskScheduler configured"); this.lastReadTime = System.currentTimeMillis(); this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> { - if (System.currentTimeMillis() - lastReadTime > duration) { - try { - runnable.run(); - } - catch (Throwable ex) { - if (logger.isDebugEnabled()) { - logger.debug("ReadInactivityTask failure", ex); - } - } - } - }, duration / 2)); + if (System.currentTimeMillis() - lastReadTime > duration) { + try { + runnable.run(); + } + catch (Throwable ex) { + if (logger.isDebugEnabled()) { + logger.debug("ReadInactivityTask failure", ex); + } + } + } + }, duration / 2)); } @Override