This is an automated email from the ASF dual-hosted git repository.
mattcasters 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 fbe4312e29 Fix Delete files Check treating the file path as a bean
property name (#8933)
fbe4312e29 is described below
commit fbe4312e29a0d294db6c899446b81cdf6aa8389d
Author: Lance <[email protected]>
AuthorDate: Thu Oct 15 15:21:45 2026 +0800
Fix Delete files Check treating the file path as a bean property name
(#8933)
Signed-off-by: leehaut <[email protected]>
---
.../actions/deletefiles/ActionDeleteFiles.java | 13 +++-
.../deletefiles/ActionDeleteFilesCheckTest.java | 87 ++++++++++++++++++++++
2 files changed, 97 insertions(+), 3 deletions(-)
diff --git
a/plugins/actions/deletefiles/src/main/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFiles.java
b/plugins/actions/deletefiles/src/main/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFiles.java
index eed75729f5..a4f30b5d51 100644
---
a/plugins/actions/deletefiles/src/main/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFiles.java
+++
b/plugins/actions/deletefiles/src/main/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFiles.java
@@ -342,13 +342,20 @@ public class ActionDeleteFiles extends ActionBase {
IVariables variables,
IHopMetadataProvider metadataProvider) {
+ if (Utils.isEmpty(fileItems)) {
+ return;
+ }
+
ValidatorContext ctx = new ValidatorContext();
- AbstractFileValidator.putVariableSpace(ctx, getVariables());
+ // Use the workflow variable space so ${Internal.Entry.Current.Folder}
resolves during Check.
+ AbstractFileValidator.putVariableSpace(ctx, variables != null ? variables
: getVariables());
AndValidator.putValidators(
ctx, ActionValidatorUtils.notNullValidator(),
ActionValidatorUtils.fileExistsValidator());
- for (FileItem item : fileItems) {
- ActionValidatorUtils.andValidator().validate(this, item.getFileName(),
remarks, ctx);
+ // The second argument is a bean property path. A filename value is not a
property name.
+ for (int i = 0; i < fileItems.size(); i++) {
+ ActionValidatorUtils.andValidator()
+ .validate(this, "fileItems[" + i + "].fileName", remarks, ctx);
}
}
diff --git
a/plugins/actions/deletefiles/src/test/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFilesCheckTest.java
b/plugins/actions/deletefiles/src/test/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFilesCheckTest.java
new file mode 100644
index 0000000000..7b981747d4
--- /dev/null
+++
b/plugins/actions/deletefiles/src/test/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFilesCheckTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.deletefiles;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.ICheckResult;
+import org.apache.hop.core.variables.Variables;
+import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/** Check must validate {@code fileItems[i].fileName}, not the filename string
itself. */
+class ActionDeleteFilesCheckTest {
+
+ @TempDir Path tempDir;
+
+ @BeforeAll
+ static void setUpClass() throws Exception {
+ HopClientEnvironment.init();
+ }
+
+ @Test
+ void variablePathIsNotUsedAsPropertyName() throws Exception {
+ Path file = tempDir.resolve("files").resolve("dummy.csv");
+ Files.createDirectories(file.getParent());
+ Files.writeString(file, "a,b", StandardCharsets.UTF_8);
+
+ String storedName = "${Internal.Entry.Current.Directory}/files/dummy.csv";
+ ActionDeleteFiles action = new ActionDeleteFiles("delete files");
+ action.setFileItems(List.of(new FileItem(storedName, "")));
+
+ Variables variables = new Variables();
+ variables.setVariable("Internal.Entry.Current.Directory",
tempDir.toAbsolutePath().toString());
+
+ List<String> errors = errorTexts(action, variables);
+
+ assertTrue(errors.isEmpty(), "Filename must not be treated as a bean
property: " + errors);
+ }
+
+ @Test
+ void nullFileNameReportsTheBeanProperty() {
+ ActionDeleteFiles action = new ActionDeleteFiles("delete files");
+ action.setFileItems(List.of(new FileItem(null, "")));
+
+ List<String> errors = errorTexts(action, new Variables());
+
+ assertTrue(
+ errors.stream().anyMatch(text ->
text.contains("fileItems[0].fileName")),
+ "Null filename must fail on the bean property, got: " + errors);
+ }
+
+ private static List<String> errorTexts(ActionDeleteFiles action, Variables
variables) {
+ List<ICheckResult> remarks = new ArrayList<>();
+ action.check(remarks, new WorkflowMeta(), variables, new
MemoryMetadataProvider());
+ List<String> errors = new ArrayList<>();
+ for (ICheckResult remark : remarks) {
+ if (remark.getType() == ICheckResult.TYPE_RESULT_ERROR) {
+ errors.add(remark.getText());
+ }
+ }
+ return errors;
+ }
+}