{"record":{"id":"65b47f608a392b35","repo":"pentaho/pentaho-kettle","slug":"the-function-call-touch-requires-1-valid-argument","errorCode":null,"errorMessage":"The function call touch requires 1 valid argument.","messagePattern":"The function call touch requires 1 valid argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":961,"sourceCode":"        throw new RuntimeException( e.toString() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call str2RegExp requires 2 arguments.\" );\n    }\n    return strArr;\n  }\n\n  public static void touch( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {\n        File file = new File( (String) ArgList[0] );\n        boolean success = file.createNewFile();\n        if ( !success ) {\n          file.setLastModified( System.currentTimeMillis() );\n        }\n      } else {\n        throw new RuntimeException( \"The function call touch requires 1 valid argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static Object fileExists( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {\n        if ( ArgList[0].equals( null ) ) {\n          return null;\n        }\n        File file = new File( (String) ArgList[0] );\n        return Boolean.valueOf( file.isFile() );\n      } else {\n        throw new RuntimeException( \"The function call fileExists requires 1 valid argument.\" );\n      }","sourceCodeStart":943,"sourceCodeEnd":979,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L943-L979","documentation":"touch() creates a file or updates its last-modified timestamp, and requires exactly one argument that is a String path. This RuntimeException is thrown when the argument count is not 1 or the argument is not a String (the code checks ArgList.length == 1 && ArgList[0] instanceof String).","triggerScenarios":"Calling touch() with zero arguments, multiple arguments, or a non-String argument such as a number, Date, or JavaScript null.","commonSituations":"Passing a transformation field that is not a string type; forgetting the filename argument; concatenating path parts outside the call and accidentally passing extra arguments.","solutions":["Call touch with exactly one String argument: touch('/path/to/file.txt').","Convert non-string fields first, e.g. touch(fieldName + '') or use a string-typed field.","Build the full path into a single JavaScript string variable before calling touch().","Catch the RuntimeException in script if the path may be dynamic and validate it beforehand."],"exampleFix":"// before\ntouch(fileId); // numeric field\n// after\ntouch('/data/export/' + fileId + '.txt');","handlingStrategy":"validation","validationCode":"if (path == null || typeof path !== 'string' || path.length === 0) throw new RuntimeException('touch needs one non-empty string path');\ntouch(path);","typeGuard":"function isPath(v) { return v != null && (typeof v === 'string' || v instanceof java.lang.String); }","tryCatchPattern":"try { touch(p); } catch (e) { logError('touch failed: ' + e.message); }","preventionTips":["Ensure path fields are string-typed in the transformation","Build full paths into one variable before calling touch()","Never pass numeric or Date fields directly"],"tags":["scripting","file","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}