This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-ear-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new d47a6c5 Fix #510: Propagate IOException instead of swallowing it in
ApplicationXmlWriter.write() (#523)
d47a6c5 is described below
commit d47a6c59f36f318e981817e70ff4f00e744d3073
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Thu Jul 9 10:10:20 2026 +0000
Fix #510: Propagate IOException instead of swallowing it in
ApplicationXmlWriter.write() (#523)
Replace the empty catch block with a throw of EarPluginException wrapping
the IOException, so build fails on IO errors instead of silently
producing a truncated or missing application.xml.
Adds unit test coverage for ApplicationXmlWriter:
- Happy path: write to a valid temp file
- Failure path: write to /dev/full triggers EarPluginException
---
.../maven/plugins/ear/ApplicationXmlWriter.java | 2 +-
.../plugins/ear/ApplicationXmlWriterTest.java | 74 ++++++++++++++++++++++
2 files changed, 75 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriter.java
b/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriter.java
index e49c5c3..cf2e913 100644
--- a/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriter.java
+++ b/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriter.java
@@ -109,7 +109,7 @@ final class ApplicationXmlWriter extends AbstractXmlWriter {
writer.endElement();
} catch (IOException ex) {
- // ignore
+ throw new EarPluginException("Failed to write application.xml",
ex);
}
}
diff --git
a/src/test/java/org/apache/maven/plugins/ear/ApplicationXmlWriterTest.java
b/src/test/java/org/apache/maven/plugins/ear/ApplicationXmlWriterTest.java
new file mode 100644
index 0000000..6f55d49
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/ear/ApplicationXmlWriterTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.maven.plugins.ear;
+
+import java.io.File;
+import java.util.Collections;
+
+import org.apache.maven.plugins.ear.util.JavaEEVersion;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class ApplicationXmlWriterTest {
+
+ @TempDir
+ File tempDir;
+
+ @Test
+ void testWriteSucceedsToValidFile() throws Exception {
+ ApplicationXmlWriter writer = new
ApplicationXmlWriter(JavaEEVersion.ELEVEN, "UTF-8", false);
+ File dest = new File(tempDir, "application.xml");
+ ApplicationXmlWriterContext context = new ApplicationXmlWriterContext(
+ dest,
+ Collections.emptyList(),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ null,
+ null,
+ null,
+ null,
+ null);
+ writer.write(context);
+ assertTrue(dest.exists(), "application.xml should have been created");
+ assertTrue(dest.length() > 0, "application.xml should not be empty");
+ }
+
+ @Test
+ void testWriteThrowsExceptionOnIoError() {
+ ApplicationXmlWriter writer = new
ApplicationXmlWriter(JavaEEVersion.ELEVEN, "UTF-8", false);
+ ApplicationXmlWriterContext context = new ApplicationXmlWriterContext(
+ new File("/dev/full"),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ null,
+ null,
+ null,
+ null,
+ null);
+ assertThrows(EarPluginException.class, () -> writer.write(context));
+ }
+}