pentaho/pentaho-kettle · error · RuntimeException
The function call getLastModifiedTime is not valid.
Error message
The function call getLastModifiedTime is not valid.
What it means
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.
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
Example fix
// before var ts = getLastModifiedTime(filename); // after var ts = getLastModifiedTime(filename, 'yyyy-MM-dd HH:mm:ss');
Defensive patterns
Strategy: validation
Validate before calling
function safeGetLastModifiedTime(path, fmt) {
if (path == null) return null;
if (typeof path !== 'string') path = String(path);
if (fmt == null) fmt = 'yyyy-MM-dd';
return getLastModifiedTime(path, fmt);
} Type guard
function isNonEmptyString(v) { return typeof v === 'string' && v.length > 0; } Try / catch
try {
var ts = getLastModifiedTime(path, 'yyyy-MM-dd HH:mm:ss');
} catch (e) {
// log and fall back
var ts = null;
} Prevention
- 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
When it happens
Trigger: Calling getLastModifiedTime in a JavaScript step with zero, one, or three+ arguments, or with a null/undefined file path as the first argument.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Please provide a valid date to the function call date2str.
- Row.EndOfFileReached
- Row.EndOfFileReadingRow
- Row.ErrorWritingRow
- Row.RowError
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/99e7f79264779a5c.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:2376
} else {
throw new RuntimeException( "file [" + ArgList[0] + "] can not be found!" );
}
return lastmodifiedtime;
} catch ( IOException e ) {
throw new RuntimeException( "The function call getLastModifiedTime throw an error : " + e.toString() );
} finally {
if ( file != null ) {
try {
file.close();
} catch ( Exception e ) {
// Ignore errors
}
}
}
} else {
throw new RuntimeException( "The function call getLastModifiedTime is not valid." );
}
} catch ( Exception e ) {
throw new RuntimeException( e.toString() );
}
}
public static Object trunc( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
Object FunctionContext ) {
try {
// 1 argument: normal truncation of numbers
//
if ( ArgList.length == 1 ) {
if ( isNull( ArgList[0] ) ) {
return null;
} else if ( isUndefined( ArgList[0] ) ) {
return undefinedValue;
}
View on GitHub (pinned to f3058517a1)