{"record":{"id":"a9d0c232fd4954e5","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getfileextension-throw-an-error-e-tostring","errorCode":null,"errorMessage":"The function call getFileExtension throw an error :  + e.toString()","messagePattern":"The function call getFileExtension 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":2274,"sourceCode":"        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] );\n          String Extension = null;\n          if ( file.exists() ) {\n            Extension = file.getName().getExtension();\n\n          } else {\n            throw new RuntimeException( \"file [\" + ArgList[0] + \"] can not be found!\" );\n          }\n\n          return Extension;\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call getFileExtension 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 getFileExtension is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n","sourceCodeStart":2256,"sourceCodeEnd":2292,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2256-L2292","documentation":"getFileExtension() wraps any IOException raised while resolving or reading the VFS FileObject into a RuntimeException with this message. Unlike the 'can not be found' variant, the file resolution itself failed at the VFS/IO layer (bad URI, provider error, access problem). The original IOException text is appended.","triggerScenarios":"Calling getFileExtension() with a malformed VFS URI (invalid scheme characters), a scheme with no registered VFS provider, or a resolution/exists() check that throws IOException (e.g. network VFS unreachable, permission issues surfacing as IOException).","commonSituations":"Windows paths with backslashes or drive letters misinterpreted as URI schemes; s3:// or other remote schemes without the required provider plugin installed; network shares temporarily unavailable during the transformation run.","solutions":["Check the appended IOException message (e.getMessage) to identify the underlying cause.","Normalize the path to a forward-slash URI form (file:///C:/data/file.txt on Windows).","Install/verify the VFS provider plugin for remote schemes (S3, SFTP, etc.).","Retry if the cause was a transient network error, after fixing connectivity.","Log the full input argument and surrounding stack trace to confirm which call site threw."],"exampleFix":"// before\nvar ext = getFileExtension( 'C:\\\\data\\\\file.txt' ); // backslashes break VFS URI\n// after\nvar ext = getFileExtension( 'file:///C:/data/file.txt' );","handlingStrategy":"try-catch","validationCode":"// ensure URI-safe form before calling\nvar 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 ext = getFileExtension(path); } catch (e) { Logger.logError('getFileExtension IO failure: ' + e); var ext = ''; }","preventionTips":["Use forward slashes and proper file:/// scheme on Windows","Install required commons-vfs provider plugins for remote schemes","Validate remote connectivity before long transformation runs"],"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"}