{"record":{"id":"883211f0da4df292","repo":"pentaho/pentaho-kettle","slug":"the-function-call-isfolder-is-not-valid","errorCode":null,"errorMessage":"The function call isFolder is not valid.","messagePattern":"The function call isFolder is not valid\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":2204,"sourceCode":"            }\n          } else {\n            throw new RuntimeException( \"folder [\" + ArgList[0] + \"] can not be found!\" );\n          }\n          return isafolder;\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call isFolder throw an error : \" + e.toString() );\n        } finally {\n          if ( file != null ) {\n            try {\n              file.close();\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n          }\n        }\n\n      } else {\n        throw new RuntimeException( \"The function call isFolder is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static String getShortFilename( Bowl bowl, 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        FileObject file = null;\n\n        try {\n          // Source file\n          file = KettleVFS.getInstance( bowl ).getFileObject( (String) ArgList[0] );","sourceCodeStart":2186,"sourceCodeEnd":2222,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2186-L2222","documentation":"Thrown by ScriptAddedFunctions.isFolder() when the argument contract is violated: the function requires exactly one argument that is neither null nor undefined (ArgList.length == 1 && !isNull && !isUndefined). Any other shape — zero arguments, multiple arguments, or a null/undefined first argument — triggers this 'function call is not valid' RuntimeException before any filesystem access.","triggerScenarios":"Calling isFolder() with no arguments, with two or more arguments, or with null/undefined as the first argument from a JavaScript step (e.g. isFolder(varThatTurnedOutUndefined)).","commonSituations":"A script variable was never assigned (undefined) because an earlier field was missing from the row; copy-paste left an extra argument; a field value was null so the guard trips even though the developer expected null to return false (the inner ArgList[0].equals(null) branch is unreachable in practice).","solutions":["Call isFolder with exactly one argument and ensure it is a non-null, defined String before the call.","Add a script-side guard: if (p != undefined && p != null) { isFolder(p) } else { /* handle */ }.","Trace why the variable is undefined/null — check the row layout and prior steps feeding the field.","Provide a default value for optional paths (e.g. p = p || \"/default/dir\").","If your field can legitimately be null, handle that case explicitly before invoking the function."],"exampleFix":"// before\nvar ok = isFolder( rowNum, path ); // 'The function call isFolder is not valid.'\n// after\nvar ok = isFolder( path ); // exactly one argument","handlingStrategy":"type-guard","validationCode":"// JavaScript\nif ( typeof p === \"string\" && p.length > 0 ) { var ok = isFolder(p); }","typeGuard":"function isDefinedString(v) { return typeof v === \"string\" && v !== null; }","tryCatchPattern":"try { ok = isFolder(p); } catch (e) { if (String(e.message).indexOf(\"is not valid\") >= 0) { Logger.logError(\"Bad arguments to isFolder\"); ok = false; } else { throw e; } }","preventionTips":["Always call with exactly one argument.","Null-check field values feeding the path variable (null-if settings in prior steps).","Trace undefined variables back to missing row fields.","Give optional paths a default value before the call."],"tags":["java","javascript","argument-count","null-argument","api-misuse"],"backgroundTag":"missing-required-argument","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"}