{"record":{"id":"1894ec0c676dfcf3","repo":"pentaho/pentaho-kettle","slug":"the-function-call-fileexists-requires-1-valid-argument","errorCode":null,"errorMessage":"The function call fileExists requires 1 valid argument.","messagePattern":"The function call fileExists 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":978,"sourceCode":"      } 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      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static Object str2date( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    Object oRC = new Object();\n    String sArg1 = \"\";\n    String sArg2 = \"\";\n    String sArg3 = \"\";\n    String sArg4 = \"\";\n    switch ( ArgList.length ) {\n      case 0:\n        throw new RuntimeException( \"Please provide a valid string to the function call str2date.\" );\n      case 1:\n        try {","sourceCodeStart":960,"sourceCodeEnd":996,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L960-L996","documentation":"fileExists() checks whether a path exists as a file and requires exactly one String argument. This RuntimeException is thrown when the argument count is not 1 or the argument is not a String. It is a precondition guard thrown before any filesystem access.","triggerScenarios":"Calling fileExists() with no arguments, with two or more arguments, or with a non-String value such as a numeric field or null object.","commonSituations":"Passing a Kettle field of non-string type; forgetting the path argument after refactoring the script; passing a JavaScript object built from JSON instead of the path string.","solutions":["Call fileExists with exactly one String path: fileExists('/path/to/file').","Coerce the field to a string first, e.g. fileExists(String(myPath)).","Guard against null in script before the call if the field may be empty."],"exampleFix":"// before\nvar exists = fileExists(someRow.field);\n// after\nvar exists = fileExists(String(someRow.field));","handlingStrategy":"validation","validationCode":"if (p != null && (typeof p === 'string' || p instanceof java.lang.String) && p.length > 0) { var exists = fileExists(p); }","typeGuard":"function isNonEmptyStr(v) { return v != null && (typeof v === 'string') && v.length > 0; }","tryCatchPattern":"try { var ex = fileExists(p); } catch (e) { logError('fileExists failed: ' + e.message); ex = false; }","preventionTips":["Pass exactly one string argument","Coerce fields to strings before the call","Guard against null fields upstream in the transformation"],"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"}