This is an automated email from the ASF dual-hosted git repository.
rmaucher 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 1351979308 Minor fixes from code review
1351979308 is described below
commit 13519793081007fc7cee9b99887d54f3a91b3db2
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 97322edfaa..001b696468 100644
--- a/java/org/apache/catalina/WebResource.java
+++ b/java/org/apache/catalina/WebResource.java
@@ -192,7 +192,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()
*/
@@ -201,7 +201,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 d35cc8f7c7..07c0415508 100644
--- a/java/org/apache/catalina/webresources/AbstractArchiveResource.java
+++ b/java/org/apache/catalina/webresources/AbstractArchiveResource.java
@@ -205,7 +205,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)));
}
@@ -230,6 +230,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 46cfe8552f..a41ecf826b 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 39c7c6fa4d..9276093358 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 0c2db082b6..c807d9fbc2 100644
---
a/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
+++
b/java/org/apache/catalina/webresources/AbstractSingleArchiveResourceSet.java
@@ -52,11 +52,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);
@@ -66,7 +66,7 @@ public abstract class AbstractSingleArchiveResourceSet
extends AbstractArchiveRe
try {
start();
} catch (LifecycleException e) {
- throw new IllegalStateException(e);
+ throw new
IllegalStateException(sm.getString("abstractArchiveResourceSet.startFail"), e);
}
}
}
@@ -88,7 +88,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();
@@ -108,7 +109,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();
@@ -128,7 +130,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();
@@ -149,13 +152,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 (MalformedURLException e) {
- throw new IllegalArgumentException(e);
+ throw new LifecycleException(
+ sm.getString("abstractArchiveResourceSet.baseUrlFail",
getBase()), e);
}
}
}
diff --git a/java/org/apache/catalina/webresources/CachedResource.java
b/java/org/apache/catalina/webresources/CachedResource.java
index 72a700b395..65be0f9c21 100644
--- a/java/org/apache/catalina/webresources/CachedResource.java
+++ b/java/org/apache/catalina/webresources/CachedResource.java
@@ -523,7 +523,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 ca62e929ed..7a31559703 100644
--- a/java/org/apache/catalina/webresources/DirResourceSet.java
+++ b/java/org/apache/catalina/webresources/DirResourceSet.java
@@ -90,7 +90,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 5986a43a7b..5de2499368 100644
--- a/java/org/apache/catalina/webresources/JarWarResourceSet.java
+++ b/java/org/apache/catalina/webresources/JarWarResourceSet.java
@@ -70,7 +70,7 @@ public class JarWarResourceSet extends
AbstractArchiveResourceSet {
try {
start();
} catch (LifecycleException e) {
- throw new IllegalStateException(e);
+ throw new
IllegalStateException(sm.getString("jarWarResourceSet.startFail"), e);
}
}
}
@@ -134,7 +134,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();
@@ -257,13 +258,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 (MalformedURLException e) {
- throw new IllegalArgumentException(e);
+ throw new
LifecycleException(sm.getString("jarWarResourceSet.baseUrlFail", getBase()), e);
}
}
diff --git a/java/org/apache/catalina/webresources/LocalStrings.properties
b/java/org/apache/catalina/webresources/LocalStrings.properties
index 4afbc2a210..0ad77fb288 100644
--- a/java/org/apache/catalina/webresources/LocalStrings.properties
+++ b/java/org/apache/catalina/webresources/LocalStrings.properties
@@ -17,9 +17,16 @@
# To edit translations see:
https://tomcat.apache.org/getinvolved.html#Translations
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
@@ -34,6 +41,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
@@ -43,6 +51,7 @@ dirResourceSet.canonCaches.enabled=Unable to disable the
global canonical file n
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}]
@@ -53,16 +62,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 df0fe55916..4e52668c16 100644
--- a/java/org/apache/catalina/webresources/StandardRoot.java
+++ b/java/org/apache/catalina/webresources/StandardRoot.java
@@ -898,7 +898,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) {
@@ -910,7 +911,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]