{"record":{"id":"8d9bf18bac9e42ee","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getlastmodifiedtime-throw-an-error-e","errorCode":null,"errorMessage":"The function call getLastModifiedTime throw an error :  + e.toString()","messagePattern":"The function call getLastModifiedTime throw an error :  \\+ e\\.toString\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":2364,"sourceCode":"          // Source file\n          file = KettleVFS.getInstance( bowl ).getFileObject( (String) ArgList[0] );\n          String dateformat = (String) ArgList[1];\n          if ( isNull( dateformat ) ) {\n            dateformat = \"yyyy-MM-dd\";\n          }\n          String lastmodifiedtime = null;\n          if ( file.exists() ) {\n            java.util.Date lastmodifiedtimedate = new java.util.Date( file.getContent().getLastModifiedTime() );\n            java.text.DateFormat dateFormat = new SimpleDateFormat( dateformat );\n            lastmodifiedtime = dateFormat.format( lastmodifiedtimedate );\n\n          } 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","sourceCodeStart":2346,"sourceCodeEnd":2382,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2346-L2382","documentation":"getLastModifiedTime() wraps IOExceptions from VFS resolution or file.getContent().getLastModifiedTime() into this RuntimeException, appending e.toString(). The argument reached the VFS layer but IO failed — bad URI, provider missing, remote backend error, or content access failure.","triggerScenarios":"Malformed VFS URI/scheme; file.getContent() throwing on a remote provider (network blip, expired session); unsupported scheme without provider plugin; permission errors surfaced as IOException.","commonSituations":"SFTP/S3 jobs failing intermittently mid-run; Windows-style paths on the VFS; reading timestamps from a mounted share that dropped during the run.","solutions":["Read the appended IOException detail for the precise cause.","Correct the URI form (forward slashes, file:/// scheme on Windows, escaped chars).","Verify remote connectivity, credentials, and installed VFS provider plugins.","Add retry at the transformation level for transient remote errors.","Consider reading lastModified via java.io.File (file.lastModified()) for local files to bypass VFS."],"exampleFix":"// before\nvar ts = getLastModifiedTime( 'C:\\\\tmp\\\\a.txt' ); // bad URI -> IOException\n// after\nvar f = new java.io.File('C:/tmp/a.txt');\nvar ts = new java.text.SimpleDateFormat('yyyy-MM-dd HH:mm:ss').format( new java.util.Date( f.lastModified() ) );","handlingStrategy":"try-catch","validationCode":"var uri = String(path).replace(/\\\\/g, '/');\nif (/^[A-Za-z]:/.test(uri)) { uri = 'file:///' + uri; }","typeGuard":"function isUriLike(v){ return typeof v === 'string' && /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(v); }","tryCatchPattern":"try { var ts = getLastModifiedTime(path, fmt); } catch (e) { Logger.logError('getLastModifiedTime IO failure: ' + e); var ts = ''; }","preventionTips":["Use proper VFS URI forms; avoid raw Windows backslash paths","Confirm VFS provider plugins and remote credentials before long runs","For local files, prefer java.io.File.lastModified() over the VFS helper","Design transformations to retry transient remote-IO failures"],"tags":["io-error","vfs","uri","javascript-step"],"backgroundTag":"file-read-failed","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"}