Skip to content

Commit

Permalink
[JENKINS-72028] replace deprecated URL() at `core/src/main/java/jen…
Browse files Browse the repository at this point in the history
…kins/` (#8568)

* missing 'alt' attribute added

* missing 'alt' attribute added

* replaced 'new URL' to 'new URI' per Java 11 target codebase

* Revert "replaced 'new URL' to 'new URI' per Java 11 target codebase"

This reverts commit aeef4c1.

* replaced deprecated URL() with URI#.toURL()

* Update core/src/main/java/jenkins/security/ResourceDomainConfiguration.java

Co-authored-by: James Nord <[email protected]>

---------

Co-authored-by: James Nord <[email protected]>
Co-authored-by: Alexander Brandes <[email protected]>
  • Loading branch information
3 people authored Oct 11, 2023
1 parent dc190ba commit df475c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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 @@ private FormValidation checkUrl(String resourceRootUrlString, boolean allowOnlin

URL resourceRootUrl;
try {
resourceRootUrl = new URL(resourceRootUrlString);
} catch (MalformedURLException ex) {
resourceRootUrl = new URI(resourceRootUrlString).toURL();
} catch (MalformedURLException | URISyntaxException ex) {
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 @@ private FormValidation checkUrl(String resourceRootUrlString, boolean allowOnlin

// 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();
if (urlConnection instanceof HttpURLConnection) {
HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
int responseCode = httpURLConnection.getResponseCode();
Expand Down Expand Up @@ -179,7 +181,7 @@ private FormValidation checkUrl(String resourceRootUrlString, boolean allowOnlin
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) {
// 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

0 comments on commit df475c1

Please sign in to comment.