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] deprecated URL instantiation applied #8515

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f66ba70
missing 'alt' attribute added
abhishekmaity Sep 17, 2023
2afcdeb
missing 'alt' attribute added
abhishekmaity Sep 17, 2023
aeef4c1
replaced 'new URL' to 'new URI' per Java 11 target codebase
abhishekmaity Sep 18, 2023
ddc5115
Revert "replaced 'new URL' to 'new URI' per Java 11 target codebase"
abhishekmaity Sep 18, 2023
4b97d1d
Merge branch 'master' into master
abhishekmaity Sep 20, 2023
7b66163
Merge branch 'jenkinsci:master' into master
abhishekmaity Sep 20, 2023
d20efb7
JENKINS-72028; deprecated URL instantiation applied
abhishekmaity Sep 21, 2023
c926874
JENKINS-72028; mvn spotless applied
abhishekmaity Sep 21, 2023
e6d065c
Merge branch 'jenkinsci:master' into task-1
abhishekmaity Sep 21, 2023
7ac67c0
resolve checkstyle
abhishekmaity Sep 22, 2023
8766f75
Merge remote-tracking branch 'origin/task-1' into task-1
abhishekmaity Sep 22, 2023
2550e1d
Merge branch 'master' into task-1
NotMyFault Sep 22, 2023
c590acc
Merge branch 'jenkinsci:master' into master
abhishekmaity Sep 24, 2023
3bc44be
Merge branch 'master' into task-1
abhishekmaity Sep 24, 2023
9b727cc
Merge branch 'master' into task-1
abhishekmaity Sep 24, 2023
7e05453
Merge branch 'jenkinsci:master' into master
abhishekmaity Sep 24, 2023
0ca8a73
updated exception handling from generic to specific
abhishekmaity Sep 25, 2023
22341db
Merge remote-tracking branch 'origin/task-1' into task-1
abhishekmaity Sep 25, 2023
2145fed
fix whitespace in response to checkstyle
abhishekmaity Sep 26, 2023
fcd86fb
Merge branch 'master' into task-1
abhishekmaity Sep 26, 2023
4b96366
Merge branch 'jenkinsci:master' into master
abhishekmaity Sep 26, 2023
3d031f7
Merge branch 'jenkinsci:master' into task-1
abhishekmaity Sep 27, 2023
9a94f16
Merge branch 'jenkinsci:master' into master
abhishekmaity Sep 27, 2023
b9c4dd5
Merge pull request #1 from abhishekmaity/master
abhishekmaity Sep 27, 2023
07c0cbb
Merge branch 'jenkinsci:master' into task-1
abhishekmaity Sep 28, 2023
57dd6e0
Merge branch 'master' into task-1
abhishekmaity Sep 30, 2023
3a6571b
Merge branch 'master' into task-1
abhishekmaity Oct 2, 2023
efee7ee
Merge branch 'jenkinsci:master' into task-1
abhishekmaity Oct 3, 2023
34d09f2
fix issues as per code review
abhishekmaity Oct 3, 2023
75d2402
Merge branch 'master' into task-1
abhishekmaity Oct 3, 2023
5c6a96e
fix checkstyle issues
abhishekmaity Oct 4, 2023
7bcdccb
Merge remote-tracking branch 'origin/task-1' into task-1
abhishekmaity Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cli/src/main/java/hudson/cli/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import java.net.URISyntaxException;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -306,7 +306,7 @@ public boolean verify(String s, SSLSession sslSession) {
}

CLIConnectionFactory factory = new CLIConnectionFactory();
String userInfo = new URL(url).getUserInfo();
String userInfo = new URI(url).getUserInfo();
if (userInfo != null) {
factory = factory.basicAuth(userInfo);
} else if (auth != null) {
Expand Down Expand Up @@ -386,9 +386,9 @@ public void close() throws IOException {
}
}

