{"record":{"id":"4f95c30d1f76f4cb","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getfilesize-is-not-valid-4f95c3","errorCode":null,"errorMessage":"The function call getFileSize is not valid.","messagePattern":"The function call getFileSize 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":2207,"sourceCode":"            }\n          } else {\n            Context.reportRuntimeError( \"file [\" + Context.toString( ArgList[0] ) + \"] can not be found!\" );\n          }\n          return filesize;\n        } catch ( IOException e ) {\n          throw Context.reportRuntimeError( \"The function call getFileSize throw an error : \" + e.toString() );\n        } finally {\n          if ( file != null ) {\n            try {\n              file.close();\n            } catch ( Exception e ) {\n              // Ignore close errors\n            }\n          }\n        }\n\n      } else {\n        throw Context.reportRuntimeError( \"The function call getFileSize is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n\n  public static boolean isFile( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {\n        if ( ArgList[0].equals( null ) ) {\n          return false;\n        }\n        FileObject file = null;\n\n        try {\n          // Source file\n          file = KettleVFS.getInstance( getBowl( actualObject ) ).getFileObject( Context.toString( ArgList[0] ) );","sourceCodeStart":2189,"sourceCodeEnd":2225,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2189-L2225","documentation":"getFileSize() throws this when invoked with an argument list that does not match the expected shape (not exactly one string path argument). The size is never computed; Rhino receives a runtime error immediately. Pure API-misuse error.","triggerScenarios":"getFileSize() with zero arguments, two or more arguments, or a non-string first argument in a Modified Java Script Value step.","commonSituations":"Passing a java.io.File or field object rather than a path string; forgetting the argument after refactoring; undefined variable due to no rows from a previous step.","solutions":["Call getFileSize with exactly one string argument: getFileSize('/tmp/f.txt').","Convert fields to strings with .stringValue().","Null/undefined-check the path before calling.","Log the argument value just before the call to confirm."],"exampleFix":"// before\nvar size = getFileSize(fileObj); // java.io.File\n// after\nvar size = getFileSize(fileObj.getAbsolutePath());","handlingStrategy":"validation","validationCode":"var p = (pathField == null) ? null : pathField.stringValue();\nif (p == null || p.length === 0) { throw new Error('getFileSize: path required'); }\nvar size = getFileSize(p);","typeGuard":"function isNonEmptyString(v){ return typeof v === 'string' && v.length > 0; }","tryCatchPattern":"try { size = getFileSize(p); } catch (e) { Logger.logError('getFileSize misuse: ' + e.message); }","preventionTips":["Pass exactly one string argument","Convert field objects with .stringValue()","Null-check variables from previous steps","Log the argument before the call"],"tags":["javascript","pdi","argument-count","file-size"],"backgroundTag":"invalid-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"}