From aaf2e8fbe666e3e5f053d355856c0a4aa6cbae64 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 4 Dec 2024 16:41:07 +0100 Subject: [PATCH] Polishing (cherry picked from commit edf7f3cd43514cd27925c14c5425996b79627256) --- .../AbstractSchedulingTaskExecutorTests.java | 14 +++----------- .../jdbc/SqlScriptsTestExecutionListener.java | 6 +++--- .../java/org/springframework/http/MediaType.java | 12 ++++++------ .../function/DefaultAsyncServerResponse.java | 5 +++-- .../DefaultServerResponseBuilderTests.java | 2 +- spring-websocket/spring-websocket.gradle | 6 +++--- .../StandardToWebSocketExtensionAdapter.java | 2 -- .../WebSocketToStandardExtensionAdapter.java | 3 ++- .../web/socket/messaging/WebSocketStompClient.java | 12 ++++++------ .../sockjs/client/DefaultTransportRequest.java | 3 ++- 10 files changed, 29 insertions(+), 36 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java b/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java index 5d817ee9e16..7d2746f90f0 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java @@ -209,18 +209,10 @@ abstract class AbstractSchedulingTaskExecutorTests { CompletableFuture future1 = executor.submitCompletable(new TestTask(this.testName, -1)); CompletableFuture future2 = executor.submitCompletable(new TestTask(this.testName, -1)); shutdownExecutor(); - - try { + assertThatExceptionOfType(TimeoutException.class).isThrownBy(() -> { future1.get(1000, TimeUnit.MILLISECONDS); - } - catch (Exception ex) { - // ignore - } - Awaitility.await() - .atMost(5, TimeUnit.SECONDS) - .pollInterval(10, TimeUnit.MILLISECONDS) - .untilAsserted(() -> assertThatExceptionOfType(TimeoutException.class) - .isThrownBy(() -> future2.get(1000, TimeUnit.MILLISECONDS))); + future2.get(1000, TimeUnit.MILLISECONDS); + }); } @Test diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java index f219bea1f74..d37b21ef5f9 100644 --- a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java @@ -182,10 +182,10 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen @Override public void processAheadOfTime(RuntimeHints runtimeHints, Class testClass, ClassLoader classLoader) { getSqlAnnotationsFor(testClass).forEach(sql -> - registerClasspathResources(getScripts(sql, testClass, null, true), runtimeHints, classLoader)); + registerClasspathResources(getScripts(sql, testClass, null, true), runtimeHints, classLoader)); getSqlMethods(testClass).forEach(testMethod -> - getSqlAnnotationsFor(testMethod).forEach(sql -> - registerClasspathResources(getScripts(sql, testClass, testMethod, false), runtimeHints, classLoader))); + getSqlAnnotationsFor(testMethod).forEach(sql -> + registerClasspathResources(getScripts(sql, testClass, testMethod, false), runtimeHints, classLoader))); } /** 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 f89063d8df0..844996abb7d 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -853,7 +853,7 @@ public class MediaType extends MimeType implements Serializable { *
audio/basic == text/html
*
audio/basic == audio/wave
* @param mediaTypes the list of media types to be sorted - * @deprecated As of 6.0, in favor of {@link MimeTypeUtils#sortBySpecificity(List)} + * @deprecated as of 6.0, in favor of {@link MimeTypeUtils#sortBySpecificity(List)} */ @Deprecated(since = "6.0", forRemoval = true) public static void sortBySpecificity(List mediaTypes) { @@ -882,7 +882,7 @@ public class MediaType extends MimeType implements Serializable { * * @param mediaTypes the list of media types to be sorted * @see #getQualityValue() - * @deprecated As of 6.0, with no direct replacement + * @deprecated as of 6.0, with no direct replacement */ @Deprecated(since = "6.0", forRemoval = true) public static void sortByQualityValue(List mediaTypes) { @@ -895,9 +895,9 @@ public class MediaType extends MimeType implements Serializable { /** * Sorts the given list of {@code MediaType} objects by specificity as the * primary criteria and quality value the secondary. - * @deprecated As of 6.0, in favor of {@link MimeTypeUtils#sortBySpecificity(List)} + * @deprecated as of 6.0, in favor of {@link MimeTypeUtils#sortBySpecificity(List)} */ - @Deprecated(since = "6.0") + @Deprecated(since = "6.0", forRemoval = true) public static void sortBySpecificityAndQuality(List mediaTypes) { Assert.notNull(mediaTypes, "'mediaTypes' must not be null"); if (mediaTypes.size() > 1) { @@ -908,7 +908,7 @@ public class MediaType extends MimeType implements Serializable { /** * Comparator used by {@link #sortByQualityValue(List)}. - * @deprecated As of 6.0, with no direct replacement + * @deprecated as of 6.0, with no direct replacement */ @Deprecated(since = "6.0", forRemoval = true) public static final Comparator QUALITY_VALUE_COMPARATOR = (mediaType1, mediaType2) -> { @@ -948,7 +948,7 @@ public class MediaType extends MimeType implements Serializable { /** * Comparator used by {@link #sortBySpecificity(List)}. - * @deprecated As of 6.0, with no direct replacement + * @deprecated as of 6.0, with no direct replacement */ @Deprecated(since = "6.0", forRemoval = true) @SuppressWarnings("removal") diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultAsyncServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultAsyncServerResponse.java index c026e40d81d..6db059f839a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultAsyncServerResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultAsyncServerResponse.java @@ -67,6 +67,7 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple this.timeout = timeout; } + @Override public ServerResponse block() { try { @@ -114,8 +115,8 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple } } - @Nullable @Override + @Nullable public ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context) throws ServletException, IOException { @@ -169,6 +170,7 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple return result; } + @SuppressWarnings({"rawtypes", "unchecked"}) public static AsyncServerResponse create(Object obj, @Nullable Duration timeout) { Assert.notNull(obj, "Argument to async must not be null"); @@ -192,5 +194,4 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple throw new IllegalArgumentException("Asynchronous type not supported: " + obj.getClass()); } - } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerResponseBuilderTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerResponseBuilderTests.java index 965a8233d14..5832ee575b4 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerResponseBuilderTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/function/DefaultServerResponseBuilderTests.java @@ -54,6 +54,7 @@ class DefaultServerResponseBuilderTests { static final ServerResponse.Context EMPTY_CONTEXT = Collections::emptyList; + @Test @SuppressWarnings("removal") void status() { @@ -75,7 +76,6 @@ class DefaultServerResponseBuilderTests { assertThat(result.cookies().getFirst("foo")).isEqualTo(cookie); } - @Test void ok() { ServerResponse response = ServerResponse.ok().build(); diff --git a/spring-websocket/spring-websocket.gradle b/spring-websocket/spring-websocket.gradle index 72df03b20dd..95c9a3d0ffc 100644 --- a/spring-websocket/spring-websocket.gradle +++ b/spring-websocket/spring-websocket.gradle @@ -16,13 +16,13 @@ dependencies { exclude group: "org.apache.tomcat", module: "tomcat-servlet-api" exclude group: "org.apache.tomcat", module: "tomcat-websocket-api" } - optional("org.eclipse.jetty.ee10:jetty-ee10-webapp") { - exclude group: "jakarta.servlet", module: "jakarta.servlet-api" - } optional("org.eclipse.jetty.ee10.websocket:jetty-ee10-websocket-jakarta-server") optional("org.eclipse.jetty.ee10.websocket:jetty-ee10-websocket-jetty-server") { exclude group: "jakarta.servlet", module: "jakarta.servlet-api" } + optional("org.eclipse.jetty.ee10:jetty-ee10-webapp") { + exclude group: "jakarta.servlet", module: "jakarta.servlet-api" + } optional("org.glassfish.tyrus:tyrus-container-servlet") testImplementation(testFixtures(project(":spring-core"))) testImplementation(testFixtures(project(":spring-web"))) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardToWebSocketExtensionAdapter.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardToWebSocketExtensionAdapter.java index af221926d62..f61d8978e92 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardToWebSocketExtensionAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/StandardToWebSocketExtensionAdapter.java @@ -34,12 +34,10 @@ import org.springframework.web.socket.WebSocketExtension; */ public class StandardToWebSocketExtensionAdapter extends WebSocketExtension { - public StandardToWebSocketExtensionAdapter(Extension extension) { super(extension.getName(), initParameters(extension)); } - private static Map initParameters(Extension extension) { List parameters = extension.getParameters(); Map result = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ROOT); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/WebSocketToStandardExtensionAdapter.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/WebSocketToStandardExtensionAdapter.java index f8334d3ff34..8455b8dd2c4 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/WebSocketToStandardExtensionAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/standard/WebSocketToStandardExtensionAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2024 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. @@ -55,6 +55,7 @@ public class WebSocketToStandardExtensionAdapter implements Extension { } } + @Override public String getName() { return this.name; 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 973376af707..9a519a0b8a8 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 @@ -234,7 +234,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif /** * An overloaded version of - * {@link #connect(String, StompSessionHandler, Object...)} that also + * {@link #connectAsync(String, StompSessionHandler, Object...)} that also * accepts {@link WebSocketHttpHeaders} to use for the WebSocket handshake. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake @@ -254,7 +254,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif /** * An overloaded version of - * {@link #connect(String, StompSessionHandler, Object...)} that also + * {@link #connectAsync(String, StompSessionHandler, Object...)} that also * accepts {@link WebSocketHttpHeaders} to use for the WebSocket handshake. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake @@ -271,7 +271,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif /** * An overloaded version of - * {@link #connect(String, StompSessionHandler, Object...)} that also accepts + * {@link #connectAsync(String, StompSessionHandler, Object...)} that also accepts * {@link WebSocketHttpHeaders} to use for the WebSocket handshake and * {@link StompHeaders} for the STOMP CONNECT frame. * @param url the url to connect to @@ -293,7 +293,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif /** * An overloaded version of - * {@link #connect(String, StompSessionHandler, Object...)} that also accepts + * {@link #connectAsync(String, StompSessionHandler, Object...)} that also accepts * {@link WebSocketHttpHeaders} to use for the WebSocket handshake and * {@link StompHeaders} for the STOMP CONNECT frame. * @param url the url to connect to @@ -314,7 +314,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif /** * An overloaded version of - * {@link #connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)} + * {@link #connectAsync(String, WebSocketHttpHeaders, StompSessionHandler, Object...)} * that accepts a fully prepared {@link java.net.URI}. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake @@ -334,7 +334,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif /** * An overloaded version of - * {@link #connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)} + * {@link #connectAsync(String, WebSocketHttpHeaders, StompSessionHandler, Object...)} * that accepts a fully prepared {@link java.net.URI}. * @param url the url to connect to * @param handshakeHeaders the headers for the WebSocket handshake diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java index b637acbb015..d320ec3fd03 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -278,6 +278,7 @@ class DefaultTransportRequest implements TransportRequest { } } + /** * Updates the given (global) future based success or failure to connect for * the entire SockJS request regardless of which transport actually managed