This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 96b8f1220b Review "Log the ignored IOException when storing a child
element fails"
96b8f1220b is described below
commit 96b8f1220b70fe98832d870d600708ad389a8399
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Oct 21 09:19:38 2026 +0100
Review "Log the ignored IOException when storing a child element fails"
Treat a child element failure as a store failure. Better to report
failure than report success when not all elements have been written.
Co-authored by: CoPilot / GPT-5.6 Sol
---
.../catalina/storeconfig/StoreFactoryBase.java | 9 ++++
.../catalina/storeconfig/TestStoreFactoryBase.java | 53 ++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/java/org/apache/catalina/storeconfig/StoreFactoryBase.java
b/java/org/apache/catalina/storeconfig/StoreFactoryBase.java
index 273b1f24a9..e60e1e0046 100644
--- a/java/org/apache/catalina/storeconfig/StoreFactoryBase.java
+++ b/java/org/apache/catalina/storeconfig/StoreFactoryBase.java
@@ -166,6 +166,7 @@ public class StoreFactoryBase implements IStoreFactory {
*/
protected void storeElementArray(PrintWriter aWriter, int indent, Object[]
elements) throws Exception {
if (elements != null) {
+ IOException firstException = null;
for (Object element : elements) {
try {
storeElement(aWriter, indent, element);
@@ -173,8 +174,16 @@ public class StoreFactoryBase implements IStoreFactory {
// Keep storing the other elements but report the failure
since some children throw without
// logging the error themselves (e.g.
StandardContextSF.storeWithBackup())
log.warn(sm.getString("factory.storeElementFailed",
element.getClass().getName()), ioe);
+ if (firstException == null) {
+ firstException = ioe;
+ } else {
+ firstException.addSuppressed(ioe);
+ }
}
}
+ if (firstException != null) {
+ throw firstException;
+ }
}
}
}
\ No newline at end of file
diff --git a/test/org/apache/catalina/storeconfig/TestStoreFactoryBase.java
b/test/org/apache/catalina/storeconfig/TestStoreFactoryBase.java
new file mode 100644
index 0000000000..7386514c5a
--- /dev/null
+++ b/test/org/apache/catalina/storeconfig/TestStoreFactoryBase.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.storeconfig;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestStoreFactoryBase {
+
+ @Test
+ public void
testStoreElementArrayPropagatesIOExceptionAfterRemainingElements() {
+ Object failingElement = new Object();
+ Object remainingElement = new Object();
+ IOException failure = new IOException("Test failure");
+ List<Object> attemptedElements = new ArrayList<>();
+ StoreFactoryBase factory = new StoreFactoryBase() {
+
+ @Override
+ protected void storeElement(PrintWriter writer, int indent, Object
element) throws Exception {
+ attemptedElements.add(element);
+ if (element == failingElement) {
+ throw failure;
+ }
+ }
+ };
+
+ IOException actual = Assert.assertThrows(IOException.class,
+ () -> factory.storeElementArray(null, 0, new Object[] {
failingElement, remainingElement }));
+
+ Assert.assertSame(failure, actual);
+ Assert.assertEquals(Arrays.asList(failingElement, remainingElement),
attemptedElements);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]