You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/11/16 13:42:14 UTC
[tomcat] branch 9.0.x updated: Java 20 deprecates all the URL constructors.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 221d28822a Java 20 deprecates all the URL constructors.
221d28822a is described below
commit 221d28822a334cdf4acb7b4240a9233ef9b9db05
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Nov 16 13:41:47 2022 +0000
Java 20 deprecates all the URL constructors.
The recommendation is to use URI instead (better input validation)
Start the refactoring process.
---
java/org/apache/catalina/ant/AbstractCatalinaTask.java | 13 +++++++++----
java/org/apache/catalina/ant/DeployTask.java | 9 +++++----
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/java/org/apache/catalina/ant/AbstractCatalinaTask.java b/java/org/apache/catalina/ant/AbstractCatalinaTask.java
index c1457afbe5..75676e2960 100644
--- a/java/org/apache/catalina/ant/AbstractCatalinaTask.java
+++ b/java/org/apache/catalina/ant/AbstractCatalinaTask.java
@@ -23,7 +23,8 @@ import java.io.OutputStream;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URLConnection;
import org.apache.catalina.util.IOTools;
@@ -179,7 +180,9 @@ public abstract class AbstractCatalinaTask extends BaseRedirectorHelperTask {
Authenticator.setDefault(new TaskAuthenticator(username, password));
// Create a connection for this command
- conn = (new URL(url + command)).openConnection();
+ URI uri = new URI(url + command);
+ uri.parseServerAuthority();
+ conn = uri.toURL().openConnection();
HttpURLConnection hconn = (HttpURLConnection) conn;
// Set up standard connection characteristics
@@ -300,11 +303,13 @@ public abstract class AbstractCatalinaTask extends BaseRedirectorHelperTask {
* host is cached and used to provide an appropriate Authorization when the
* next request is made (that includes a request body).
*/
- private void preAuthenticate() throws IOException {
+ private void preAuthenticate() throws IOException, URISyntaxException {
URLConnection conn = null;
// Create a connection for this command
- conn = (new URL(url)).openConnection();
+ URI uri = new URI(url);
+ uri.parseServerAuthority();
+ conn = uri.toURL().openConnection();
HttpURLConnection hconn = (HttpURLConnection) conn;
// Set up standard connection characteristics
diff --git a/java/org/apache/catalina/ant/DeployTask.java b/java/org/apache/catalina/ant/DeployTask.java
index 54cb8a0c59..bf4bc673e9 100644
--- a/java/org/apache/catalina/ant/DeployTask.java
+++ b/java/org/apache/catalina/ant/DeployTask.java
@@ -20,7 +20,8 @@ import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.channels.FileChannel;
@@ -132,11 +133,11 @@ public class DeployTask extends AbstractCatalinaCommandTask {
if (war != null) {
if (PROTOCOL_PATTERN.matcher(war).lookingAt()) {
try {
- URL url = new URL(war);
- URLConnection conn = url.openConnection();
+ URI uri = new URI(war);
+ URLConnection conn = uri.toURL().openConnection();
contentLength = conn.getContentLengthLong();
stream = new BufferedInputStream(conn.getInputStream(), 1024);
- } catch (IOException e) {
+ } catch (IOException | URISyntaxException e) {
throw new BuildException(e);
}
} else {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org