From ad9cc3b6515b0a660f98e06aab320ee72c9b5419 Mon Sep 17 00:00:00 2001 From: HyeongDo-Myeong Date: Thu, 8 May 2025 18:58:11 +0900 Subject: [PATCH] Replace deprecated URL constructor in getUrl (#1179) * Replace URL with URI in FeignClientsRegistrar to avoid deprecation warning The constructor 'URL(String)' has been deprecated since Java 20. Although this does not affect the current environment (Java 17), it will cause issues when upgrading to Java 21 or later. This commit updates the URL validation in FeignClientsRegistrar.getUrl by replacing `new URL(url)` with `new URI(url)`, ensuring forward compatibility. Verified with Java 17 and the FeignClientsRegistrarTests. Signed-off-by: HyeongDo-Myeong * chore: update license year and add author tags Updated license headers to reflect year 2025 in all modified Java files. Also added @author Javadoc tags with full name to classes modified in the previous commit as requested in PR review. Signed-off-by: HyeongDo-Myeong --------- Signed-off-by: HyeongDo-Myeong --- .../cloud/openfeign/FeignClientsRegistrar.java | 9 ++++----- .../openfeign/FeignClientsRegistrarTests.java | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java index 00fe8f19..d36b3f72 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2024 the original author or authors. + * Copyright 2013-2025 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. @@ -16,10 +16,8 @@ package org.springframework.cloud.openfeign; -import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -68,6 +66,7 @@ import org.springframework.util.StringUtils; * @author Olga Maciaszek-Sharma * @author Jasbir Singh * @author Jinho Lee + * @author HyeongDo Myeong */ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware { @@ -122,9 +121,9 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLo url = url.substring(0, url.length() - 1); } try { - new URL(url); + new URI(url); } - catch (MalformedURLException e) { + catch (URISyntaxException e) { throw new IllegalArgumentException(url + " is malformed", e); } } diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java index 5459dd66..3ac36ea5 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2024 the original author or authors. + * Copyright 2013-2025 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. @@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Michal Domagala * @author Szymon Linowski * @author Olga Maciaszek-Sharma + * @author HyeongDo Myeong */ class FeignClientsRegistrarTests { @@ -89,6 +90,18 @@ class FeignClientsRegistrarTests { return registrar.getName(Collections.singletonMap("name", name)); } + @Test + void goodUrl() { + String url = FeignClientsRegistrar.getUrl("https://good.url"); + assertThat(url).as("url was wrong").isEqualTo("https://good.url"); + } + + @Test + void badUrl() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> FeignClientsRegistrar.getUrl("http://bad url")); + } + @Test void testRemoveTrailingSlashFromUrl() { String url = FeignClientsRegistrar.getUrl("http://localhost/");