Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-72028] replace deprecated URL() at core/src/main/java/jenkins/ #8568

Merged
merged 10 commits into from
Oct 11, 2023
3 changes: 2 additions & 1 deletion core/src/main/java/jenkins/install/SetupWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.net.HttpRetryException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -561,7 +562,7 @@ public JSONArray getPlatformPluginUpdates() {
suggestedPluginUrl = suggestedPluginUrl + (suggestedPluginUrl.contains("?") ? "&" : "?") + "version=" + version;
}
try {
URLConnection connection = ProxyConfiguration.open(new URL(suggestedPluginUrl));
URLConnection connection = ProxyConfiguration.open(new URI(suggestedPluginUrl).toURL());

try {
String initialPluginJson = IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -112,14 +114,14 @@

URL resourceRootUrl;
try {
resourceRootUrl = new URL(resourceRootUrlString);
} catch (MalformedURLException ex) {
resourceRootUrl = new URI(resourceRootUrlString).toURL();
} catch (MalformedURLException | URISyntaxException ex) {

Check warning on line 118 in core/src/main/java/jenkins/security/ResourceDomainConfiguration.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 118 is not covered by tests
return FormValidation.error(Messages.ResourceDomainConfiguration_Invalid());
}

String resourceRootUrlHost = resourceRootUrl.getHost();
try {
String jenkinsRootUrlHost = new URL(jenkinsRootUrlString).getHost();
String jenkinsRootUrlHost = new URI(jenkinsRootUrlString).getHost();
if (jenkinsRootUrlHost.equals(resourceRootUrlHost)) {
// We do not allow the same host for Jenkins and resource root URLs even if there's some other difference.
// This is a conservative choice and prohibits same host/different proto/different port/different path:
Expand Down Expand Up @@ -147,7 +149,7 @@

// Send a request to /instance-identity/ at the resource root URL and check whether it is this Jenkins
try {
URLConnection urlConnection = new URL(resourceRootUrlString + "instance-identity/").openConnection();
URLConnection urlConnection = new URI(resourceRootUrlString + "instance-identity/").toURL().openConnection();

Check warning on line 152 in core/src/main/java/jenkins/security/ResourceDomainConfiguration.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 152 is not covered by tests
if (urlConnection instanceof HttpURLConnection) {
HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
int responseCode = httpURLConnection.getResponseCode();
Expand Down Expand Up @@ -179,7 +181,7 @@
return FormValidation.error(Messages.ResourceDomainConfiguration_FailedIdentityCheck(responseCode, responseMessage));
}
return FormValidation.error(Messages.ResourceDomainConfiguration_Invalid()); // unlikely to ever be hit
} catch (MalformedURLException ex) {
} catch (MalformedURLException | URISyntaxException ex) {

Check warning on line 184 in core/src/main/java/jenkins/security/ResourceDomainConfiguration.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 184 is not covered by tests
// Not expected to be hit
LOGGER.log(Level.FINE, "MalformedURLException occurred during instance identity check for " + resourceRootUrlString, ex);
return FormValidation.error(Messages.ResourceDomainConfiguration_Exception(ex.getMessage()));
Expand Down
Loading