This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 77f98c1c3c Final URL -> URI refactoring
77f98c1c3c is described below

commit 77f98c1c3c6397066ed9be01fad3834c71cc3a0a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Nov 16 19:19:43 2022 +0000

    Final URL -> URI refactoring
    
    These require API changes so no plans to back-port.
---
 .../AbstractSingleArchiveResourceSet.java            |  3 +--
 .../catalina/webresources/JarWarResourceSet.java     |  3 +--
 java/org/apache/tomcat/util/scan/JarFactory.java     | 14 ++++++++++----
 .../apache/tomcat/util/buf/TesterUriUtilBase.java    | 20 ++++++++++----------
 4 files changed, 22 insertions(+), 18 deletions(-)

diff --git 
a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java 
b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
index 5edf114f77..688e2128ae 100644
--- 
a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
+++ 
b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
@@ -18,7 +18,6 @@ package org.apache.catalina.webresources;
 
 import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
@@ -144,7 +143,7 @@ public abstract class AbstractSingleArchiveResourceSet 
extends AbstractArchiveRe
 
         try {
             setBaseUrl(UriUtil.buildJarSafeUrl(new File(getBase())));
-        } catch (MalformedURLException e) {
+        } catch (IOException e) {
             throw new IllegalArgumentException(e);
         }
     }
diff --git a/java/org/apache/catalina/webresources/JarWarResourceSet.java 
b/java/org/apache/catalina/webresources/JarWarResourceSet.java
index 37253fc390..215cf3b07f 100644
--- a/java/org/apache/catalina/webresources/JarWarResourceSet.java
+++ b/java/org/apache/catalina/webresources/JarWarResourceSet.java
@@ -19,7 +19,6 @@ package org.apache.catalina.webresources;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -250,7 +249,7 @@ public class JarWarResourceSet extends 
AbstractArchiveResourceSet {
 
         try {
             setBaseUrl(UriUtil.buildJarSafeUrl(new File(getBase())));
-        } catch (MalformedURLException e) {
+        } catch (IOException e) {
             throw new IllegalArgumentException(e);
         }
     }
diff --git a/java/org/apache/tomcat/util/scan/JarFactory.java 
b/java/org/apache/tomcat/util/scan/JarFactory.java
index 51c0011ed1..ec6a438ad8 100644
--- a/java/org/apache/tomcat/util/scan/JarFactory.java
+++ b/java/org/apache/tomcat/util/scan/JarFactory.java
@@ -17,7 +17,8 @@
 package org.apache.tomcat.util.scan;
 
 import java.io.IOException;
-import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.regex.Matcher;
 
@@ -53,8 +54,7 @@ public class JarFactory {
     }
 
 
-    public static URL getJarEntryURL(URL baseUrl, String entryName)
-            throws MalformedURLException {
+    public static URL getJarEntryURL(URL baseUrl, String entryName) throws 
IOException {
 
         String baseExternal = baseUrl.toExternalForm();
 
@@ -66,6 +66,12 @@ public class JarFactory {
                     Matcher.quoteReplacement(UriUtil.getWarSeparator()));
         }
 
-        return new URL("jar:" + baseExternal + "!/" + entryName);
+        URI uri;
+        try {
+            uri = new URI("jar:" + baseExternal + "!/" + entryName);
+        } catch (URISyntaxException e) {
+            throw new IOException(e);
+        }
+        return uri.toURL();
     }
 }
diff --git a/test/org/apache/tomcat/util/buf/TesterUriUtilBase.java 
b/test/org/apache/tomcat/util/buf/TesterUriUtilBase.java
index b176788bf4..9980669aa2 100644
--- a/test/org/apache/tomcat/util/buf/TesterUriUtilBase.java
+++ b/test/org/apache/tomcat/util/buf/TesterUriUtilBase.java
@@ -17,7 +17,7 @@
 package org.apache.tomcat.util.buf;
 
 import java.io.File;
-import java.net.MalformedURLException;
+import java.io.IOException;
 import java.net.URL;
 
 import org.junit.Assert;
@@ -37,7 +37,7 @@ public abstract class TesterUriUtilBase {
 
 
     @Test
-    public void testBuildJarUrl01() throws MalformedURLException {
+    public void testBuildJarUrl01() throws IOException {
         File jarFile = new File("/patha/pathb!/pathc");
         String result = UriUtil.buildJarUrl(jarFile).toString();
 
@@ -47,7 +47,7 @@ public abstract class TesterUriUtilBase {
 
 
     @Test
-    public void testBuildJarUrl02() throws MalformedURLException {
+    public void testBuildJarUrl02() throws IOException {
         File jarFile = new File("/patha/pathb*/pathc");
         String result = UriUtil.buildJarUrl(jarFile).toString();
 
@@ -60,7 +60,7 @@ public abstract class TesterUriUtilBase {
 
 
     @Test
-    public void testBuildJarUrl03() throws MalformedURLException {
+    public void testBuildJarUrl03() throws IOException {
         File jarFile = new File("/patha/pathb^/pathc");
         String result = UriUtil.buildJarUrl(jarFile).toString();
 
@@ -73,7 +73,7 @@ public abstract class TesterUriUtilBase {
 
 
     @Test
-    public void testBuildJarUrl04() throws MalformedURLException {
+    public void testBuildJarUrl04() throws IOException {
         File jarFile = new File("/patha/pathb" + separator + "/pathc");
         String result = UriUtil.buildJarUrl(jarFile).toString();
 
@@ -86,24 +86,24 @@ public abstract class TesterUriUtilBase {
 
 
     @Test
-    public void testWarToJar01() throws MalformedURLException {
+    public void testWarToJar01() throws IOException {
         doTestWarToJar("^");
     }
 
 
     @Test
-    public void testWarToJar02() throws MalformedURLException {
+    public void testWarToJar02() throws IOException {
         doTestWarToJar("*");
     }
 
 
     @Test
-    public void testWarToJar03() throws MalformedURLException {
+    public void testWarToJar03() throws IOException {
         doTestWarToJar(separator);
     }
 
 
-    private void doTestWarToJar(String separator) throws MalformedURLException 
{
+    private void doTestWarToJar(String separator) throws IOException {
         URL warUrl = new URL("war:file:/external/path" + separator + 
"/internal/path");
         URL jarUrl = UriUtil.warToJar(warUrl);
         Assert.assertEquals("jar:file:/external/path!/internal/path", 
jarUrl.toString());
@@ -111,7 +111,7 @@ public abstract class TesterUriUtilBase {
 
 
     // @Test /* Uncomment to test performance for different implementations. */
-    public void performanceTestBuildJarUrl() throws MalformedURLException {
+    public void performanceTestBuildJarUrl() throws IOException {
         File jarFile = new File("/patha/pathb^/pathc");
 
         URL url = null;


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to