From 911d1f2dead11945e026cc8aa8da0447f015f255 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 14 Sep 2022 14:59:50 +0200 Subject: [PATCH] Suppress warnings --- .../org/springframework/context/annotation/Gh29105Tests.java | 3 +++ .../java/org/springframework/aot/hint/ReflectionHints.java | 3 ++- .../http/client/support/InterceptingHttpAccessorTests.java | 4 ++-- .../http/server/reactive/AsyncIntegrationTests.java | 1 + .../http/server/reactive/CookieIntegrationTests.java | 1 + .../http/server/reactive/EchoHandlerIntegrationTests.java | 3 ++- .../http/server/reactive/ErrorHandlerIntegrationTests.java | 3 +++ .../http/server/reactive/MultipartIntegrationTests.java | 3 ++- .../http/server/reactive/RandomHandlerIntegrationTests.java | 3 ++- .../server/reactive/ServerHttpRequestIntegrationTests.java | 1 + .../server/reactive/WriteOnlyHandlerIntegrationTests.java | 3 ++- .../http/server/reactive/ZeroCopyIntegrationTests.java | 1 + .../org/springframework/web/client/RestTemplateTests.java | 1 + .../result/SimpleUrlHandlerMappingIntegrationTests.java | 4 ++++ .../result/method/annotation/ContextPathIntegrationTests.java | 4 +++- .../RequestMappingViewResolutionIntegrationTests.java | 3 ++- 16 files changed, 32 insertions(+), 9 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/context/annotation/Gh29105Tests.java b/spring-context/src/test/java/org/springframework/context/annotation/Gh29105Tests.java index e954f5e989f..f93d7a3e35e 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/Gh29105Tests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/Gh29105Tests.java @@ -47,6 +47,8 @@ public class Gh29105Tests { List> orderedTypes = child.getBeanProvider(MyService.class) .orderedStream().map(Object::getClass).collect(Collectors.toList()); assertThat(orderedTypes).containsExactly(CustomService.class, DefaultService.class); + parent.close(); + child.close(); } @@ -78,4 +80,5 @@ public class Gh29105Tests { } } + } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java index 31d06b43eb0..e2e4fb89f09 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java @@ -210,6 +210,7 @@ public class ReflectionHints { * @deprecated in favor of {@link #registerConstructor(Constructor, ExecutableMode)} */ @Deprecated + @SuppressWarnings("deprecation") public ReflectionHints registerConstructor(Constructor constructor, Consumer constructorHint) { return registerType(TypeReference.of(constructor.getDeclaringClass()), typeHint -> typeHint.withConstructor(mapParameters(constructor), constructorHint)); @@ -247,7 +248,7 @@ public class ReflectionHints { * @deprecated in favor of {@link #registerMethod(Method, ExecutableMode)} */ @Deprecated - + @SuppressWarnings("deprecation") public ReflectionHints registerMethod(Method method, Consumer methodHint) { return registerType(TypeReference.of(method.getDeclaringClass()), typeHint -> typeHint.withMethod(method.getName(), mapParameters(method), methodHint)); diff --git a/spring-web/src/test/java/org/springframework/http/client/support/InterceptingHttpAccessorTests.java b/spring-web/src/test/java/org/springframework/http/client/support/InterceptingHttpAccessorTests.java index 407ce43d77a..28095b582ac 100644 --- a/spring-web/src/test/java/org/springframework/http/client/support/InterceptingHttpAccessorTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/support/InterceptingHttpAccessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -30,7 +30,6 @@ import org.springframework.http.client.ClientHttpResponse; import static org.assertj.core.api.Assertions.assertThat; - /** * Tests for {@link InterceptingHttpAccessor}. * @@ -40,6 +39,7 @@ public class InterceptingHttpAccessorTests { @Test public void getInterceptors() { + @SuppressWarnings("resource") TestInterceptingHttpAccessor accessor = new TestInterceptingHttpAccessor(); List interceptors = Arrays.asList( new SecondClientHttpRequestInterceptor(), diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java index e092e94f37f..a7c9e22d830 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/AsyncIntegrationTests.java @@ -52,6 +52,7 @@ class AsyncIntegrationTests extends AbstractHttpHandlerIntegrationTests { startServer(httpServer); URI url = new URI("http://localhost:" + port); + @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange(RequestEntity.get(url).build(), String.class); assertThat(response.getBody()).isEqualTo("hello"); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java index 432a0ce6e5b..13b29e63d2e 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/CookieIntegrationTests.java @@ -53,6 +53,7 @@ public class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests URI url = new URI("http://localhost:" + port); String header = "SID=31d4d96e407aad42; lang=en-US"; + @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange( RequestEntity.get(url).header("Cookie", header).build(), Void.class); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java index 83e7694309f..f3e6e546bcd 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/EchoHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -49,6 +49,7 @@ public class EchoHandlerIntegrationTests extends AbstractHttpHandlerIntegrationT public void echo(HttpServer httpServer) throws Exception { startServer(httpServer); + @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); byte[] body = randomBytes(); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java index f91779cba1b..ca7f22481aa 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java @@ -49,6 +49,7 @@ class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { void responseBodyError(HttpServer httpServer) throws Exception { startServer(httpServer); + @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER); @@ -62,6 +63,7 @@ class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { void handlingError(HttpServer httpServer) throws Exception { startServer(httpServer); + @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER); @@ -75,6 +77,7 @@ class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { void emptyPathSegments(HttpServer httpServer) throws Exception { startServer(httpServer); + @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/MultipartIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/MultipartIntegrationTests.java index b5eac6a0b23..f41a40b8fd8 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/MultipartIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/MultipartIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -57,6 +57,7 @@ class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests { void getFormParts(HttpServer httpServer) throws Exception { startServer(httpServer); + @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); RequestEntity> request = RequestEntity .post(new URI("http://localhost:" + port + "/form-parts")) diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java index e54798cb3a2..a6c862350cd 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/RandomHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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,6 +59,7 @@ class RandomHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests // TODO: fix Reactor support + @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); byte[] body = randomBytes(); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java index 8e0ca6179c0..f0c91f6e91d 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ServerHttpRequestIntegrationTests.java @@ -46,6 +46,7 @@ class ServerHttpRequestIntegrationTests extends AbstractHttpHandlerIntegrationTe URI url = new URI("http://localhost:" + port + "/foo?param=bar"); RequestEntity request = RequestEntity.post(url).build(); + @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange(request, Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java index 09ccb1272d9..fd3217f4482 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/WriteOnlyHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -54,6 +54,7 @@ class WriteOnlyHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTes void writeOnly(HttpServer httpServer) throws Exception { startServer(httpServer); + @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); this.body = randomBytes(); diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java index 79ba2eb64b4..6e4d9a067b0 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ZeroCopyIntegrationTests.java @@ -61,6 +61,7 @@ class ZeroCopyIntegrationTests extends AbstractHttpHandlerIntegrationTests { URI url = new URI("http://localhost:" + port); RequestEntity request = RequestEntity.get(url).build(); + @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange(request, byte[].class); assertThat(response.hasBody()).isTrue(); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java index b2326d48643..114970e443a 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateTests.java @@ -106,6 +106,7 @@ class RestTemplateTests { @Test // gh-29008 void defaultMessageConvertersWithKotlinSerialization() { + @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); List> httpMessageConverters = restTemplate.getMessageConverters(); assertThat(httpMessageConverters).extracting("class").containsOnlyOnce( diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java index f323bf1b85e..01390877cb6 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java @@ -72,6 +72,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra URI url = new URI("http://localhost:" + this.port + "/foo"); RequestEntity request = RequestEntity.get(url).build(); + @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange(request, byte[].class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -84,6 +85,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra URI url = new URI("http://localhost:" + this.port + "/bar"); RequestEntity request = RequestEntity.get(url).build(); + @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange(request, byte[].class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -96,6 +98,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra URI url = new URI("http://localhost:" + this.port + "/header"); RequestEntity request = RequestEntity.get(url).build(); + @SuppressWarnings("resource") ResponseEntity response = new RestTemplate().exchange(request, byte[].class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -103,6 +106,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra } @ParameterizedHttpServerTest + @SuppressWarnings("resource") void handlerNotFound(HttpServer httpServer) throws Exception { startServer(httpServer); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java index 4434cf6d289..80e301cb01e 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ContextPathIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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 @@ class ContextPathIntegrationTests { server.start(); try { + @SuppressWarnings("resource") RestTemplate restTemplate = new RestTemplate(); String actual; @@ -87,6 +88,7 @@ class ContextPathIntegrationTests { try { String url = "http://localhost:" + server.getPort() + "/app/api/test"; + @SuppressWarnings("resource") String actual = new RestTemplate().getForObject(url, String.class); assertThat(actual).isEqualTo("Tested in /app/api"); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java index c0e4176a45b..3d0f350e408 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. @@ -94,6 +94,7 @@ class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappin URI uri = new URI("http://localhost:" + this.port + "/redirect"); RequestEntity request = RequestEntity.get(uri).accept(MediaType.ALL).build(); + @SuppressWarnings("resource") ResponseEntity response = new RestTemplate(factory).exchange(request, Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SEE_OTHER);