{"record":{"id":"3c5585566fa21f91","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getlastmodifiedtime-is-not-valid-3c5585","errorCode":null,"errorMessage":"The function call getLastModifiedTime is not valid.","messagePattern":"The function call getLastModifiedTime is not valid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2465,"sourceCode":"            Context.reportRuntimeError( \"file [\" + Context.toString( ArgList[0] ) + \"] can not be found!\" );\n          }\n\n          return lastmodifiedtime;\n        } catch ( IOException e ) {\n          throw Context.reportRuntimeError( \"The function call getLastModifiedTime throw an error : \"\n            + 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 Context.reportRuntimeError( \"The function call getLastModifiedTime is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n\n  public static Object trunc( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function 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 Context.getUndefinedValue();\n        }\n","sourceCodeStart":2447,"sourceCodeEnd":2483,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2447-L2483","documentation":"getLastModifiedTime is a Rhino JavaScript helper function added by ScriptValuesAddedFunctions. It requires exactly one argument (a file name string or File object); any other argument count or type falls through to the final else and this reportRuntimeError is thrown. The error means the JS script called getLastModifiedTime with an invalid signature.","triggerScenarios":"Calling getLastModifiedTime() with zero arguments, with more than one argument, or with a first argument that cannot be converted to a java.io.File (e.g. a number, null, or a non-string object) from a JavaScript step (Modified Java Script Value).","commonSituations":"Passing a JS variable that is undefined/null because an upstream field was empty; forgetting the argument entirely; passing a Path-like or JavaScript string built from concatenation that ends up not coercible; copy-pasted script code assuming a different helper signature.","solutions":["Pass exactly one argument that is a valid file path string, e.g. getLastModifiedTime('/tmp/data.csv').","Guard the argument in script: if (path != null && typeof path == 'string') { ... } before calling.","Check that the file-related variables coming from previous steps are actually populated (log them before the call).","Wrap the call in try/catch inside the script and return a default (e.g. null) when arguments are invalid."],"exampleFix":"// before\nvar ts = getLastModifiedTime();\n// after\nvar ts = (filename != null) ? getLastModifiedTime(filename.toString()) : null;","handlingStrategy":"validation","validationCode":"function safeGetLastModified(p) { if (p == null || typeof p !== 'string' || p.length === 0) return null; try { return getLastModifiedTime(p); } catch (e) { return null; } }","typeGuard":"function isFilePath(v) { return v != null && typeof v === 'string' && v.length > 0; }","tryCatchPattern":"try { ts = getLastModifiedTime(path); } catch (e) { Logger.LogError('getLastModifiedTime failed: ' + e.message); ts = null; }","preventionTips":["Always pass exactly one string path argument","Null-check variables sourced from upstream steps","Log argument values before calling file helpers"],"tags":["javascript","scripting","argument-validation","rhino"],"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"}