private static int plainHttpConnection(String url, List<String> args, CLIConnectionFactory factory) throws IOException, InterruptedException {
private static int plainHttpConnection(String url, List<String> args, CLIConnectionFactory factory) throws IOException, InterruptedException, URISyntaxException {
LOGGER.log(FINE, "Trying to connect to {0} via plain protocol over HTTP", url);
FullDuplexHttpStream streams = new FullDuplexHttpStream(new URL(url), "cli?remoting=false", factory.authorization);
FullDuplexHttpStream streams = new FullDuplexHttpStream(new URI(url).toURL(), "cli?remoting=false", factory.authorization);
try (ClientSideImpl connection = new ClientSideImpl(new PlainCLIProtocol.FramedOutput(streams.getOutputStream()))) {
connection.start(args);
InputStream is = streams.getInputStream();
Expand Down
23 changes: 12 additions & 11 deletions cli/src/main/java/hudson/cli/SSHCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.util.QuotedStringTokenizer;
import java.io.IOException;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyPair;
import java.security.PublicKey;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
Expand All @@ -45,7 +45,6 @@
import org.apache.sshd.client.future.ConnectFuture;
import org.apache.sshd.client.keyverifier.DefaultKnownHostsServerKeyVerifier;
import org.apache.sshd.client.keyverifier.KnownHostsServerKeyVerifier;
import org.apache.sshd.client.keyverifier.ServerKeyVerifier;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.future.WaitableFuture;
import org.apache.sshd.common.util.io.input.NoCloseInputStream;
Expand All @@ -60,9 +59,14 @@
*/
class SSHCLI {

static int sshConnection(String jenkinsUrl, String user, List<String> args, PrivateKeyProvider provider, final boolean strictHostKey) throws IOException {
static int sshConnection(String jenkinsUrl, String user, List<String> args, PrivateKeyProvider provider, final boolean strictHostKey) throws IOException, URISyntaxException {
Logger.getLogger(SecurityUtils.class.getName()).setLevel(Level.WARNING); // suppress: BouncyCastle not registered, using the default JCE provider
URL url = new URL(jenkinsUrl + "login");
URL url = null;
try {
url = new URI(jenkinsUrl + "login").toURL();
} catch (URISyntaxException e) {
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
throw new RuntimeException(e);
}
URLConnection conn = openConnection(url);
CLI.verifyJenkinsConnection(conn);
String endpointDescription = conn.getHeaderField("X-SSH-Endpoint");
Expand All @@ -86,12 +90,9 @@ static int sshConnection(String jenkinsUrl, String user, List<String> args, Priv

try (SshClient client = SshClient.setUpDefaultClient()) {

KnownHostsServerKeyVerifier verifier = new DefaultKnownHostsServerKeyVerifier(new ServerKeyVerifier() {
@Override
public boolean verifyServerKey(ClientSession clientSession, SocketAddress remoteAddress, PublicKey serverKey) {
CLI.LOGGER.log(Level.WARNING, "Unknown host key for {0}", remoteAddress.toString());
return !strictHostKey;
}
KnownHostsServerKeyVerifier verifier = new DefaultKnownHostsServerKeyVerifier((clientSession, remoteAddress, serverKey) -> {
CLI.LOGGER.log(Level.WARNING, "Unknown host key for {0}", remoteAddress.toString());
return !strictHostKey;
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
}, true);

client.setServerKeyVerifier(verifier);
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
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.Charset;
Expand Down Expand Up @@ -1065,6 +1066,8 @@
return true;
} catch (IOException e) {
throw new IOException("Failed to install " + archive + " to " + remote, e);
} catch (URISyntaxException e) {

Check warning on line 1069 in core/src/main/java/hudson/FilePath.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1069 is not covered by tests
throw new RuntimeException(e);

Check warning on line 1070 in core/src/main/java/hudson/FilePath.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1070 is not covered by tests
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -3337,8 +3340,8 @@

@Restricted(NoExternalUse.class)
static class UrlFactory {
public URL newURL(String location) throws MalformedURLException {
return new URL(location);
public URL newURL(String location) throws MalformedURLException, URISyntaxException {
return new URI(location).toURL();

Check warning on line 3344 in core/src/main/java/hudson/FilePath.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 3344 is not covered by tests
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -1933,18 +1932,21 @@
* @deprecated use {@link JNLPLauncher#getInboundAgentUrl}
*/
@Deprecated
public String getServerName() {
public String getServerName() throws URISyntaxException, MalformedURLException {
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
// Try to infer this from the configured root URL.
// This makes it work correctly when Hudson runs behind a reverse proxy.
String url = Jenkins.get().getRootUrl();
try {
if (url != null) {
String host = new URL(url).getHost();
String host = new URI(url).toURL().getHost();

Check warning on line 1941 in core/src/main/java/hudson/Functions.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1941 is not covered by tests
if (host != null)
return host;
}
} catch (MalformedURLException e) {
// fall back to HTTP request
throw new MalformedURLException();

Check warning on line 1947 in core/src/main/java/hudson/Functions.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1947 is not covered by tests
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
} catch (URISyntaxException e) {

Check warning on line 1948 in core/src/main/java/hudson/Functions.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1948 is not covered by tests
throw new URISyntaxException(e.getReason(), e.getInput());

Check warning on line 1949 in core/src/main/java/hudson/Functions.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1949 is not covered by tests
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
}
return Stapler.getCurrentRequest().getServerName();
}
Expand Down
9 changes: 5 additions & 4 deletions core/src/main/java/hudson/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.Writer;
import java.net.HttpRetryException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -99,11 +100,11 @@
if (!home.endsWith("/")) home = home + '/'; // make sure it ends with '/'

// check for authentication info
String auth = new URL(home).getUserInfo();
String auth = new URI(home).getUserInfo();

Check warning on line 103 in core/src/main/java/hudson/Main.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 103 is not covered by tests
if (auth != null) auth = "Basic " + new Base64Encoder().encode(auth.getBytes(StandardCharsets.UTF_8));

{ // check if the home is set correctly
HttpURLConnection con = open(new URL(home));
HttpURLConnection con = open(new URI(home).toURL());

Check warning on line 107 in core/src/main/java/hudson/Main.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 107 is not covered by tests
if (auth != null) con.setRequestProperty("Authorization", auth);
con.connect();
if (con.getResponseCode() != 200
Expand All @@ -113,7 +114,7 @@
}
}

URL jobURL = new URL(home + "job/" + Util.encode(projectName).replace("/", "/job/") + "/");
URL jobURL = new URI(home + "job/" + Util.encode(projectName).replace("/", "/job/") + "/").toURL();

Check warning on line 117 in core/src/main/java/hudson/Main.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 117 is not covered by tests

{ // check if the job name is correct
HttpURLConnection con = open(new URL(jobURL, "acceptBuildResult"));
Expand Down Expand Up @@ -193,7 +194,7 @@
} catch (HttpRetryException e) {
if (e.getLocation() != null) {
// retry with the new location
location = new URL(e.getLocation());
location = new URI(e.getLocation()).toURL();

Check warning on line 197 in core/src/main/java/hudson/Main.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 197 is not covered by tests
continue;
}
// otherwise failed for reasons beyond us.
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@

@Override
public void copy(File target) throws Exception {
try (InputStream input = ProxyConfiguration.getInputStream(new URL(url))) {
try (InputStream input = ProxyConfiguration.getInputStream(new URI(url).toURL())) {
Files.copy(input, target.toPath());
}
}
Expand Down Expand Up @@ -1942,10 +1942,10 @@
}

@Restricted(NoExternalUse.class)
@RequirePOST public FormValidation doCheckPluginUrl(StaplerRequest request, @QueryParameter String value) throws IOException {
@RequirePOST public FormValidation doCheckPluginUrl(StaplerRequest request, @QueryParameter String value) throws IOException, URISyntaxException {
if (StringUtils.isNotBlank(value)) {
try {
URL url = new URL(value);
URL url = new URI(value).toURL();

Check warning on line 1948 in core/src/main/java/hudson/PluginManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1948 is not covered by tests
if (!url.getProtocol().startsWith("http")) {
return FormValidation.error(Messages.PluginManager_invalidUrl());
}
Expand All @@ -1955,6 +1955,8 @@
}
} catch (MalformedURLException e) {
return FormValidation.error(e.getMessage());
} catch (URISyntaxException e) {

Check warning on line 1958 in core/src/main/java/hudson/PluginManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1958 is not covered by tests
throw new URISyntaxException(e.getReason(), e.getInput());

Check warning on line 1959 in core/src/main/java/hudson/PluginManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1959 is not covered by tests
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
}
}
return FormValidation.ok();
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/java/hudson/TcpSlaveAgentListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.channels.ServerSocketChannel;
import java.nio.charset.StandardCharsets;
import java.security.interfaces.RSAPublicKey;
Expand Down Expand Up @@ -130,14 +131,16 @@
* Gets the host name that we advertise protocol clients to connect to.
* @since 2.198
*/
public String getAdvertisedHost() {
public String getAdvertisedHost() throws URISyntaxException {
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
if (CLI_HOST_NAME != null) {
return CLI_HOST_NAME;
}
try {
return new URL(Jenkins.get().getRootUrl()).getHost();
return new URI(Jenkins.get().getRootUrl()).toURL().getHost();

Check warning on line 139 in core/src/main/java/hudson/TcpSlaveAgentListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 139 is not covered by tests
} catch (MalformedURLException e) {
throw new IllegalStateException("Could not get TcpSlaveAgentListener host name", e);
} catch (URISyntaxException e) {

Check warning on line 142 in core/src/main/java/hudson/TcpSlaveAgentListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 142 is not covered by tests
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
throw new URISyntaxException(e.getReason(), e.getInput());

Check warning on line 143 in core/src/main/java/hudson/TcpSlaveAgentListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 143 is not covered by tests
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/cli/InstallPluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import hudson.util.VersionNumber;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
Expand Down Expand Up @@ -104,7 +105,7 @@

// is this an URL?
try {
URL u = new URL(source);
URL u = new URI(source).toURL();

Check warning on line 108 in core/src/main/java/hudson/cli/InstallPluginCommand.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 108 is not covered by tests
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromUrl(u));
File f = getTmpFile();
FileUtils.copyURLToFile(u, f); // TODO JENKINS-58248 proxy
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/DownloadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
Expand Down Expand Up @@ -388,7 +389,7 @@ public FormValidation updateNow() throws IOException {
}
String jsonString;
try {
jsonString = loadJSONHTML(new URL(site + ".html?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8)));
jsonString = loadJSONHTML(new URI(site + ".html?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8)).toURL());
toolInstallerMetadataExists = true;
} catch (Exception e) {
LOGGER.log(Level.FINE, "Could not load json from " + site, e);
Expand Down
38 changes: 28 additions & 10 deletions core/src/main/java/hudson/model/UpdateCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import java.net.HttpRetryException;
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.net.UnknownHostException;
Expand Down Expand Up @@ -1206,8 +1208,8 @@
* that is assumed to be always available.
* @throws IOException if a connection can't be established
*/
public void checkConnection(ConnectionCheckJob job, String connectionCheckUrl) throws IOException {
testConnection(new URL(connectionCheckUrl));
public void checkConnection(ConnectionCheckJob job, String connectionCheckUrl) throws IOException, URISyntaxException {
testConnection(new URI(connectionCheckUrl).toURL());
}

/**
Expand All @@ -1217,7 +1219,7 @@
* @param updateCenterUrl A sting containing the URL of the update center host.
* @throws IOException if a connection to the update center server can't be established.
*/
public void checkUpdateCenter(ConnectionCheckJob job, String updateCenterUrl) throws IOException {
public void checkUpdateCenter(ConnectionCheckJob job, String updateCenterUrl) throws IOException, URISyntaxException {
testConnection(toUpdateCenterCheckUrl(updateCenterUrl));
}

Expand All @@ -1227,12 +1229,12 @@
* @return the converted URL.
* @throws MalformedURLException if the supplied URL is malformed.
*/
static URL toUpdateCenterCheckUrl(String updateCenterUrl) throws MalformedURLException {
static URL toUpdateCenterCheckUrl(String updateCenterUrl) throws MalformedURLException, URISyntaxException {
URL url;
if (updateCenterUrl.startsWith("http://") || updateCenterUrl.startsWith("https://")) {
url = new URL(updateCenterUrl + (updateCenterUrl.indexOf('?') == -1 ? "?uctest" : "&uctest"));
url = new URI(updateCenterUrl + (updateCenterUrl.indexOf('?') == -1 ? "?uctest" : "&uctest")).toURL();
} else {
url = new URL(updateCenterUrl);
url = new URI(updateCenterUrl).toURL();
}
return url;
}
Expand Down Expand Up @@ -2193,7 +2195,11 @@

@Override
protected URL getURL() throws MalformedURLException {
return new URL(plugin.url);
try {
return new URI(plugin.url).toURL();
} catch (URISyntaxException e) {

Check warning on line 2200 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2200 is not covered by tests
throw new RuntimeException(e);

Check warning on line 2201 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2201 is not covered by tests
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
Expand Down Expand Up @@ -2422,7 +2428,11 @@

@Override
protected URL getURL() throws MalformedURLException {
return new URL(plugin.url);
try {
return new URI(plugin.url).toURL();

Check warning on line 2432 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2432 is not covered by tests
} catch (MalformedURLException | URISyntaxException e) {

Check warning on line 2433 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2433 is not covered by tests
throw new RuntimeException(e);

Check warning on line 2434 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2434 is not covered by tests
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
abhishekmaity marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
Expand Down Expand Up @@ -2517,7 +2527,11 @@
if (site == null) {
throw new MalformedURLException("no update site defined");
}
return new URL(site.getData().core.url);
try {
return new URI(site.getData().core.url).toURL();

Check warning on line 2531 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2531 is not covered by tests
} catch (URISyntaxException e) {

Check warning on line 2532 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2532 is not covered by tests
throw new RuntimeException(e);

Check warning on line 2533 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2533 is not covered by tests
}
}

@Override
Expand Down Expand Up @@ -2564,7 +2578,11 @@
if (site == null) {
throw new MalformedURLException("no update site defined");
}
return new URL(site.getData().core.url);
try {
return new URI(site.getData().core.url).toURL();

Check warning on line 2582 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2582 is not covered by tests
} catch (URISyntaxException e) {

Check warning on line 2583 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2583 is not covered by tests
throw new RuntimeException(e);

Check warning on line 2584 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2584 is not covered by tests
}
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/hudson/model/UpdateSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
Expand Down Expand Up @@ -215,7 +215,11 @@

@Restricted(NoExternalUse.class)
public @NonNull FormValidation updateDirectlyNow(boolean signatureCheck) throws IOException {
return updateData(DownloadService.loadJSON(new URL(getUrl() + "?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8))), signatureCheck);
try {
return updateData(DownloadService.loadJSON(new URI(getUrl() + "?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8)).toURL()), signatureCheck);
} catch (URISyntaxException e) {

Check warning on line 220 in core/src/main/java/hudson/model/UpdateSite.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 220 is not covered by tests
throw new RuntimeException(e);

Check warning on line 221 in core/src/main/java/hudson/model/UpdateSite.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 221 is not covered by tests
}
}

private FormValidation updateData(String json, boolean signatureCheck)
Expand Down
Loading
Loading