From 3978926425b58ea34085df7e0ad4469c3145fbc3 Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Tue, 11 Nov 2025 11:34:01 +0100 Subject: [PATCH] [rewrite] Add `Java8toJava11` Signed-off-by: Vincent Potucek Changes have been made to spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.Java8toJava11 org.openrewrite.java.migrate.nio.file.PathsGetToPathOf org.openrewrite.java.ChangeMethodTargetToStatic: {methodPattern=java.nio.file.Paths get(..), fullyQualifiedTargetTypeName=java.nio.file.Path} org.openrewrite.java.ChangeMethodName: {methodPattern=java.nio.file.Path get(..), newMethodName=of} Changes have been made to spring-webmvc/spring-webmvc.gradle by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.Java8toJava11 org.openrewrite.java.migrate.javax.AddJaxbDependenciesWithRuntime org.openrewrite.java.migrate.javax.AddJaxbAPIDependencies org.openrewrite.java.dependencies.RemoveDependency: {groupId=com.sun.xml.bind, artifactId=jaxb-core} org.openrewrite.java.migrate.javax.AddJaxbRuntime: {runtime=glassfish} Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.staticanalysis.AddSerialAnnotationToSerialVersionUID Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/HtmlFileTransportHandler.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/DefaultSockJsFrameFormat.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Changes have been made to spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Changes have been made to spring-websocket/src/test/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecoratorTests.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.lang.StringFormatted: {addParentheses=false} Please review and commit the results. Estimate time saved: 6h 14m --- .github/actions/build/action.yml | 5 ++++ build.gradle | 12 ++++++---- gradle/rewrite.gradle | 24 +++++++++++++++++++ rewrite.yml | 16 +++++++++++++ .../beans/propertyeditors/PathEditor.java | 9 ++++--- .../beans/ConcurrentBeanWrapperTests.java | 3 ++- .../propertyeditors/PathEditorTests.java | 3 +-- .../spring-context-indexer.gradle | 2 ++ .../jmx/support/JmxUtilsTests.java | 8 +++---- spring-core-test/spring-core-test.gradle | 3 ++- .../springframework/core/io/PathResource.java | 9 ++++--- .../util/backoff/ExponentialBackOff.java | 3 ++- .../core/io/PathResourceTests.java | 3 +-- .../core/io/ResourceTests.java | 5 ++-- .../core/io/buffer/DataBufferUtilsTests.java | 23 +++++++++--------- ...hMatchingResourcePatternResolverTests.java | 15 ++++++------ .../datasource/DriverManagerDataSource.java | 22 +++++++++++++++++ .../IsolationLevelDataSourceAdapter.java | 22 +++++++++++++++++ .../LazyConnectionDataSourceProxy.java | 22 +++++++++++++++++ .../ShardingKeyDataSourceAdapter.java | 22 +++++++++++++++++ .../datasource/SimpleDriverDataSource.java | 22 +++++++++++++++++ .../SingleConnectionDataSource.java | 22 +++++++++++++++++ .../TransactionAwareDataSourceProxy.java | 22 +++++++++++++++++ .../UserCredentialsDataSourceAdapter.java | 22 +++++++++++++++++ .../IsolationLevelDataSourceRouter.java | 22 +++++++++++++++++ spring-messaging/spring-messaging.gradle | 3 +-- spring-oxm/spring-oxm.gradle | 3 +-- spring-test/spring-test.gradle | 3 +-- .../test/context/aot/AbstractAotTests.java | 5 ++-- .../test/context/aot/AotIntegrationTests.java | 5 ++-- spring-web/spring-web.gradle | 3 +-- .../web/util/UrlPathHelper.java | 3 ++- .../Jackson2ObjectMapperBuilderTests.java | 3 +-- spring-webflux/spring-webflux.gradle | 3 +-- ...ltipartRouterFunctionIntegrationTests.java | 3 +-- .../web/reactive/resource/GzipSupport.java | 3 +-- .../resource/ResourceWebHandlerTests.java | 4 ++-- .../MultipartWebClientIntegrationTests.java | 5 ++-- spring-webmvc/spring-webmvc.gradle | 3 +-- .../web/servlet/resource/GzipSupport.java | 3 +-- 40 files changed, 312 insertions(+), 81 deletions(-) create mode 100644 gradle/rewrite.gradle create mode 100644 rewrite.yml diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 1e486fe672c8..c3bc6022f202 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -42,6 +42,11 @@ runs: java-early-access: ${{ inputs.java-early-access }} java-toolchain: ${{ inputs.java-toolchain }} java-version: ${{ inputs.java-version }} + - name: SanityCheck + id: build + if: ${{ inputs.publish == 'false' }} + shell: bash + run: ./gradlew rewriteDryRun -Dorg.gradle.jvmargs=-Xmx8G - name: Build id: build if: ${{ inputs.publish == 'false' }} diff --git a/build.gradle b/build.gradle index a86c93fcd8a6..c87a29205c59 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,12 @@ plugins { - id 'io.freefair.aspectj' version '8.13.1' apply false - // kotlinVersion is managed in gradle.properties - id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false - id 'org.jetbrains.dokka' id 'com.github.bjornvester.xjc' version '1.8.2' apply false id 'com.gradleup.shadow' version "9.2.2" apply false - id 'me.champeau.jmh' version '0.7.2' apply false + id 'io.freefair.aspectj' version '8.13.1' apply false id 'io.spring.nullability' version '0.0.8' apply false + id 'me.champeau.jmh' version '0.7.2' apply false + id 'org.jetbrains.dokka' + id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false // kotlinVersion is managed in gradle.properties + id 'org.openrewrite.rewrite' version '7.20.0' apply false } ext { @@ -16,6 +16,8 @@ ext { description = "Spring Framework" +apply from: "$rootDir/gradle/rewrite.gradle" + configure(allprojects) { project -> apply plugin: "org.springframework.build.localdev" group = "org.springframework" diff --git a/gradle/rewrite.gradle b/gradle/rewrite.gradle new file mode 100644 index 000000000000..af3ff64b98c8 --- /dev/null +++ b/gradle/rewrite.gradle @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +project.apply plugin: 'org.openrewrite.rewrite' + +rewrite { + activeRecipe('org.opensearch.openrewrite.SanityCheck') + setExportDatatables(true) + setFailOnDryRunResults(true) +} + +dependencies { + rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.18.0")) + rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.21.1") + rewrite("org.openrewrite.recipe:rewrite-java-security:3.20.0") + rewrite("org.openrewrite.recipe:rewrite-rewrite:0.15.0") + rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.21.0") + rewrite("org.openrewrite.recipe:rewrite-third-party:0.30.0") +} diff --git a/rewrite.yml b/rewrite.yml new file mode 100644 index 000000000000..0b865b65d19a --- /dev/null +++ b/rewrite.yml @@ -0,0 +1,16 @@ +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.opensearch.openrewrite.SanityCheck +displayName: Apply all Java & Gradle best practices +description: Comprehensive code quality recipe combining modernization, security, and best practices. +tags: + - java + - gradle + - static-analysis + - cleanup +recipeList: + - org.openrewrite.gradle.EnableGradleBuildCache + - org.openrewrite.gradle.EnableGradleParallelExecution + - org.openrewrite.gradle.GradleBestPractices + - org.openrewrite.java.migrate.Java8toJava11 +--- diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java index de26e7b70671..0f1b5a93af91 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java @@ -22,7 +22,6 @@ import java.net.URISyntaxException; import java.nio.file.FileSystemNotFoundException; import java.nio.file.Path; -import java.nio.file.Paths; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceEditor; @@ -33,7 +32,7 @@ * Editor for {@code java.nio.file.Path}, to directly populate a Path * property instead of using a String property as bridge. * - *

Based on {@link Paths#get(URI)}'s resolution algorithm, checking + *

Based on {@link Path#of(URI)}'s resolution algorithm, checking * registered NIO file system providers, including the default file system * for "file:..." paths. Also supports Spring-style URL notation: any fully * qualified standard URL and Spring's special "classpath:" pseudo-URL, as @@ -44,7 +43,7 @@ * @author Juergen Hoeller * @since 4.3.2 * @see java.nio.file.Path - * @see Paths#get(URI) + * @see Path#of(URI) * @see ResourceEditor * @see org.springframework.core.io.ResourceLoader * @see FileEditor @@ -83,7 +82,7 @@ public void setAsText(String text) throws IllegalArgumentException { // No NIO candidate except for "C:" style drive letters nioPathCandidate = (scheme.length() == 1); // Let's try NIO file system providers via Paths.get(URI) - setValue(Paths.get(uri).normalize()); + setValue(Path.of(uri).normalize()); return; } } @@ -104,7 +103,7 @@ public void setAsText(String text) throws IllegalArgumentException { setValue(null); } else if (nioPathCandidate && (!resource.isFile() || !resource.exists())) { - setValue(Paths.get(text).normalize()); + setValue(Path.of(text).normalize()); } else { try { diff --git a/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java b/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java index 260996841b3f..2910ac80d548 100644 --- a/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java @@ -22,6 +22,7 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ThreadLocalRandom; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -84,7 +85,7 @@ private static void performSet() { for (Iterator i = p.entrySet().iterator(); i.hasNext();) { i.next(); - if (Math.random() > 0.9) { + if (ThreadLocalRandom.current().nextDouble() > 0.9) { i.remove(); } } diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java index 4ee774e89d61..96665bcc4b14 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java @@ -19,7 +19,6 @@ import java.beans.PropertyEditor; import java.io.File; import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.jupiter.api.Test; @@ -106,7 +105,7 @@ void testCurrentDirectory() { Object value = pathEditor.getValue(); assertThat(value).isInstanceOf(Path.class); Path path = (Path) value; - assertThat(path).isEqualTo(Paths.get(".")); + assertThat(path).isEqualTo(Path.of(".")); } @Test diff --git a/spring-context-indexer/spring-context-indexer.gradle b/spring-context-indexer/spring-context-indexer.gradle index a0f311ee6d59..df154ab355de 100644 --- a/spring-context-indexer/spring-context-indexer.gradle +++ b/spring-context-indexer/spring-context-indexer.gradle @@ -1,6 +1,8 @@ description = "Spring Context Indexer" dependencies { + compileOnly "jakarta.annotation:jakarta.annotation-api:1.3.5" + testImplementation(project(":spring-context")) testImplementation("jakarta.annotation:jakarta.annotation-api") testImplementation("jakarta.inject:jakarta.inject-api") diff --git a/spring-context/src/test/java/org/springframework/jmx/support/JmxUtilsTests.java b/spring-context/src/test/java/org/springframework/jmx/support/JmxUtilsTests.java index 10e56fe318a3..0634d9c8c463 100644 --- a/spring-context/src/test/java/org/springframework/jmx/support/JmxUtilsTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/support/JmxUtilsTests.java @@ -196,7 +196,7 @@ public void dontExposeMe() { } - public interface FooMBean { + public public interface FooMBean { String getName(); } @@ -211,7 +211,7 @@ public String getName() { } - public interface FooMXBean { + public public interface FooMXBean { String getName(); } @@ -234,7 +234,7 @@ public static class Abc extends Bar { } - private interface JmxInterfaceMBean { + public interface JmxInterfaceMBean { } @@ -246,7 +246,7 @@ private interface SpecializedJmxInterface extends JmxInterface { } - private interface JmxClassMBean { + public interface JmxClassMBean { } diff --git a/spring-core-test/spring-core-test.gradle b/spring-core-test/spring-core-test.gradle index a398ed30c3bf..f80bcf9b2d94 100644 --- a/spring-core-test/spring-core-test.gradle +++ b/spring-core-test/spring-core-test.gradle @@ -2,7 +2,8 @@ description = "Spring Core Test" dependencies { api(project(":spring-core")) - optional("org.assertj:assertj-core") + compileOnly "jakarta.annotation:jakarta.annotation-api:1.3.5" + optional("org.assertj:assertj-core") optional("org.junit.jupiter:junit-jupiter-api") compileOnly("org.junit.jupiter:junit-jupiter-params") // Used in CompileWithForkedClassLoaderExtension Javadoc compileOnly("org.junit.platform:junit-platform-launcher") // Used in CompileWithForkedClassLoaderExtension diff --git a/spring-core/src/main/java/org/springframework/core/io/PathResource.java b/spring-core/src/main/java/org/springframework/core/io/PathResource.java index 9b8eaaefe83e..cf2b8ff5641c 100644 --- a/spring-core/src/main/java/org/springframework/core/io/PathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/PathResource.java @@ -30,7 +30,6 @@ import java.nio.file.NoSuchFileException; import java.nio.file.OpenOption; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import org.jspecify.annotations.Nullable; @@ -82,11 +81,11 @@ public PathResource(Path path) { * via {@link #createRelative}, the relative path will be built underneath * the given root: for example, Paths.get("C:/dir1/"), relative path "dir2" → "C:/dir1/dir2"! * @param path a path - * @see java.nio.file.Paths#get(String, String...) + * @see Path#of(String, String...) */ public PathResource(String path) { Assert.notNull(path, "Path must not be null"); - this.path = Paths.get(path).normalize(); + this.path = Path.of(path).normalize(); } /** @@ -95,11 +94,11 @@ public PathResource(String path) { * via {@link #createRelative}, the relative path will be built underneath * the given root: for example, Paths.get("C:/dir1/"), relative path "dir2" → "C:/dir1/dir2"! * @param uri a path URI - * @see java.nio.file.Paths#get(URI) + * @see Path#of(URI) */ public PathResource(URI uri) { Assert.notNull(uri, "URI must not be null"); - this.path = Paths.get(uri).normalize(); + this.path = Path.of(uri).normalize(); } diff --git a/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java index c641f2887e0e..1c820eb2e908 100644 --- a/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java @@ -17,6 +17,7 @@ package org.springframework.util.backoff; import java.util.StringJoiner; +import java.util.concurrent.ThreadLocalRandom; import org.springframework.util.Assert; @@ -308,7 +309,7 @@ private long applyJitter(long interval) { long applicableJitter = jitter * (interval / initialInterval); long min = Math.max(interval - applicableJitter, initialInterval); long max = Math.min(interval + applicableJitter, getMaxInterval()); - return min + (long) (Math.random() * (max - min)); + return min + (long) (ThreadLocalRandom.current().nextDouble() * (max - min)); } return interval; } diff --git a/spring-core/src/test/java/org/springframework/core/io/PathResourceTests.java b/spring-core/src/test/java/org/springframework/core/io/PathResourceTests.java index 5823195032f5..209b8edab361 100644 --- a/spring-core/src/test/java/org/springframework/core/io/PathResourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/PathResourceTests.java @@ -27,7 +27,6 @@ import java.nio.file.AccessDeniedException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -88,7 +87,7 @@ void nullUri() { @Test void createFromPath() { - Path path = Paths.get(TEST_FILE); + Path path = Path.of(TEST_FILE); PathResource resource = new PathResource(path); assertThat(resource.getPath()).isEqualTo(TEST_FILE); } diff --git a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java index 9385a210f99a..dce26e6f108a 100644 --- a/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/ResourceTests.java @@ -32,7 +32,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Base64; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; @@ -132,7 +131,7 @@ void resourceCreateRelativeUnknown(Resource resource) throws Exception { private static Stream resource() throws URISyntaxException { URL resourceClass = ResourceTests.class.getResource("ResourceTests.class"); - Path resourceClassFilePath = Paths.get(resourceClass.toURI()); + Path resourceClassFilePath = Path.of(resourceClass.toURI()); return Stream.of( argumentSet("ClassPathResource", new ClassPathResource("org/springframework/core/io/ResourceTests.class")), argumentSet("ClassPathResource with ClassLoader", new ClassPathResource("org/springframework/core/io/ResourceTests.class", ResourceTests.class.getClassLoader())), @@ -252,7 +251,7 @@ void sameResourceFromFileIsEqual() { @Test void sameResourceFromFilePathIsEqual() throws Exception { - Path filePath = Paths.get(getClass().getResource("ResourceTests.class").toURI()); + Path filePath = Path.of(getClass().getResource("ResourceTests.class").toURI()); Resource resource = new FileSystemResource(filePath); assertThat(resource).isEqualTo(new FileSystemResource(filePath)); } diff --git a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java index 00d95af03a18..c397d75b4ea1 100644 --- a/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java @@ -31,7 +31,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.time.Duration; import java.util.ArrayList; @@ -99,7 +98,7 @@ void readByteChannel(DataBufferFactory bufferFactory) throws Exception { URI uri = this.resource.getURI(); Flux result = - DataBufferUtils.readByteChannel(() -> FileChannel.open(Paths.get(uri), StandardOpenOption.READ), + DataBufferUtils.readByteChannel(() -> FileChannel.open(Path.of(uri), StandardOpenOption.READ), super.bufferFactory, 3); verifyReadData(result); @@ -134,7 +133,7 @@ void readByteChannelCancel(DataBufferFactory bufferFactory) throws Exception { URI uri = this.resource.getURI(); Flux result = - DataBufferUtils.readByteChannel(() -> FileChannel.open(Paths.get(uri), StandardOpenOption.READ), + DataBufferUtils.readByteChannel(() -> FileChannel.open(Path.of(uri), StandardOpenOption.READ), super.bufferFactory, 3); StepVerifier.create(result) @@ -149,7 +148,7 @@ void readAsynchronousFileChannel(DataBufferFactory bufferFactory) throws Excepti URI uri = this.resource.getURI(); Flux flux = DataBufferUtils.readAsynchronousFileChannel( - () -> AsynchronousFileChannel.open(Paths.get(uri), StandardOpenOption.READ), + () -> AsynchronousFileChannel.open(Path.of(uri), StandardOpenOption.READ), super.bufferFactory, 3); verifyReadData(flux); @@ -161,7 +160,7 @@ void readAsynchronousFileChannelPosition(DataBufferFactory bufferFactory) throws URI uri = this.resource.getURI(); Flux flux = DataBufferUtils.readAsynchronousFileChannel( - () -> AsynchronousFileChannel.open(Paths.get(uri), StandardOpenOption.READ), + () -> AsynchronousFileChannel.open(Path.of(uri), StandardOpenOption.READ), 9, super.bufferFactory, 3); StepVerifier.create(flux) @@ -207,7 +206,7 @@ void readAsynchronousFileChannelCancel(DataBufferFactory bufferFactory) throws E URI uri = this.resource.getURI(); Flux flux = DataBufferUtils.readAsynchronousFileChannel( - () -> AsynchronousFileChannel.open(Paths.get(uri), StandardOpenOption.READ), + () -> AsynchronousFileChannel.open(Path.of(uri), StandardOpenOption.READ), super.bufferFactory, 3); StepVerifier.create(flux) @@ -222,7 +221,7 @@ void readAsynchronousFileChannelCancelWithoutDemand(DataBufferFactory bufferFact URI uri = this.resource.getURI(); Flux flux = DataBufferUtils.readAsynchronousFileChannel( - () -> AsynchronousFileChannel.open(Paths.get(uri), StandardOpenOption.READ), + () -> AsynchronousFileChannel.open(Path.of(uri), StandardOpenOption.READ), super.bufferFactory, 3); BaseSubscriber subscriber = new ZeroDemandSubscriber(); @@ -891,7 +890,7 @@ void inputStreamSubscriberClose(DataBufferFactory bufferFactory) throws Interrup void readAndWriteByteChannel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; - Path source = Paths.get( + Path source = Path.of( DataBufferUtilsTests.class.getResource("DataBufferUtilsTests.txt").toURI()); Flux sourceFlux = DataBufferUtils @@ -925,7 +924,7 @@ void readAndWriteByteChannel(DataBufferFactory bufferFactory) throws Exception { void readAndWriteAsynchronousFileChannel(DataBufferFactory bufferFactory) throws Exception { super.bufferFactory = bufferFactory; - Path source = Paths.get( + Path source = Path.of( DataBufferUtilsTests.class.getResource("DataBufferUtilsTests.txt").toURI()); Flux sourceFlux = DataBufferUtils.readAsynchronousFileChannel( () -> AsynchronousFileChannel.open(source, StandardOpenOption.READ), @@ -1283,7 +1282,7 @@ void matcher3(DataBufferFactory bufferFactory) { @ParameterizedDataBufferAllocatingTest void propagateContextByteChannel(DataBufferFactory bufferFactory) throws IOException { - Path path = Paths.get(this.resource.getURI()); + Path path = Path.of(this.resource.getURI()); try (SeekableByteChannel out = Files.newByteChannel(this.tempFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) { Flux result = DataBufferUtils.read(path, bufferFactory, 1024, StandardOpenOption.READ) .transformDeferredContextual((f, ctx) -> { @@ -1307,7 +1306,7 @@ void propagateContextByteChannel(DataBufferFactory bufferFactory) throws IOExcep @ParameterizedDataBufferAllocatingTest void propagateContextAsynchronousFileChannel(DataBufferFactory bufferFactory) throws IOException { - Path path = Paths.get(this.resource.getURI()); + Path path = Path.of(this.resource.getURI()); try (AsynchronousFileChannel out = AsynchronousFileChannel.open(this.tempFile, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) { Flux result = DataBufferUtils.read(path, bufferFactory, 1024, StandardOpenOption.READ) .transformDeferredContextual((f, ctx) -> { @@ -1331,7 +1330,7 @@ void propagateContextAsynchronousFileChannel(DataBufferFactory bufferFactory) th @ParameterizedDataBufferAllocatingTest void propagateContextPath(DataBufferFactory bufferFactory) throws IOException { - Path path = Paths.get(this.resource.getURI()); + Path path = Path.of(this.resource.getURI()); Path out = Files.createTempFile("data-buffer-utils-tests", ".tmp"); Flux result = DataBufferUtils.read(path, bufferFactory, 1024, StandardOpenOption.READ) diff --git a/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java b/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java index e0390b6c7b03..ebd04c1098a4 100644 --- a/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/support/PathMatchingResourcePatternResolverTests.java @@ -30,7 +30,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Enumeration; import java.util.List; @@ -118,7 +117,7 @@ void classpathStarWithPatternOnFileSystem() { @Test // gh-31111 void usingFileProtocolWithWildcardInPatternAndNonexistentRootPath() throws IOException { - Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath(); + Path testResourcesDir = Path.of("src/test/resources").toAbsolutePath(); String pattern = String.format("file:%s/example/bogus/**", testResourcesDir); assertThat(resolver.getResources(pattern)).isEmpty(); // When the log level for the resolver is set to at least INFO, we should see @@ -131,7 +130,7 @@ void usingFileProtocolWithWildcardInPatternAndNonexistentRootPath() throws IOExc @Test void encodedHashtagInPath() throws IOException { - Path rootDir = Paths.get("src/test/resources/custom%23root").toAbsolutePath(); + Path rootDir = Path.of("src/test/resources/custom%23root").toAbsolutePath(); URL root = new URL("file:" + rootDir + "/"); resolver = new PathMatchingResourcePatternResolver(new DefaultResourceLoader(new URLClassLoader(new URL[] {root}))); resolver.setUseCaches(false); @@ -164,7 +163,7 @@ void usingClasspathStarProtocolWithWildcardInPatternAndNotEndingInSlash() throws @Test void usingFileProtocolWithWildcardInPatternAndNotEndingInSlash() throws Exception { - Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath(); + Path testResourcesDir = Path.of("src/test/resources").toAbsolutePath(); String pattern = String.format("file:%s/org/springframework/core/io/sup*", testResourcesDir); String pathPrefix = ".+org/springframework/core/io/"; @@ -195,7 +194,7 @@ void usingClasspathStarProtocolWithWildcardInPatternAndEndingInSlash() throws Ex @Test void usingFileProtocolWithWildcardInPatternAndEndingInSlash() throws Exception { - Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath(); + Path testResourcesDir = Path.of("src/test/resources").toAbsolutePath(); String pattern = String.format("file:%s/org/springframework/core/io/sup*/", testResourcesDir); String pathPrefix = ".+org/springframework/core/io/"; @@ -229,7 +228,7 @@ private List getSubPathsIgnoringClassFilesEtc(String pattern, String pat @Test void usingFileProtocolWithoutWildcardInPatternAndEndingInSlashStarStar() { - Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath(); + Path testResourcesDir = Path.of("src/test/resources").toAbsolutePath(); String pattern = String.format("file:%s/scanned-resources/**", testResourcesDir); String pathPrefix = ".+?resources/"; @@ -241,7 +240,7 @@ void usingFileProtocolWithoutWildcardInPatternAndEndingInSlashStarStar() { @Test void usingFileProtocolWithWildcardInPatternAndEndingInSlashStarStar() { - Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath(); + Path testResourcesDir = Path.of("src/test/resources").toAbsolutePath(); String pattern = String.format("file:%s/scanned*resources/**", testResourcesDir); String pathPrefix = ".+?resources/"; @@ -253,7 +252,7 @@ void usingFileProtocolWithWildcardInPatternAndEndingInSlashStarStar() { @Test void usingFileProtocolAndAssertingUrlAndUriSyntax() throws Exception { - Path testResourcesDir = Paths.get("src/test/resources").toAbsolutePath(); + Path testResourcesDir = Path.of("src/test/resources").toAbsolutePath(); String pattern = "file:%s/scanned-resources/**/resource#test1.txt".formatted(testResourcesDir); Resource[] resources = resolver.getResources(pattern); assertThat(resources).hasSize(1); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DriverManagerDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DriverManagerDataSource.java index 6a8160063f1b..19da8114457b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DriverManagerDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DriverManagerDataSource.java @@ -155,4 +155,26 @@ protected Connection getConnectionFromDriverManager(String url, Properties props return DriverManager.getConnection(url, props); } + public boolean isWrapperFor(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + return iface != null && iface.isAssignableFrom(this.getClass()); + } + + public T unwrap(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + try { + if (iface != null && iface.isAssignableFrom(this.getClass())) { + return (T) this; + } + throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation"); + } catch (Exception e) { + throw new java.sql.SQLException(e); + } + } + + public java.util.logging.Logger getParentLogger() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapter.java index 419913c9b20c..6b3ddffe041d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/IsolationLevelDataSourceAdapter.java @@ -173,4 +173,26 @@ protected Connection doGetConnection(@Nullable String username, @Nullable String return (txReadOnly ? Boolean.TRUE : null); } + public boolean isWrapperFor(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + return iface != null && iface.isAssignableFrom(this.getClass()); + } + + public T unwrap(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + try { + if (iface != null && iface.isAssignableFrom(this.getClass())) { + return (T) this; + } + throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation"); + } catch (Exception e) { + throw new java.sql.SQLException(e); + } + } + + public java.util.logging.Logger getParentLogger() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java index 2cc269a0aad7..566add56fa24 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java @@ -509,4 +509,26 @@ private DataSource getDataSourceToUse() { } } + public boolean isWrapperFor(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + return iface != null && iface.isAssignableFrom(this.getClass()); + } + + public T unwrap(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + try { + if (iface != null && iface.isAssignableFrom(this.getClass())) { + return (T) this; + } + throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation"); + } catch (Exception e) { + throw new java.sql.SQLException(e); + } + } + + public java.util.logging.Logger getParentLogger() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyDataSourceAdapter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyDataSourceAdapter.java index b51f9b39d0e0..c2d3fa197405 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyDataSourceAdapter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyDataSourceAdapter.java @@ -134,4 +134,26 @@ public ConnectionBuilder createConnectionBuilder() throws SQLException { return connectionBuilder.shardingKey(shardingKey).superShardingKey(superShardingKey); } + public boolean isWrapperFor(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + return iface != null && iface.isAssignableFrom(this.getClass()); + } + + public T unwrap(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + try { + if (iface != null && iface.isAssignableFrom(this.getClass())) { + return (T) this; + } + throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation"); + } catch (Exception e) { + throw new java.sql.SQLException(e); + } + } + + public java.util.logging.Logger getParentLogger() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SimpleDriverDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SimpleDriverDataSource.java index 27c1ad7b9d01..722470d73931 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SimpleDriverDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SimpleDriverDataSource.java @@ -143,4 +143,26 @@ protected Connection getConnectionFromDriver(Properties props) throws SQLExcepti return driver.connect(url, props); } + public boolean isWrapperFor(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + return iface != null && iface.isAssignableFrom(this.getClass()); + } + + public T unwrap(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + try { + if (iface != null && iface.isAssignableFrom(this.getClass())) { + return (T) this; + } + throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation"); + } catch (Exception e) { + throw new java.sql.SQLException(e); + } + } + + public java.util.logging.Logger getParentLogger() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java index 6cc44269bbb1..2b3d2d05f1d8 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java @@ -393,4 +393,26 @@ public CloseSuppressingInvocationHandler(Connection target) { } } + public boolean isWrapperFor(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + return iface != null && iface.isAssignableFrom(this.getClass()); + } + + public T unwrap(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + try { + if (iface != null && iface.isAssignableFrom(this.getClass())) { + return (T) this; + } + throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation"); + } catch (Exception e) { + throw new java.sql.SQLException(e); + } + } + + public java.util.logging.Logger getParentLogger() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java index 3a2f08a87a48..efc0ed358617 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java @@ -289,4 +289,26 @@ public TransactionAwareInvocationHandler(DataSource targetDataSource) { } } + public boolean isWrapperFor(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + return iface != null && iface.isAssignableFrom(this.getClass()); + } + + public T unwrap(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + try { + if (iface != null && iface.isAssignableFrom(this.getClass())) { + return (T) this; + } + throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation"); + } catch (Exception e) { + throw new java.sql.SQLException(e); + } + } + + public java.util.logging.Logger getParentLogger() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.java index 03ef91a79d59..4b5da2f70c05 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.java @@ -217,4 +217,26 @@ public String toString() { } } + public boolean isWrapperFor(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + return iface != null && iface.isAssignableFrom(this.getClass()); + } + + public T unwrap(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + try { + if (iface != null && iface.isAssignableFrom(this.getClass())) { + return (T) this; + } + throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation"); + } catch (Exception e) { + throw new java.sql.SQLException(e); + } + } + + public java.util.logging.Logger getParentLogger() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/IsolationLevelDataSourceRouter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/IsolationLevelDataSourceRouter.java index 84c8c2025b61..7e29a93f1ef4 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/IsolationLevelDataSourceRouter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/IsolationLevelDataSourceRouter.java @@ -138,4 +138,26 @@ else if (lookupKey instanceof String constantName) { return TransactionSynchronizationManager.getCurrentTransactionIsolationLevel(); } + public boolean isWrapperFor(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + return iface != null && iface.isAssignableFrom(this.getClass()); + } + + public T unwrap(Class iface) throws java.sql.SQLException { + // TODO Auto-generated method stub + try { + if (iface != null && iface.isAssignableFrom(this.getClass())) { + return (T) this; + } + throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation"); + } catch (Exception e) { + throw new java.sql.SQLException(e); + } + } + + public java.util.logging.Logger getParentLogger() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/spring-messaging/spring-messaging.gradle b/spring-messaging/spring-messaging.gradle index a611cf669825..547f519cce75 100644 --- a/spring-messaging/spring-messaging.gradle +++ b/spring-messaging/spring-messaging.gradle @@ -39,8 +39,7 @@ dependencies { testImplementation("org.xmlunit:xmlunit-matchers") testRuntimeOnly(project(":spring-context")) testRuntimeOnly("com.sun.activation:jakarta.activation") - testRuntimeOnly("com.sun.xml.bind:jaxb-core") - testRuntimeOnly("com.sun.xml.bind:jaxb-impl") + testRuntimeOnly("org.glassfish.jaxb:jaxb-runtime") testRuntimeOnly("jakarta.json:jakarta.json-api") testRuntimeOnly("org.eclipse:yasson") } diff --git a/spring-oxm/spring-oxm.gradle b/spring-oxm/spring-oxm.gradle index dea37ac797e1..df4305b4fc32 100644 --- a/spring-oxm/spring-oxm.gradle +++ b/spring-oxm/spring-oxm.gradle @@ -22,8 +22,7 @@ dependencies { } testImplementation("org.xmlunit:xmlunit-assertj") testImplementation("org.xmlunit:xmlunit-matchers") - testRuntimeOnly("com.sun.xml.bind:jaxb-core") - testRuntimeOnly("com.sun.xml.bind:jaxb-impl") + testRuntimeOnly("org.glassfish.jaxb:jaxb-runtime") } tasks.named("xjc").configure { xjc -> diff --git a/spring-test/spring-test.gradle b/spring-test/spring-test.gradle index ea631c65786b..9ac78bf94e5d 100644 --- a/spring-test/spring-test.gradle +++ b/spring-test/spring-test.gradle @@ -83,8 +83,7 @@ dependencies { testImplementation("org.hsqldb:hsqldb") testImplementation("org.junit.platform:junit-platform-testkit") testImplementation("tools.jackson.core:jackson-databind") - testRuntimeOnly("com.sun.xml.bind:jaxb-core") - testRuntimeOnly("com.sun.xml.bind:jaxb-impl") + testRuntimeOnly("org.glassfish.jaxb:jaxb-runtime") testRuntimeOnly("org.glassfish:jakarta.el") testRuntimeOnly("org.junit.support:testng-engine") testRuntimeOnly("org.junit.vintage:junit-vintage-engine") { diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/AbstractAotTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/AbstractAotTests.java index cdaf8da48286..e36eac177f66 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/AbstractAotTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/AbstractAotTests.java @@ -17,7 +17,6 @@ package org.springframework.test.context.aot; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Set; import java.util.stream.Stream; @@ -140,7 +139,7 @@ Set classpathRoots() { Path classpathRoot() { try { - return Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()); + return Path.of(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()); } catch (Exception ex) { throw new RuntimeException(ex); @@ -149,7 +148,7 @@ Path classpathRoot() { Path classpathRoot(Class clazz) { try { - return Paths.get(clazz.getProtectionDomain().getCodeSource().getLocation().toURI()); + return Path.of(clazz.getProtectionDomain().getCodeSource().getLocation().toURI()); } catch (Exception ex) { throw new RuntimeException(ex); diff --git a/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java index 12ed85654041..b9b82fd91837 100644 --- a/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/aot/AotIntegrationTests.java @@ -18,7 +18,6 @@ import java.io.PrintWriter; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Optional; import java.util.Set; @@ -81,7 +80,7 @@ class AotIntegrationTests extends AbstractAotTests { // nested JUnit Platform launched by the CompileWithForkedClassLoaderExtension. static { try { - Path classpathRoot = Paths.get(AotIntegrationTests.class.getProtectionDomain().getCodeSource().getLocation().toURI()); + Path classpathRoot = Path.of(AotIntegrationTests.class.getProtectionDomain().getCodeSource().getLocation().toURI()); System.setProperty(CLASSPATH_ROOT, classpathRoot.toFile().getCanonicalPath()); } catch (Exception ex) { @@ -267,7 +266,7 @@ else if (source instanceof MethodSource methodSource) { private static TestClassScanner createTestClassScanner() { String classpathRoot = System.getProperty(CLASSPATH_ROOT); assertThat(classpathRoot).as(CLASSPATH_ROOT).isNotNull(); - Set classpathRoots = Set.of(Paths.get(classpathRoot)); + Set classpathRoots = Set.of(Path.of(classpathRoot)); return new TestClassScanner(classpathRoots); } diff --git a/spring-web/spring-web.gradle b/spring-web/spring-web.gradle index 62a50956d608..a23d27933502 100644 --- a/spring-web/spring-web.gradle +++ b/spring-web/spring-web.gradle @@ -94,8 +94,7 @@ dependencies { testImplementation("org.xmlunit:xmlunit-assertj") testImplementation("org.xmlunit:xmlunit-matchers") testImplementation("tools.jackson.module:jackson-module-kotlin") - testRuntimeOnly("com.sun.xml.bind:jaxb-core") - testRuntimeOnly("com.sun.xml.bind:jaxb-impl") + testRuntimeOnly("org.glassfish.jaxb:jaxb-runtime") testRuntimeOnly("jakarta.json:jakarta.json-api") testRuntimeOnly("org.eclipse.angus:angus-mail") testRuntimeOnly("org.eclipse:yasson") diff --git a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java index 0202febd610e..9b1e6b03d111 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java +++ b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java @@ -17,6 +17,7 @@ package org.springframework.web.util; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.util.Locale; import java.util.Map; @@ -554,7 +555,7 @@ private String decodeInternal(HttpServletRequest request, String source) { logger.debug("Could not decode request string [" + source + "] with encoding '" + enc + "': falling back to platform default encoding; exception message: " + ex.getMessage()); } - return URLDecoder.decode(source); + return URLDecoder.decode(source, StandardCharsets.UTF_8); } } diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java index 83f7c82a640a..1d5c30314878 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilderTests.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; -import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.time.OffsetDateTime; import java.time.format.DateTimeParseException; @@ -284,7 +283,7 @@ int getY() { void wellKnownModules() throws JsonProcessingException { ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build(); - Path file = Paths.get("foo"); + Path file = Path.of("foo"); assertThat(new String(objectMapper.writeValueAsBytes(file), StandardCharsets.UTF_8)) .endsWith("foo\""); diff --git a/spring-webflux/spring-webflux.gradle b/spring-webflux/spring-webflux.gradle index dad853c54300..8914467e3117 100644 --- a/spring-webflux/spring-webflux.gradle +++ b/spring-webflux/spring-webflux.gradle @@ -54,8 +54,7 @@ dependencies { testImplementation("org.eclipse.jetty:jetty-server") testImplementation("org.hibernate.validator:hibernate-validator") testImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json") - testRuntimeOnly("com.sun.xml.bind:jaxb-core") - testRuntimeOnly("com.sun.xml.bind:jaxb-impl") + testRuntimeOnly("org.glassfish.jaxb:jaxb-runtime") testRuntimeOnly("com.sun.activation:jakarta.activation") testRuntimeOnly("org.glassfish:jakarta.el") testRuntimeOnly("org.jruby:jruby") diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java index bc959ea2f542..ff3303944dd5 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/MultipartRouterFunctionIntegrationTests.java @@ -20,7 +20,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.time.Duration; import java.util.List; import java.util.Map; @@ -117,7 +116,7 @@ private void verifyTransferTo(HttpServer httpServer) throws Exception { .create(result) .consumeNextWith(location -> { try { - byte[] actualBytes = Files.readAllBytes(Paths.get(location)); + byte[] actualBytes = Files.readAllBytes(Path.of(location)); byte[] expectedBytes = FileCopyUtils.copyToByteArray(this.resource.getInputStream()); assertThat(actualBytes).isEqualTo(expectedBytes); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipSupport.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipSupport.java index bbbfa3946072..491774bb4e74 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipSupport.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/GzipSupport.java @@ -22,7 +22,6 @@ import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.HashSet; import java.util.Set; import java.util.zip.GZIPOutputStream; @@ -72,7 +71,7 @@ void create(String filePath) { Resource location = new ClassPathResource("test/", getClass()); Resource resource = new FileSystemResource(location.createRelative(filePath).getFile()); - Path gzFilePath = Paths.get(resource.getFile().getAbsolutePath() + ".gz"); + Path gzFilePath = Path.of(resource.getFile().getAbsolutePath() + ".gz"); Files.deleteIfExists(gzFilePath); File gzFile = Files.createFile(gzFilePath).toFile(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java index 7aff83db6f0f..b70cfede7f3d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java @@ -17,7 +17,7 @@ package org.springframework.web.reactive.resource; import java.io.IOException; -import java.nio.file.Paths; +import java.nio.file.Path; import java.time.Duration; import java.util.Arrays; import java.util.Collections; @@ -800,7 +800,7 @@ void shouldNotServeDirectoryInJarFile() throws Exception { @Test void servesResourcesFromFileSystem() throws Exception { String packagePath = ClassUtils.classPackageAsResourcePath(getClass()); - String path = Paths.get("src/test/resources", packagePath).normalize() + "/"; + String path = Path.of("src/test/resources", packagePath).normalize() + "/"; this.handler.setLocations(List.of(new FileSystemResource(path))); this.handler.afterPropertiesSet(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java index 580f7c58d39f..2ba818a5f3d0 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MultipartWebClientIntegrationTests.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.stream.Collectors; @@ -176,8 +175,8 @@ void transferTo(HttpServer httpServer) throws Exception { .bodyToFlux(String.class); StepVerifier.create(result) - .consumeNextWith(filename -> verifyContents(Paths.get(filename), new ClassPathResource("foo.txt", MultipartHttpMessageReader.class))) - .consumeNextWith(filename -> verifyContents(Paths.get(filename), new ClassPathResource("logo.png", getClass()))) + .consumeNextWith(filename -> verifyContents(Path.of(filename), new ClassPathResource("foo.txt", MultipartHttpMessageReader.class))) + .consumeNextWith(filename -> verifyContents(Path.of(filename), new ClassPathResource("logo.png", getClass()))) .verifyComplete(); } diff --git a/spring-webmvc/spring-webmvc.gradle b/spring-webmvc/spring-webmvc.gradle index 760530e3c87d..4cdadc59ae63 100644 --- a/spring-webmvc/spring-webmvc.gradle +++ b/spring-webmvc/spring-webmvc.gradle @@ -74,8 +74,7 @@ dependencies { testImplementation("org.xmlunit:xmlunit-assertj") testImplementation("org.xmlunit:xmlunit-matchers") testRuntimeOnly("com.sun.activation:jakarta.activation") - testRuntimeOnly("com.sun.xml.bind:jaxb-core") - testRuntimeOnly("com.sun.xml.bind:jaxb-impl") + testRuntimeOnly("org.glassfish.jaxb:jaxb-runtime") testRuntimeOnly("org.apache.httpcomponents.client5:httpclient5") testRuntimeOnly("org.glassfish:jakarta.el") testRuntimeOnly("org.jruby:jruby") diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java index 16e3e8062b3c..b4749fe12cd2 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/GzipSupport.java @@ -22,7 +22,6 @@ import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.HashSet; import java.util.Set; import java.util.zip.GZIPOutputStream; @@ -72,7 +71,7 @@ void create(String filePath) { Resource location = new ClassPathResource("test/", getClass()); Resource resource = new FileSystemResource(location.createRelative(filePath).getFile()); - Path gzFilePath = Paths.get(resource.getFile().getAbsolutePath() + ".gz"); + Path gzFilePath = Path.of(resource.getFile().getAbsolutePath() + ".gz"); Files.deleteIfExists(gzFilePath); File gzFile = Files.createFile(gzFilePath).toFile();