pentaho/pentaho-kettle · error

The function call getFileSize is not valid.

Error message

The function call getFileSize is not valid.

What it means

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.

Solutions

  1. Call getFileSize with exactly one string argument: getFileSize('/tmp/f.txt').
  2. Convert fields to strings with .stringValue().
  3. Null/undefined-check the path before calling.
  4. Log the argument value just before the call to confirm.

Example fix

// before
var size = getFileSize(fileObj); // java.io.File
// after
var size = getFileSize(fileObj.getAbsolutePath());
Defensive patterns

Strategy: validation

Validate before calling

var p = (pathField == null) ? null : pathField.stringValue();
if (p == null || p.length === 0) { throw new Error('getFileSize: path required'); }
var size = getFileSize(p);

Type guard

function isNonEmptyString(v){ return typeof v === 'string' && v.length > 0; }

Try / catch

try { size = getFileSize(p); } catch (e) { Logger.logError('getFileSize misuse: ' + e.message); }

Prevention

When it happens

Trigger: getFileSize() with zero arguments, two or more arguments, or a non-string first argument in a Modified Java Script Value step.

Common situations: 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.

Understand the failure class

Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/4f95c30d1f76f4cb. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:2207

            }
          } else {
            Context.reportRuntimeError( "file [" + Context.toString( ArgList[0] ) + "] can not be found!" );
          }
          return filesize;
        } catch ( IOException e ) {
          throw Context.reportRuntimeError( "The function call getFileSize throw an error : " + e.toString() );
        } finally {
          if ( file != null ) {
            try {
              file.close();
            } catch ( Exception e ) {
              // Ignore close errors
            }
          }
        }

      } else {
        throw Context.reportRuntimeError( "The function call getFileSize is not valid." );
      }
    } catch ( Exception e ) {
      throw Context.reportRuntimeError( e.toString() );
    }
  }

  public static boolean isFile( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    try {
      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {
        if ( ArgList[0].equals( null ) ) {
          return false;
        }
        FileObject file = null;

        try {
          // Source file
          file = KettleVFS.getInstance( getBowl( actualObject ) ).getFileObject( Context.toString( ArgList[0] ) );

View on GitHub (pinned to f3058517a1)