{"record":{"id":"99e7f79264779a5c","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getlastmodifiedtime-is-not-valid","errorCode":null,"errorMessage":"The function call getLastModifiedTime is not valid.","messagePattern":"The function call getLastModifiedTime 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":2376,"sourceCode":"          } else {\n            throw new RuntimeException( \"file [\" + ArgList[0] + \"] can not be found!\" );\n          }\n\n          return lastmodifiedtime;\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call getLastModifiedTime 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 getLastModifiedTime is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static Object trunc( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    try {\n      // 1 argument: normal truncation of numbers\n      //\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return null;\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return undefinedValue;\n        }\n","sourceCodeStart":2358,"sourceCodeEnd":2394,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2358-L2394","documentation":"getLastModifiedTime(FilePath, DateFormat) is a JavaScript scripting function added by Pentaho Kettle (ScriptAddedFunctions) that returns a file's last-modified timestamp formatted with a SimpleDateFormat pattern. This RuntimeException is thrown when the argument contract is violated: the function requires exactly 2 arguments (file path string and date format string), with a non-null, non-undefined first argument. The library throws it before doing any I/O so the script author immediately learns the call shape is wrong.","triggerScenarios":"Calling getLastModifiedTime in a JavaScript step with zero, one, or three+ arguments, or with a null/undefined file path as the first argument.","commonSituations":"Script authors copy a getLastModifiedTime(filePath) one-argument call from an older example or another dialect; a variable holding the path is undefined at runtime because an upstream field was renamed or empty; the second date-format argument was accidentally removed in a refactor.","solutions":["Pass exactly 2 arguments: getLastModifiedTime(filePath, 'yyyy-MM-dd HH:mm:ss')","Ensure the first argument is a non-null, non-undefined string file path before calling","If no custom format is needed, pass null as the second argument (defaults to 'yyyy-MM-dd') but never omit it","Wrap the call in a check like if (path != null) before invoking"],"exampleFix":"// before\nvar ts = getLastModifiedTime(filename);\n// after\nvar ts = getLastModifiedTime(filename, 'yyyy-MM-dd HH:mm:ss');","handlingStrategy":"validation","validationCode":"function safeGetLastModifiedTime(path, fmt) {\n  if (path == null) return null;\n  if (typeof path !== 'string') path = String(path);\n  if (fmt == null) fmt = 'yyyy-MM-dd';\n  return getLastModifiedTime(path, fmt);\n}","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.length > 0; }","tryCatchPattern":"try {\n  var ts = getLastModifiedTime(path, 'yyyy-MM-dd HH:mm:ss');\n} catch (e) {\n  // log and fall back\n  var ts = null;\n}","preventionTips":["Always pass both arguments, even if the format is null","Verify path variables are defined before the script step runs","Use fileExists() to validate the path before metadata calls","Keep a wrapper function to centralize argument coercion"],"tags":["javascript","scripting","argument-count","file-metadata"],"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"}