This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 4b29f8108b Java 20 deprecates all the URL constructors.
4b29f8108b is described below
commit 4b29f8108b6ad1de800134712d1767a10670c03a
Author: Mark Thomas <[email protected]>
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: [email protected]
For additional commands, e-mail: [email protected]