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

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


The following commit(s) were added to refs/heads/main by this push:
     new 990a8362e8 Fix#9174  Action result handling for invalid regex, XML 
well formed, and Wait for file  (#9237)
990a8362e8 is described below

commit 990a8362e8862870ef3126c1eab9edd948abb1df
Author: Lance <[email protected]>
AuthorDate: Wed Nov 4 16:30:34 2026 +0800

    Fix#9174  Action result handling for invalid regex, XML well formed, and 
Wait for file  (#9237)
    
    * Fix Action result handling for invalid regex, XML well formed, and Wait 
for file
    
    Signed-off-by: leehaut <[email protected]>
    
    * Fix Action result handling for invalid regex, XML well formed, and Wait 
for file
    
    Signed-off-by: leehaut <[email protected]>
    
    ---------
    
    Signed-off-by: leehaut <[email protected]>
---
 .../pages/workflow/actions/evalfilesmetrics.adoc   |   2 +-
 .../workflow/actions/processresultfilenames.adoc   |   2 +-
 .../ROOT/pages/workflow/actions/waitforfile.adoc   |   2 +-
 .../ROOT/pages/workflow/actions/xmlwellformed.adoc |   4 +-
 .../ActionCopyMoveResultFilenames.java             |  21 +++-
 .../ActionCopyMoveResultFilenamesTest.java         |  94 ++++++++++++++++
 .../evalfilesmetrics/ActionEvalFilesMetrics.java   |  13 ++-
 .../messages/messages_en_US.properties             |   1 +
 .../ActionEvalFilesMetricsTest.java                |  47 ++++++++
 .../actions/waitforfile/ActionWaitForFile.java     |   4 +-
 .../waitforfile/WorkflowActionWaitForFileTest.java |  45 ++++++++
 .../actions/xml/xmlwellformed/XmlWellFormed.java   |   7 +-
 .../xml/xmlwellformed/XmlWellFormedResultTest.java | 122 +++++++++++++++++++++
 13 files changed, 348 insertions(+), 16 deletions(-)

diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/evalfilesmetrics.adoc
 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/evalfilesmetrics.adoc
index 9d1ac6bf54..a6479265de 100644
--- 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/evalfilesmetrics.adoc
+++ 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/evalfilesmetrics.adoc
@@ -99,4 +99,4 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 |Result rows|Passed on unchanged. With *Previous result row*, the file or 
folder, the wildcard and the include subfolders flag come from the result row 
fields named in *File Result field*, *Wildcard result field* and *Include 
subfolders result field*.
 |===
 
-NOTE: With *Filenames result*, an invalid regular expression in *Wildcard* 
stops the workflow with an error, and no hop is followed.
+NOTE: With *Filenames result*, an invalid regular expression in *Wildcard* 
makes the action false with 1 error.
diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/processresultfilenames.adoc
 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/processresultfilenames.adoc
index f0a5bb3829..0dfd66e681 100644
--- 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/processresultfilenames.adoc
+++ 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/processresultfilenames.adoc
@@ -71,4 +71,4 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 |Lines written|The number of files copied, moved or deleted. When the action 
stops because the destination folder does not exist, the value of the previous 
action is passed on.
 |===
 
-NOTE: With *Success when number of errors lesser than*, the action is still 
true when the number of errors equals *Nr errors lesser than*. An invalid 
regular expression in *Wildcard (RegExp)* or *Exclude wildcard (RegExp)* stops 
the workflow with an error, and no hop is followed, also when *Limit action to* 
is not selected.
+NOTE: With *Success when number of errors lesser than*, the action is still 
true when the number of errors equals *Nr errors lesser than*. With *Limit 
action to* selected, an invalid regular expression in *Wildcard (RegExp)* or 
*Exclude wildcard (RegExp)* makes the action false with 1 error.
diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/waitforfile.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/waitforfile.adoc
index a72cd0ca4a..914e5dc665 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/waitforfile.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/waitforfile.adoc
@@ -57,7 +57,7 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 |===
 |Result|Value
 |True|The file or folder exists, or appears before *Maximum timeout*. With 
*Success on timeout*, the action is also true when the timeout is reached 
without it. With *File size check*, the action first waits until the size stays 
the same between two checks. A *Maximum timeout* of 0 waits until the file 
appears or the workflow is stopped.
-|False|The timeout is reached without the file and *Success on timeout* is not 
selected, no file name is set, the path cannot be read (for example a `zip:` 
path into a file that is not a zip), or the workflow is stopped while waiting. 
The number of errors is always 0.
+|False|The timeout is reached without the file and *Success on timeout* is not 
selected, no file name is set, the path cannot be read (for example a `zip:` 
path into a file that is not a zip), or the workflow is stopped while waiting. 
When the path cannot be read, the action is false with 1 error.
 |Result files|With *Add filename to result*, the file is added when it is 
found. A folder is not added, and nothing is added when the action ends on the 
timeout. The result files of the previous action are kept.
 |Result rows|Passed on unchanged.
 |===
diff --git 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/xmlwellformed.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/xmlwellformed.adoc
index b1ad226a67..4d7fb20044 100644
--- 
a/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/xmlwellformed.adoc
+++ 
b/docs/hop-user-manual/modules/ROOT/pages/workflow/actions/xmlwellformed.adoc
@@ -35,7 +35,7 @@ The `Check if XML file is well-formed action` verifies if one 
or more files cont
 |Include subfolders|Also check the matching files in the subfolders of a 
folder.
 |Copy previous results to args|Take the files or folders and wildcards from 
the result rows of the previous action instead of from the list. See <<Result>>.
 |File/Folder source|Enter or select (Browse button) a file or folder
-|Wildcard (RegExp)|A regular expression matched against the whole path of each 
file in the folder, for example `+.*\.xml+` (see <<Result>>).
+|Wildcard (RegExp)|A regular expression matched against the file name 
(basename) of each file in the folder, for example `+.*\.xml+` or 
`+orders\.xml+` (see <<Result>>).
 |Files/Folders a|Specify the list of files or folders with wildcards (regular 
expressions) in this grid.
 You can add a different file or folder and wildcard on each line.
 
@@ -74,4 +74,4 @@ What this action passes on to the next action. See 
xref:workflow/action-results.
 |Lines rejected|The number of bad formed files.
 |===
 
-NOTE: A result row with fewer than two fields stops the workflow with an 
error, and no hop is followed. The wildcard is matched against the whole path 
of each file (for example `file:///data/in/orders.xml`), not its name: 
`+.*\.xml+` matches, `+orders\.xml+` matches nothing, and the action is still 
true.
+NOTE: With *Copy previous results to args*, a result row with only one field 
uses an empty wildcard (the whole file or folder is checked). The wildcard is 
matched against the file name (basename), not the full path: `+orders\.xml+` 
and `+.*\.xml+` both match `orders.xml`.
diff --git 
a/plugins/actions/copymoveresultfilenames/src/main/java/org/apache/hop/workflow/actions/copymoveresultfilenames/ActionCopyMoveResultFilenames.java
 
b/plugins/actions/copymoveresultfilenames/src/main/java/org/apache/hop/workflow/actions/copymoveresultfilenames/ActionCopyMoveResultFilenames.java
index ed698fbd92..a82135a494 100644
--- 
a/plugins/actions/copymoveresultfilenames/src/main/java/org/apache/hop/workflow/actions/copymoveresultfilenames/ActionCopyMoveResultFilenames.java
+++ 
b/plugins/actions/copymoveresultfilenames/src/main/java/org/apache/hop/workflow/actions/copymoveresultfilenames/ActionCopyMoveResultFilenames.java
@@ -23,6 +23,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 import lombok.Getter;
 import lombok.Setter;
 import org.apache.commons.vfs2.FileObject;
@@ -169,6 +170,20 @@ public class ActionCopyMoveResultFilenames extends 
ActionBase implements Cloneab
 
     boolean deleteFile = getAction() == ActionType.DELETE;
 
+    try {
+      if (specifyWildcard) {
+        if (!Utils.isEmpty(wildcard)) {
+          wildcardPattern = Pattern.compile(resolve(wildcard));
+        }
+        if (!Utils.isEmpty(wildcardExclude)) {
+          wildcardExcludePattern = Pattern.compile(resolve(wildcardExclude));
+        }
+      }
+    } catch (PatternSyntaxException e) {
+      logError(BaseMessages.getString(PKG, 
"ActionCopyMoveResultFilenames.Error", e.toString()));
+      return result;
+    }
+
     String realdestinationFolder = null;
     if (!deleteFile) {
       realdestinationFolder = resolve(getDestinationFolder());
@@ -177,12 +192,6 @@ public class ActionCopyMoveResultFilenames extends 
ActionBase implements Cloneab
         return result;
       }
     }
-    if (!Utils.isEmpty(wildcard)) {
-      wildcardPattern = Pattern.compile(resolve(wildcard));
-    }
-    if (!Utils.isEmpty(wildcardExclude)) {
-      wildcardExcludePattern = Pattern.compile(resolve(wildcardExclude));
-    }
 
     nrErrors = 0;
     limitFiles = Const.toInt(resolve(getNrErrorsLessThan()), 10);
diff --git 
a/plugins/actions/copymoveresultfilenames/src/test/java/org/apache/hop/workflow/actions/copymoveresultfilenames/ActionCopyMoveResultFilenamesTest.java
 
b/plugins/actions/copymoveresultfilenames/src/test/java/org/apache/hop/workflow/actions/copymoveresultfilenames/ActionCopyMoveResultFilenamesTest.java
index 6d5b1f3ac6..f1949c79c0 100644
--- 
a/plugins/actions/copymoveresultfilenames/src/test/java/org/apache/hop/workflow/actions/copymoveresultfilenames/ActionCopyMoveResultFilenamesTest.java
+++ 
b/plugins/actions/copymoveresultfilenames/src/test/java/org/apache/hop/workflow/actions/copymoveresultfilenames/ActionCopyMoveResultFilenamesTest.java
@@ -22,15 +22,33 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.hop.core.ICheckResult;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.ResultFile;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.vfs.HopVfs;
+import org.apache.hop.workflow.WorkflowMeta;
 import org.apache.hop.workflow.action.ActionSerializationTestUtil;
+import org.apache.hop.workflow.engine.IWorkflowEngine;
+import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 /** Unit test for {@link ActionCopyMoveResultFilenames} */
 class ActionCopyMoveResultFilenamesTest {
 
+  @TempDir Path tempDir;
+
+  @BeforeAll
+  static void setUpBeforeClass() {
+    HopLogStore.init();
+  }
+
   @Test
   void testSerializationRoundTrip() throws Exception {
     ActionCopyMoveResultFilenames action =
@@ -103,6 +121,82 @@ class ActionCopyMoveResultFilenamesTest {
     assertTrue(remarks.isEmpty());
   }
 
+  @Test
+  void invalidWildcardMakesActionFalseWithOneError() throws Exception {
+    IWorkflowEngine<WorkflowMeta> workflow = new LocalWorkflowEngine(new 
WorkflowMeta());
+    workflow.setStopped(false);
+
+    Path destination = tempDir.resolve("out");
+    ActionCopyMoveResultFilenames action = new ActionCopyMoveResultFilenames();
+    action.setParentWorkflow(workflow);
+    action.setAction(ActionCopyMoveResultFilenames.ActionType.COPY);
+    action.setDestinationFolder(destination.toString());
+    action.setCreateDestinationFolder(true);
+    action.setSpecifyWildcard(true);
+    action.setWildcard("[");
+
+    Result result = new Result();
+    Path source = Files.writeString(tempDir.resolve("file.txt"), "data");
+    ResultFile resultFile =
+        new ResultFile(
+            ResultFile.FILE_TYPE_GENERAL, 
HopVfs.getFileObject(source.toString()), "wf", "action");
+    result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
+
+    result = action.execute(result, 0);
+
+    assertFalse(result.isResult());
+    assertEquals(1, result.getNrErrors());
+    assertFalse(
+        Files.exists(destination),
+        "destination folder must not be created when the wildcard is invalid");
+  }
+
+  @Test
+  void invalidExcludeWildcardMakesActionFalseWithOneError() {
+    IWorkflowEngine<WorkflowMeta> workflow = new LocalWorkflowEngine(new 
WorkflowMeta());
+    workflow.setStopped(false);
+
+    ActionCopyMoveResultFilenames action = new ActionCopyMoveResultFilenames();
+    action.setParentWorkflow(workflow);
+    action.setAction(ActionCopyMoveResultFilenames.ActionType.DELETE);
+    action.setSpecifyWildcard(true);
+    action.setWildcard(".*\\.txt");
+    action.setWildcardExclude("[");
+
+    Result result = action.execute(new Result(), 0);
+
+    assertFalse(result.isResult());
+    assertEquals(1, result.getNrErrors());
+  }
+
+  @Test
+  void leftoverInvalidWildcardIsIgnoredWhenLimitActionToIsOff() throws 
Exception {
+    IWorkflowEngine<WorkflowMeta> workflow = new LocalWorkflowEngine(new 
WorkflowMeta());
+    workflow.setStopped(false);
+
+    Path destination = tempDir.resolve("out-no-limit");
+    ActionCopyMoveResultFilenames action = new ActionCopyMoveResultFilenames();
+    action.setParentWorkflow(workflow);
+    action.setAction(ActionCopyMoveResultFilenames.ActionType.COPY);
+    action.setDestinationFolder(destination.toString());
+    action.setCreateDestinationFolder(true);
+    action.setSpecifyWildcard(false);
+    action.setWildcard("[");
+
+    Result result = new Result();
+    Path source = Files.writeString(tempDir.resolve("file-no-limit.txt"), 
"data");
+    ResultFile resultFile =
+        new ResultFile(
+            ResultFile.FILE_TYPE_GENERAL, 
HopVfs.getFileObject(source.toString()), "wf", "action");
+    result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
+
+    result = action.execute(result, 0);
+
+    assertTrue(result.isResult());
+    assertEquals(0, result.getNrErrors());
+    assertTrue(Files.exists(destination.resolve("file-no-limit.txt")));
+  }
+
   private static List<ICheckResult> check(ActionCopyMoveResultFilenames 
action) {
     List<ICheckResult> remarks = new ArrayList<>();
     action.check(remarks, null, action, null);
diff --git 
a/plugins/actions/evalfilesmetrics/src/main/java/org/apache/hop/workflow/actions/evalfilesmetrics/ActionEvalFilesMetrics.java
 
b/plugins/actions/evalfilesmetrics/src/main/java/org/apache/hop/workflow/actions/evalfilesmetrics/ActionEvalFilesMetrics.java
index 404a863acc..da8a9eac8f 100644
--- 
a/plugins/actions/evalfilesmetrics/src/main/java/org/apache/hop/workflow/actions/evalfilesmetrics/ActionEvalFilesMetrics.java
+++ 
b/plugins/actions/evalfilesmetrics/src/main/java/org/apache/hop/workflow/actions/evalfilesmetrics/ActionEvalFilesMetrics.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 import lombok.Getter;
 import lombok.Setter;
 import org.apache.commons.lang3.StringUtils;
@@ -266,7 +267,17 @@ public class ActionEvalFilesMetrics extends ActionBase 
implements Cloneable, IAc
           Pattern pattern = null;
           String realPattern = resolve(getResultFilenamesWildcard());
           if (!Utils.isEmpty(realPattern)) {
-            pattern = Pattern.compile(realPattern);
+            try {
+              pattern = Pattern.compile(realPattern);
+            } catch (PatternSyntaxException e) {
+              logError(
+                  BaseMessages.getString(
+                      PKG, "ActionEvalFilesMetrics.Error.InvalidWildcard", 
e.toString()));
+              incrementErrors();
+              result.setResult(false);
+              result.setNrErrors(getNrErrors());
+              return result;
+            }
           }
 
           for (Iterator<ResultFile> it = resultFiles.iterator();
diff --git 
a/plugins/actions/evalfilesmetrics/src/main/resources/org/apache/hop/workflow/actions/evalfilesmetrics/messages/messages_en_US.properties
 
b/plugins/actions/evalfilesmetrics/src/main/resources/org/apache/hop/workflow/actions/evalfilesmetrics/messages/messages_en_US.properties
index 4c80267526..177553d98c 100644
--- 
a/plugins/actions/evalfilesmetrics/src/main/resources/org/apache/hop/workflow/actions/evalfilesmetrics/messages/messages_en_US.properties
+++ 
b/plugins/actions/evalfilesmetrics/src/main/resources/org/apache/hop/workflow/actions/evalfilesmetrics/messages/messages_en_US.properties
@@ -26,6 +26,7 @@ ActionEvalFilesMetrics.Error.FilesGridEmpty=Files/Folders 
grid is empty!
 ActionEvalFilesMetrics.Error.GettingFileFromResultFilenames=Error getting file 
[{0}] from result filenames! Error : {1}
 ActionEvalFilesMetrics.Error.GettingFileSize=Error getting size for file 
[{0}]! Error  {1}
 ActionEvalFilesMetrics.Error.Init=Error while initializing values to compare! 
Please check compare/min/max value. Error : {0}
+ActionEvalFilesMetrics.Error.InvalidWildcard=Invalid regular expression in 
Wildcard. Error : {0}
 ActionEvalFilesMetrics.Error.ResultFieldsFileMissing=File result field is 
missing!
 ActionEvalFilesMetrics.Error.SourceFileNotExists=File/folder [{0}] does not 
exist!
 ActionEvalFilesMetrics.Error.UnknowFileFormat=We can not get the format of 
[{0}]!
diff --git 
a/plugins/actions/evalfilesmetrics/src/test/java/org/apache/hop/workflow/actions/evalfilesmetrics/ActionEvalFilesMetricsTest.java
 
b/plugins/actions/evalfilesmetrics/src/test/java/org/apache/hop/workflow/actions/evalfilesmetrics/ActionEvalFilesMetricsTest.java
index 113242524c..da147d03bd 100644
--- 
a/plugins/actions/evalfilesmetrics/src/test/java/org/apache/hop/workflow/actions/evalfilesmetrics/ActionEvalFilesMetricsTest.java
+++ 
b/plugins/actions/evalfilesmetrics/src/test/java/org/apache/hop/workflow/actions/evalfilesmetrics/ActionEvalFilesMetricsTest.java
@@ -18,13 +18,34 @@
 package org.apache.hop.workflow.actions.evalfilesmetrics;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 
+import java.nio.file.Files;
+import java.nio.file.Path;
 import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.ResultFile;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.vfs.HopVfs;
+import org.apache.hop.workflow.WorkflowMeta;
 import org.apache.hop.workflow.action.ActionSerializationTestUtil;
+import org.apache.hop.workflow.engine.IWorkflowEngine;
+import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
+import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
+/** Unit test for {@link ActionEvalFilesMetrics} */
 class ActionEvalFilesMetricsTest {
+
+  @TempDir Path tempDir;
+
+  @BeforeAll
+  static void setUpBeforeClass() {
+    HopLogStore.init();
+  }
+
   @BeforeEach
   void setUp() throws Exception {
     HopClientEnvironment.init();
@@ -66,4 +87,30 @@ class ActionEvalFilesMetricsTest {
     assertEquals("wildcard3", f.getSourceWildcard());
     assertEquals("Y", f.getSourceIncludeSubfolders());
   }
+
+  @Test
+  void invalidResultFilenamesWildcardMakesActionFalseWithOneError() throws 
Exception {
+    IWorkflowEngine<WorkflowMeta> workflow = new LocalWorkflowEngine(new 
WorkflowMeta());
+    workflow.setStopped(false);
+
+    ActionEvalFilesMetrics action = new ActionEvalFilesMetrics();
+    action.setParentWorkflow(workflow);
+    
action.setSourceFilesType(ActionEvalFilesMetrics.SourceFilesType.FILENAMES_RESULT);
+    action.setEvaluationType(ActionEvalFilesMetrics.EvaluationType.COUNT);
+    
action.setSuccessConditionType(ActionEvalFilesMetrics.SuccesConditionType.EQUAL);
+    action.setCompareValue("1");
+    action.setResultFilenamesWildcard("[");
+
+    Result result = new Result();
+    Path source = Files.writeString(tempDir.resolve("sales.csv"), "id\n1\n");
+    ResultFile resultFile =
+        new ResultFile(
+            ResultFile.FILE_TYPE_GENERAL, 
HopVfs.getFileObject(source.toString()), "wf", "action");
+    result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
+
+    result = action.execute(result, 0);
+
+    assertFalse(result.isResult());
+    assertEquals(1, result.getNrErrors());
+  }
 }
diff --git 
a/plugins/actions/waitforfile/src/main/java/org/apache/hop/workflow/actions/waitforfile/ActionWaitForFile.java
 
b/plugins/actions/waitforfile/src/main/java/org/apache/hop/workflow/actions/waitforfile/ActionWaitForFile.java
index 74bbdba77e..0cbacb5aaa 100644
--- 
a/plugins/actions/waitforfile/src/main/java/org/apache/hop/workflow/actions/waitforfile/ActionWaitForFile.java
+++ 
b/plugins/actions/waitforfile/src/main/java/org/apache/hop/workflow/actions/waitforfile/ActionWaitForFile.java
@@ -277,7 +277,9 @@ public class ActionWaitForFile extends ActionBase 
implements Cloneable, IAction
           result.setResult(false);
         }
       } catch (Exception e) {
-        logBasic("Exception while waiting for file [" + realFilename + 
CONST_TO_STOP_GROWING, e);
+        logError("Exception while waiting for file [" + realFilename + "]", e);
+        result.setResult(false);
+        result.setNrErrors(1);
       } finally {
         if (fileObject != null) {
           try {
diff --git 
a/plugins/actions/waitforfile/src/test/java/org/apache/hop/workflow/actions/waitforfile/WorkflowActionWaitForFileTest.java
 
b/plugins/actions/waitforfile/src/test/java/org/apache/hop/workflow/actions/waitforfile/WorkflowActionWaitForFileTest.java
index 7cd6e193cf..4014a8d2da 100644
--- 
a/plugins/actions/waitforfile/src/test/java/org/apache/hop/workflow/actions/waitforfile/WorkflowActionWaitForFileTest.java
+++ 
b/plugins/actions/waitforfile/src/test/java/org/apache/hop/workflow/actions/waitforfile/WorkflowActionWaitForFileTest.java
@@ -16,17 +16,39 @@
  */
 package org.apache.hop.workflow.actions.waitforfile;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.logging.HopLogStore;
 import org.apache.hop.junit.rules.RestoreHopEngineEnvironmentExtension;
+import org.apache.hop.workflow.WorkflowMeta;
 import 
org.apache.hop.workflow.action.loadsave.WorkflowActionLoadSaveTestSupport;
+import org.apache.hop.workflow.engine.IWorkflowEngine;
+import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
 
+/** Unit test for {@link ActionWaitForFile} */
 class WorkflowActionWaitForFileTest extends 
WorkflowActionLoadSaveTestSupport<ActionWaitForFile> {
   @RegisterExtension
   static RestoreHopEngineEnvironmentExtension env = new 
RestoreHopEngineEnvironmentExtension();
 
+  @TempDir Path tempDir;
+
+  @BeforeAll
+  static void setUpBeforeClass() {
+    HopLogStore.init();
+  }
+
   @Override
   protected Class<ActionWaitForFile> getActionClass() {
     return ActionWaitForFile.class;
@@ -64,4 +86,27 @@ class WorkflowActionWaitForFileTest extends 
WorkflowActionLoadSaveTestSupport<Ac
         "fileSizeCheck", "setFileSizeCheck",
         "addFilenameToResult", "setAddFilenameToResult");
   }
+
+  @Test
+  void unreadableZipPathIsFalseWithOneError() throws Exception {
+    Path fakeZip =
+        Files.writeString(
+            tempDir.resolve("not-a-zip.zip"),
+            "this is plain text, not a zip",
+            StandardCharsets.UTF_8);
+
+    IWorkflowEngine<WorkflowMeta> workflow = new LocalWorkflowEngine(new 
WorkflowMeta());
+    workflow.setStopped(false);
+
+    ActionWaitForFile action = new ActionWaitForFile();
+    action.setParentWorkflow(workflow);
+    action.setFilename("zip:" + fakeZip.toAbsolutePath() + "!/inside.txt");
+    action.setMaximumTimeout("5");
+    action.setCheckCycleTime("1");
+
+    Result result = action.execute(new Result(), 0);
+
+    assertFalse(result.isResult());
+    assertEquals(1, result.getNrErrors());
+  }
 }
diff --git 
a/plugins/actions/xml/src/main/java/org/apache/hop/workflow/actions/xml/xmlwellformed/XmlWellFormed.java
 
b/plugins/actions/xml/src/main/java/org/apache/hop/workflow/actions/xml/xmlwellformed/XmlWellFormed.java
index 534405b8ea..76ce5cde8e 100644
--- 
a/plugins/actions/xml/src/main/java/org/apache/hop/workflow/actions/xml/xmlwellformed/XmlWellFormed.java
+++ 
b/plugins/actions/xml/src/main/java/org/apache/hop/workflow/actions/xml/xmlwellformed/XmlWellFormed.java
@@ -188,7 +188,7 @@ public class XmlWellFormed extends ActionBase implements 
Cloneable, IAction {
 
         // Get source and destination file names, also wildcard
         String vSourceFileFolderPrevious = resultRow.getString(0, null);
-        String vWildcardPrevious = resultRow.getString(1, null);
+        String vWildcardPrevious = resultRow.size() > 1 ? 
resultRow.getString(1, null) : null;
 
         if (isDetailed()) {
           logDetailed(
@@ -401,13 +401,14 @@ public class XmlWellFormed extends ActionBase implements 
Cloneable, IAction {
 
               if 
(!currentFile.getParent().toString().equals(sourcefilefolder.toString())) {
                 // Not in the Base Folder..Only if include sub folders
-                if (includeSubfolders && 
GetFileWildcard(currentFile.toString(), realWildcard)) {
+                if (includeSubfolders
+                    && GetFileWildcard(currentFile.getName().getBaseName(), 
realWildcard)) {
                   checkOneFile(currentFile, result, parentWorkflow);
                 }
 
               } else {
                 // In the base folder
-                if (GetFileWildcard(currentFile.toString(), realWildcard)) {
+                if (GetFileWildcard(currentFile.getName().getBaseName(), 
realWildcard)) {
                   checkOneFile(currentFile, result, parentWorkflow);
                 }
               }
diff --git 
a/plugins/actions/xml/src/test/java/org/apache/hop/workflow/actions/xml/xmlwellformed/XmlWellFormedResultTest.java
 
b/plugins/actions/xml/src/test/java/org/apache/hop/workflow/actions/xml/xmlwellformed/XmlWellFormedResultTest.java
new file mode 100644
index 0000000000..f0eac1918a
--- /dev/null
+++ 
b/plugins/actions/xml/src/test/java/org/apache/hop/workflow/actions/xml/xmlwellformed/XmlWellFormedResultTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.hop.workflow.actions.xml.xmlwellformed;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import org.apache.hop.core.Result;
+import org.apache.hop.core.RowMetaAndData;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.core.row.RowMeta;
+import org.apache.hop.core.row.value.ValueMetaString;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.apache.hop.workflow.action.ActionMeta;
+import org.apache.hop.workflow.engine.IWorkflowEngine;
+import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/** Result-behaviour tests for {@link XmlWellFormed} (apache/hop#9174). */
+class XmlWellFormedResultTest {
+
+  private static final String WELL_FORMED = "<?xml 
version=\"1.0\"?><root><a>1</a></root>";
+
+  @TempDir Path folder;
+
+  private XmlWellFormed action;
+
+  @BeforeAll
+  static void setUpBeforeClass() {
+    HopLogStore.init();
+  }
+
+  @BeforeEach
+  void setUp() {
+    IWorkflowEngine<WorkflowMeta> workflow = new LocalWorkflowEngine(new 
WorkflowMeta());
+    action = new XmlWellFormed();
+    workflow.getWorkflowMeta().addAction(new ActionMeta(action));
+    action.setParentWorkflow(workflow);
+    action.setParentWorkflowMeta(mock(WorkflowMeta.class));
+    workflow.setStopped(false);
+  }
+
+  @Test
+  void basenameWildcardMatchesFileName() throws Exception {
+    Files.writeString(folder.resolve("good.xml"), WELL_FORMED, 
StandardCharsets.UTF_8);
+
+    XmlWellFormedField field = new XmlWellFormedField();
+    field.setSourceFilefolder(folder.toString());
+    field.setWildcard("good\\.xml");
+    action.setSourceFileFolders(List.of(field));
+
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult());
+    assertEquals(0, result.getNrErrors());
+    assertEquals(1, result.getNrLinesWritten(), "basename wildcard must check 
the file");
+  }
+
+  @Test
+  void basenameWildcardMatchesFileNameInSubfolder() throws Exception {
+    Path subFolder = Files.createDirectory(folder.resolve("nested"));
+    Files.writeString(subFolder.resolve("good.xml"), WELL_FORMED, 
StandardCharsets.UTF_8);
+    Files.writeString(folder.resolve("skip.xml"), WELL_FORMED, 
StandardCharsets.UTF_8);
+
+    XmlWellFormedField field = new XmlWellFormedField();
+    field.setSourceFilefolder(folder.toString());
+    field.setWildcard("good\\.xml");
+    action.setSourceFileFolders(List.of(field));
+    action.includeSubfolders = true;
+
+    Result result = action.execute(new Result(), 0);
+
+    assertTrue(result.isResult());
+    assertEquals(0, result.getNrErrors());
+    assertEquals(
+        1, result.getNrLinesWritten(), "basename wildcard must check the 
nested file by name");
+  }
+
+  @Test
+  void oneFieldResultRowUsesEmptyWildcard() throws Exception {
+    Files.writeString(folder.resolve("good.xml"), WELL_FORMED, 
StandardCharsets.UTF_8);
+
+    action.argFromPrevious = true;
+
+    RowMeta rowMeta = new RowMeta();
+    rowMeta.addValueMeta(new ValueMetaString("filename"));
+    RowMetaAndData row = new RowMetaAndData(rowMeta, new Object[] 
{folder.toString()});
+
+    Result previous = new Result();
+    previous.getRows().add(row);
+
+    Result result = action.execute(previous, 0);
+
+    assertTrue(result.isResult());
+    assertEquals(0, result.getNrErrors());
+    assertEquals(
+        1, result.getNrLinesWritten(), "a one-field folder row must check the 
whole folder");
+  }
+}

Reply via email to