{"record":{"id":"037c2c0d7fd63cbc","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getshortfilename-is-not-valid","errorCode":null,"errorMessage":"The function call getShortFilename is not valid.","messagePattern":"The function call getShortFilename 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":2245,"sourceCode":"          } else {\n            throw new RuntimeException( \"file [\" + ArgList[0] + \"] can not be found!\" );\n          }\n\n          return Filename;\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call getShortFilename 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 getShortFilename is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static String getFileExtension( 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":2227,"sourceCodeEnd":2263,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2227-L2263","documentation":"Thrown by ScriptAddedFunctions.getShortFilename() when the argument contract fails: the function requires exactly one argument that is non-null and non-undefined (ArgList.length == 1 && !isNull && !isUndefined). Zero arguments, extra arguments, or a null/undefined first argument produce this 'The function call getShortFilename is not valid.' RuntimeException before any file access.","triggerScenarios":"Calling getShortFilename() with no arguments, more than one argument, or a null/undefined filename variable from a JavaScript step (e.g. the incoming row field holding the filename was null).","commonSituations":"The filename field is absent from some rows so the variable is null; a typo in the variable name leaves it undefined; an extra argument left after refactoring the script.","solutions":["Pass exactly one defined, non-null String path: getShortFilename(path).","Guard in script: if (fn == undefined || fn == null) { skip/log } else { getShortFilename(fn) }.","Fix upstream steps so the filename field is always populated (defaults, null-if handling).","Log the offending row (with the row number) to find which record produced the null/undefined value.","Trim extra arguments — the function signature accepts only one."],"exampleFix":"// before\nvar name = getShortFilename( path, \"/data\" ); // 'not valid'\n// after\nvar name = getShortFilename( path );","handlingStrategy":"type-guard","validationCode":"// JavaScript\nif ( typeof fn === \"string\" && fn.length > 0 ) { var name = getShortFilename(fn); }","typeGuard":"function isDefinedString(v) { return typeof v === \"string\" && v !== null; }","tryCatchPattern":"try { name = getShortFilename(fn); } catch (e) { if (String(e.message).indexOf(\"is not valid\") >= 0) { Logger.logError(\"getShortFilename needs exactly one non-null string\"); name = null; } else { throw e; } }","preventionTips":["Call with exactly one argument.","Handle null filename fields before the script step (filters or default values).","Log row numbers to locate rows producing null/undefined paths.","Remove leftover extra arguments after script refactors."],"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"}