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

rmaucher 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 ebdbc5854e Minor fixes from code review
ebdbc5854e is described below

commit ebdbc5854e7acd9f72241834a5fc69fa3d750518
Author: remm <[email protected]>
AuthorDate: Fri Jul 17 09:13:42 2026 +0200

    Minor fixes from code review
---
 java/org/apache/catalina/WebResource.java           |  4 ++--
 java/org/apache/catalina/WebResourceSet.java        |  3 ++-
 .../tribes/transport/nio/PooledParallelSender.java  |  1 +
 .../webresources/AbstractArchiveResource.java       |  6 +++++-
 .../webresources/AbstractArchiveResourceSet.java    |  1 +
 .../webresources/AbstractFileResourceSet.java       |  3 ++-
 .../catalina/webresources/AbstractResource.java     | 18 +++++++++++-------
 .../AbstractSingleArchiveResourceSet.java           | 21 +++++++++++++--------
 .../catalina/webresources/CachedResource.java       |  2 +-
 .../catalina/webresources/DirResourceSet.java       |  2 +-
 .../apache/catalina/webresources/EmptyResource.java |  2 +-
 .../catalina/webresources/EmptyResourceSet.java     |  3 ++-
 .../catalina/webresources/FileResourceSet.java      |  2 +-
 .../catalina/webresources/JarWarResourceSet.java    | 10 ++++++----
 .../catalina/webresources/LocalStrings.properties   | 16 ++++++++++++++++
 .../apache/catalina/webresources/StandardRoot.java  |  6 ++++--
 16 files changed, 69 insertions(+), 31 deletions(-)

