Skip to content

Commit c6ab115

Browse files
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.
1 parent c38b20e commit c6ab115

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsRegistrar.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616

1717
package org.springframework.cloud.openfeign;
1818

19-
import java.net.MalformedURLException;
2019
import java.net.URI;
2120
import java.net.URISyntaxException;
22-
import java.net.URL;
2321
import java.util.ArrayList;
2422
import java.util.Arrays;
2523
import java.util.Collections;
@@ -122,9 +120,9 @@ static String getUrl(String url) {
122120
url = url.substring(0, url.length() - 1);
123121
}
124122
try {
125-
new URL(url);
123+
new URI(url);
126124
}
127-
catch (MalformedURLException e) {
125+
catch (URISyntaxException e) {
128126
throw new IllegalArgumentException(url + " is malformed", e);
129127
}
130128
}

spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientsRegistrarTests.java

+12
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ private String testGetName(String name) {
8989
return registrar.getName(Collections.singletonMap("name", name));
9090
}
9191

92+
@Test
93+
void goodUrl() {
94+
String url = FeignClientsRegistrar.getUrl("https://good.url");
95+
assertThat(url).as("url was wrong").isEqualTo("https://good.url");
96+
}
97+
98+
@Test
99+
void badUrl() {
100+
assertThatExceptionOfType(IllegalArgumentException.class)
101+
.isThrownBy(() -> FeignClientsRegistrar.getUrl("http://bad url"));
102+
}
103+
92104
@Test
93105
void testRemoveTrailingSlashFromUrl() {
94106
String url = FeignClientsRegistrar.getUrl("http://localhost/");

0 commit comments

Comments
 (0)