diff --git a/java/org/apache/catalina/WebResource.java 
b/java/org/apache/catalina/WebResource.java
index eef127c437..1f370ae3bc 100644
--- a/java/org/apache/catalina/WebResource.java
+++ b/java/org/apache/catalina/WebResource.java
@@ -199,7 +199,7 @@ public interface WebResource {
     /**
      * Returns the certificates that were used to sign this resource to verify 
it.
      *
-     * @return the certificates that were used to sign this resource to verify 
it or @null if none.
+     * @return the certificates that were used to sign this resource to verify 
it or {@code null} if none.
      *
      * @see java.util.jar.JarEntry#getCertificates()
      */
@@ -208,7 +208,7 @@ public interface WebResource {
     /**
      * Returns the manifest associated with this resource.
      *
-     * @return the manifest associated with this resource or @null if none.
+     * @return the manifest associated with this resource or {@code null} if 
none.
      *
      * @see java.util.jar.JarFile#getManifest()
      */
diff --git a/java/org/apache/catalina/WebResourceSet.java 
b/java/org/apache/catalina/WebResourceSet.java
index e06f04682a..75f022f577 100644
--- a/java/org/apache/catalina/WebResourceSet.java
+++ b/java/org/apache/catalina/WebResourceSet.java
@@ -71,7 +71,8 @@ public interface WebResourceSet extends Lifecycle {
      *
      * @param path      The path to be used for the new Resource. It is 
relative to the root of the web application and
      *                      must start with '/'.
-     * @param is        The InputStream that will provide the content for the 
new Resource.
+     * @param is        The InputStream that will provide the content for the 
new Resource. The caller is responsible
+     *                  for closing the stream if required.
      * @param overwrite If <code>true</code> and the resource already exists 
it will be overwritten. If
      *                      <code>false</code> and the resource already exists 
the write will fail.
      *
diff --git 
a/java/org/apache/catalina/tribes/transport/nio/PooledParallelSender.java 
b/java/org/apache/catalina/tribes/transport/nio/PooledParallelSender.java
index 36f26b75f6..45a69a4b9b 100644
--- a/java/org/apache/catalina/tribes/transport/nio/PooledParallelSender.java
+++ b/java/org/apache/catalina/tribes/transport/nio/PooledParallelSender.java
@@ -32,6 +32,7 @@ import org.apache.juli.logging.LogFactory;
  */
 public class PooledParallelSender extends PooledSender implements 
PooledParallelSenderMBean {
     private static final Log log = 
LogFactory.getLog(PooledParallelSender.class);
+    /** StringManager for internationalized log messages. */
     protected static final StringManager sm = 
StringManager.getManager(PooledParallelSender.class);
 
     /**
diff --git a/java/org/apache/catalina/webresources/AbstractArchiveResource.java 
b/java/org/apache/catalina/webresources/AbstractArchiveResource.java
index 8e923baf35..f206d6e1d6 100644
--- a/java/org/apache/catalina/webresources/AbstractArchiveResource.java
+++ b/java/org/apache/catalina/webresources/AbstractArchiveResource.java
@@ -219,7 +219,7 @@ public abstract class AbstractArchiveResource extends 
AbstractResource {
 
         if (len > Integer.MAX_VALUE) {
             // Can't create an array that big
-            throw new ArrayIndexOutOfBoundsException(
+            throw new IllegalStateException(
                     sm.getString("abstractResource.getContentTooLarge", 
getWebappPath(), Long.valueOf(len)));
         }
 
@@ -244,6 +244,10 @@ public abstract class AbstractArchiveResource extends 
AbstractResource {
                 }
                 pos += n;
             }
+            if (pos < size) {
+                // Stream ended before expected size — return null to avoid 
partial data
+                return null;
+            }
             // Once the stream has been read, read the certs
             certificates = jisw.getCertificates();
             readCerts = true;
diff --git 
a/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java 
b/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
index f71f3cb809..3b3ce1c210 100644
--- a/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
+++ b/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java
@@ -356,6 +356,7 @@ public abstract class AbstractArchiveResourceSet extends 
AbstractResourceSet {
      */
     @Override
     public void setAllowLinking(boolean allowLinking) {
+        // NO-OP
     }
 
     /**
diff --git a/java/org/apache/catalina/webresources/AbstractFileResourceSet.java 
b/java/org/apache/catalina/webresources/AbstractFileResourceSet.java
index 474263c28b..d1da47776c 100644
--- a/java/org/apache/catalina/webresources/AbstractFileResourceSet.java
+++ b/java/org/apache/catalina/webresources/AbstractFileResourceSet.java
@@ -286,7 +286,8 @@ public abstract class AbstractFileResourceSet extends 
AbstractResourceSet {
         try {
             this.canonicalBase = fileBase.getCanonicalPath();
         } catch (IOException ioe) {
-            throw new IllegalArgumentException(ioe);
+            throw new LifecycleException(
+                    sm.getString("abstractFileResourceSet.canonicalPathFail", 
getBase()), ioe);
         }
 
         // Need to handle mapping of the file system root as a special case
diff --git a/java/org/apache/catalina/webresources/AbstractResource.java 
b/java/org/apache/catalina/webresources/AbstractResource.java
index 686078f43a..eb1ecda85d 100644
--- a/java/org/apache/catalina/webresources/AbstractResource.java
+++ b/java/org/apache/catalina/webresources/AbstractResource.java
@@ -138,15 +138,19 @@ public abstract class AbstractResource implements 
WebResource {
                         } else {
                             byte[] buf = new byte[4096];
                             try (InputStream is = getInputStream()) {
-                                MessageDigest digest = 
MessageDigest.getInstance("SHA-256");
-                                while (true) {
-                                    int n = is.read(buf);
-                                    if (n <= 0) {
-                                        break;
+                                if (is == null) {
+                                    strongETag = getETag();
+                                } else {
+                                    MessageDigest digest = 
MessageDigest.getInstance("SHA-256");
+                                    while (true) {
+                                        int n = is.read(buf);
+                                        if (n <= 0) {
+                                            break;
+                                        }
+                                        digest.update(buf, 0, n);
                                     }
-                                    digest.update(buf, 0, n);
+                                    strongETag = "\"" + 
HexUtils.toHexString(digest.digest()) + "\"";
                                 }
-                                strongETag = "\"" + 
HexUtils.toHexString(digest.digest()) + "\"";
                             } catch (Exception e) {
                                 strongETag = getETag();
                             }
diff --git 
a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java 
b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
index 9fa79f7ca1..2e1764a12c 100644
--- 
a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
+++ 
b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
@@ -51,11 +51,11 @@ public abstract class AbstractSingleArchiveResourceSet 
extends AbstractArchiveRe
      * @param base         The base
      * @param internalPath The internal path
      *
-     * @throws IllegalArgumentException if the {@link WebResourceRoot} is 
available but this resource set cannot be
+     * @throws IllegalStateException if the {@link WebResourceRoot} is 
available but this resource set cannot be
      *                                      started
      */
     public AbstractSingleArchiveResourceSet(WebResourceRoot root, String 
webAppMount, String base, String internalPath)
-            throws IllegalArgumentException {
+            throws IllegalStateException {
         setRoot(root);
         setWebAppMount(webAppMount);
         setBase(base);
@@ -65,7 +65,7 @@ public abstract class AbstractSingleArchiveResourceSet 
extends AbstractArchiveRe
             try {
                 start();
             } catch (LifecycleException e) {
-                throw new IllegalStateException(e);
+                throw new 
IllegalStateException(sm.getString("abstractArchiveResourceSet.startFail"), e);
             }
         }
     }
@@ -87,7 +87,8 @@ public abstract class AbstractSingleArchiveResourceSet 
extends AbstractArchiveRe
                 } catch (IOException ioe) {
                     // Should never happen
                     archiveEntries = null;
-                    throw new IllegalStateException(ioe);
+                    throw new IllegalStateException(
+                            
sm.getString("abstractArchiveResourceSet.archiveEntriesFail", getBase()), ioe);
                 } finally {
                     if (jarFile != null) {
                         closeJarFile();
@@ -107,7 +108,8 @@ public abstract class AbstractSingleArchiveResourceSet 
extends AbstractArchiveRe
             return jarFile.getJarEntry(pathInArchive);
         } catch (IOException ioe) {
             // Should never happen
-            throw new IllegalStateException(ioe);
+            throw new IllegalStateException(
+                    
sm.getString("abstractArchiveResourceSet.archiveEntryFail", getBase()), ioe);
         } finally {
             if (jarFile != null) {
                 closeJarFile();
@@ -127,7 +129,8 @@ public abstract class AbstractSingleArchiveResourceSet 
extends AbstractArchiveRe
                         multiRelease = 
Boolean.valueOf(jarFile.isMultiRelease());
                     } catch (IOException ioe) {
                         // Should never happen
-                        throw new IllegalStateException(ioe);
+                        throw new IllegalStateException(
+                                
sm.getString("abstractArchiveResourceSet.multiReleaseFail", getBase()), ioe);
                     } finally {
                         if (jarFile != null) {
                             closeJarFile();
@@ -148,13 +151,15 @@ public abstract class AbstractSingleArchiveResourceSet 
extends AbstractArchiveRe
         try (JarFile jarFile = new JarFile(new File(getBase()), true, 
ZipFile.OPEN_READ, Runtime.version())) {
             setManifest(jarFile.getManifest());
         } catch (IOException ioe) {
-            throw new IllegalArgumentException(ioe);
+            throw new LifecycleException(
+                    sm.getString("abstractArchiveResourceSet.manifestFail", 
getBase()), ioe);
         }
 
         try {
             setBaseUrl(UriUtil.buildJarSafeUrl(new File(getBase())));
         } catch (IOException ioe) {
-            throw new IllegalArgumentException(ioe);
+            throw new LifecycleException(
+                    sm.getString("abstractArchiveResourceSet.baseUrlFail", 
getBase()), ioe);
         }
     }
 }
diff --git a/java/org/apache/catalina/webresources/CachedResource.java 
b/java/org/apache/catalina/webresources/CachedResource.java
index 2d79c6c9ad..9f401058d9 100644
--- a/java/org/apache/catalina/webresources/CachedResource.java
+++ b/java/org/apache/catalina/webresources/CachedResource.java
@@ -524,7 +524,7 @@ public class CachedResource implements WebResource {
                     constructedURI = new URI(u.toExternalForm());
                 } catch (URISyntaxException e) {
                     // Not ideal but consistent with API
-                    throw new IOException(e);
+                    throw new 
IOException(sm.getString("cachedResource.invalidURI", u.toExternalForm()), e);
                 }
                 URL constructedURL = constructedURI.toURL();
                 return constructedURL.openConnection();
diff --git a/java/org/apache/catalina/webresources/DirResourceSet.java 
b/java/org/apache/catalina/webresources/DirResourceSet.java
index 9ebb76a07a..92ebe82498 100644
--- a/java/org/apache/catalina/webresources/DirResourceSet.java
+++ b/java/org/apache/catalina/webresources/DirResourceSet.java
@@ -89,7 +89,7 @@ public class DirResourceSet extends AbstractFileResourceSet 
implements WebResour
             try {
                 start();
             } catch (LifecycleException e) {
-                throw new IllegalStateException(e);
+                throw new 
IllegalStateException(sm.getString("dirResourceSet.startFail"), e);
             }
         }
     }
diff --git a/java/org/apache/catalina/webresources/EmptyResource.java 
b/java/org/apache/catalina/webresources/EmptyResource.java
index 094fa3be33..9d66d1ee7a 100644
--- a/java/org/apache/catalina/webresources/EmptyResource.java
+++ b/java/org/apache/catalina/webresources/EmptyResource.java
@@ -139,7 +139,7 @@ public class EmptyResource implements WebResource {
 
     @Override
     public void setMimeType(String mimeType) {
-        // NOOP
+        // NO-OP
     }
 
     @Override
diff --git a/java/org/apache/catalina/webresources/EmptyResourceSet.java 
b/java/org/apache/catalina/webresources/EmptyResourceSet.java
index 05993e6484..9dc61a2344 100644
--- a/java/org/apache/catalina/webresources/EmptyResourceSet.java
+++ b/java/org/apache/catalina/webresources/EmptyResourceSet.java
@@ -142,7 +142,7 @@ public class EmptyResourceSet extends LifecycleBase 
implements WebResourceSet {
      */
     @Override
     public void setReadOnly(boolean readOnly) {
-
+        // NO-OP
     }
 
     /**
@@ -152,6 +152,7 @@ public class EmptyResourceSet extends LifecycleBase 
implements WebResourceSet {
      */
     @Override
     public void setAllowLinking(boolean allowLinking) {
+        // NO-OP
     }
 
     /**
diff --git a/java/org/apache/catalina/webresources/FileResourceSet.java 
b/java/org/apache/catalina/webresources/FileResourceSet.java
index 93f0aab504..1642e607c6 100644
--- a/java/org/apache/catalina/webresources/FileResourceSet.java
+++ b/java/org/apache/catalina/webresources/FileResourceSet.java
@@ -59,7 +59,7 @@ public class FileResourceSet extends AbstractFileResourceSet {
             try {
                 start();
             } catch (LifecycleException e) {
-                throw new IllegalStateException(e);
+                throw new 
IllegalStateException(sm.getString("fileResourceSet.startFail"), e);
             }
         }
     }
diff --git a/java/org/apache/catalina/webresources/JarWarResourceSet.java 
b/java/org/apache/catalina/webresources/JarWarResourceSet.java
index 7e6dacda8e..6bf9ccdd33 100644
--- a/java/org/apache/catalina/webresources/JarWarResourceSet.java
+++ b/java/org/apache/catalina/webresources/JarWarResourceSet.java
@@ -69,7 +69,7 @@ public class JarWarResourceSet extends 
AbstractArchiveResourceSet {
             try {
                 start();
             } catch (LifecycleException e) {
-                throw new IllegalStateException(e);
+                throw new 
IllegalStateException(sm.getString("jarWarResourceSet.startFail"), e);
             }
         }
     }
@@ -133,7 +133,8 @@ public class JarWarResourceSet extends 
AbstractArchiveResourceSet {
                 } catch (IOException ioe) {
                     // Should never happen
                     archiveEntries = null;
-                    throw new IllegalStateException(ioe);
+                    throw new IllegalStateException(
+                            
sm.getString("jarWarResourceSet.archiveEntriesFail", archivePath, getBase()), 
ioe);
                 } finally {
                     if (warFile != null) {
                         closeJarFile();
@@ -256,13 +257,14 @@ public class JarWarResourceSet extends 
AbstractArchiveResourceSet {
                 setManifest(jarIs.getManifest());
             }
         } catch (IOException ioe) {
-            throw new IllegalArgumentException(ioe);
+            throw new LifecycleException(
+                    sm.getString("jarWarResourceSet.manifestFail", 
archivePath, getBase()), ioe);
         }
 
         try {
             setBaseUrl(UriUtil.buildJarSafeUrl(new File(getBase())));
         } catch (IOException ioe) {
-            throw new IllegalArgumentException(ioe);
+            throw new 
LifecycleException(sm.getString("jarWarResourceSet.baseUrlFail", getBase()), 
ioe);
         }
     }
 
diff --git a/java/org/apache/catalina/webresources/LocalStrings.properties 
b/java/org/apache/catalina/webresources/LocalStrings.properties
index 2dac41235d..0b4fd31e22 100644
--- a/java/org/apache/catalina/webresources/LocalStrings.properties
+++ b/java/org/apache/catalina/webresources/LocalStrings.properties
@@ -14,9 +14,16 @@
 # limitations under the License.
 
 abstractArchiveResourceSet.archiveCloseFailed=Error closing archive. Archive 
may still be open.
+abstractArchiveResourceSet.archiveEntriesFail=Failed to read the archive 
entries from [{0}]
+abstractArchiveResourceSet.archiveEntryFail=Failed to obtain an entry from the 
archive [{0}]
+abstractArchiveResourceSet.baseUrlFail=Failed to build the base URL for the 
archive [{0}]
+abstractArchiveResourceSet.manifestFail=Failed to read the manifest from the 
archive [{0}]
+abstractArchiveResourceSet.multiReleaseFail=Failed to determine if the archive 
[{0}] is a multi-release JAR
+abstractArchiveResourceSet.startFail=Failed to start the resource set
 abstractArchiveResourceSet.setReadOnlyFalse=Archive based WebResourceSets such 
as those based on JARs are hard-coded to be read-only and may not be configured 
to be read-write
 
 abstractFileResourceSet.canonicalfileCheckFailed=Resource for web application 
[{0}] at path [{1}] was not loaded as the canonical path [{2}] did not match. 
Use of symlinks is one possible cause.
+abstractFileResourceSet.canonicalPathFail=Failed to determine the canonical 
path for [{0}]
 
 abstractResource.getContentFail=Unable to return [{0}] as a byte array
 abstractResource.getContentFirst=getContent must be called before 
getCertificates
@@ -31,6 +38,7 @@ cache.objectMaxSizeTooBigBytes=The value specified for the 
maximum object size t
 cache.sizeTracking.add=Increased cache size by [{0}] for item [{1}] at [{2}] 
making total cache size [{3}]
 cache.sizeTracking.remove=Decreased cache size by [{0}] for item [{1}] at 
[{2}] making total cache size [{3}]
 
+cachedResource.invalidURI=Unable to construct a URI from the URL [{0}]
 cachedResource.invalidURL=Unable to create an instance of 
CachedResourceURLStreamHandler because the URL [{0}] is malformed
 
 classpathUrlStreamHandler.notFound=Unable to load the resource [{0}] using the 
thread context class loader or the current class''s class loader
@@ -38,6 +46,7 @@ classpathUrlStreamHandler.notFound=Unable to load the 
resource [{0}] using the t
 dirResourceSet.isCaseSensitive.fail=Error trying to determine if file system 
at [{0}] is case sensitive so assuming it is not case sensitive
 dirResourceSet.manifestFail=Failed to read manifest from [{0}]
 dirResourceSet.notDirectory=The directory specified by base and internal path 
[{0}]{1}[{2}] does not exist.
+dirResourceSet.startFail=Failed to start the resource set
 dirResourceSet.writeNpe=The input stream may not be null
 
 extractingRoot.jarFailed=Failed to extract the JAR file [{0}]
@@ -48,16 +57,23 @@ fileResource.getCreationFail=Unable to determine the 
creation time for the resou
 fileResource.getUrlFail=Unable to determine a URL for the resource [{0}]
 
 fileResourceSet.notFile=The file specified by base and internal path 
[{0}]{1}[{2}] does not exist.
+fileResourceSet.startFail=Failed to start the resource set
 
 jarResource.getInputStreamFail=Unable to obtain an InputStream for the 
resource [{0}] located in the JAR [{1}]
 
 jarResourceRoot.invalidWebAppPath=This resource always refers to a directory 
so the supplied webAppPath must end with / but the provided webAppPath was [{0}]
 
+jarWarResourceSet.archiveEntriesFail=Failed to read the archive entries from 
the inner JAR [{0}] located in [{1}]
+jarWarResourceSet.baseUrlFail=Failed to build the base URL for the WAR file 
[{0}]
 jarWarResourceSet.codingError=Coding error
+jarWarResourceSet.manifestFail=Failed to read the manifest from the inner JAR 
[{0}] located in [{1}]
+jarWarResourceSet.startFail=Failed to start the resource set
 
 standardRoot.checkStateNotStarted=The resources may not be accessed if they 
are not currently started
 standardRoot.createInvalidFile=Unable to create WebResourceSet from [{0}]
 standardRoot.createUnknownType=Unable to create WebResourceSet of unknown type 
[{0}]
+standardRoot.invalidFileUrl=The file URL [{0}] has invalid syntax
+standardRoot.invalidJarUrl=The JAR/WAR URL [{0}] has invalid syntax
 standardRoot.invalidPath=The resource path [{0}] is not valid
 standardRoot.invalidPathNormal=The resource path [{0}] has been normalized to 
[{1}] which is not valid
 standardRoot.lockedFile=The web application [{0}] failed to close the file 
[{1}] opened via the following stack trace
diff --git a/java/org/apache/catalina/webresources/StandardRoot.java 
b/java/org/apache/catalina/webresources/StandardRoot.java
index a90e95b40b..ad5e403379 100644
--- a/java/org/apache/catalina/webresources/StandardRoot.java
+++ b/java/org/apache/catalina/webresources/StandardRoot.java
@@ -889,7 +889,8 @@ public class StandardRoot extends LifecycleMBeanBase 
implements WebResourceRoot
                 try {
                     f = new File(new URI(fileUrl));
                 } catch (URISyntaxException e) {
-                    throw new IllegalArgumentException(e);
+                    throw new IllegalArgumentException(
+                            sm.getString("standardRoot.invalidJarUrl", 
fileUrl), e);
                 }
                 int startOfArchivePath = endOfFileUrl + 2;
                 if (jarUrl.length() > startOfArchivePath) {
@@ -901,7 +902,8 @@ public class StandardRoot extends LifecycleMBeanBase 
implements WebResourceRoot
                 try {
                     f = new File(url.toURI());
                 } catch (URISyntaxException e) {
-                    throw new IllegalArgumentException(e);
+                    throw new IllegalArgumentException(
+                            sm.getString("standardRoot.invalidFileUrl", 
url.toExternalForm()), e);
                 }
                 archivePath = null;
             } else {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to