{"record":{"id":"e50890f894180f7e","repo":"pentaho/pentaho-kettle","slug":"error-in-isempty-function","errorCode":null,"errorMessage":"Error in isEmpty function: ","messagePattern":"Error in isEmpty function: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2669,"sourceCode":"\n  public static Boolean isEmpty( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isUndefined( ArgList[0] ) ) {\n          throw new Exception( ArgList[0] + \" is  undefined!\" );\n        }\n        if ( isNull( ArgList[0] ) ) {\n          return Boolean.TRUE;\n        }\n        if ( Context.toString( ArgList[0] ).length() == 0 ) {\n          return Boolean.TRUE;\n        } else {\n          return Boolean.FALSE;\n        }\n\n      } catch ( Exception e ) {\n        throw Context.reportRuntimeError( \"Error in isEmpty function: \" + e.getMessage() );\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call isEmpty is not valid\" );\n    }\n  }\n\n  public static Boolean isMailValid( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    Boolean isValid;\n    if ( ArgList.length == 1 ) {\n      try {\n        if ( isUndefined( ArgList[0] ) ) {\n          throw new Exception( ArgList[0] + \" is  undefined!\" );\n        }\n        if ( isNull( ArgList[0] ) ) {\n          return Boolean.FALSE;\n        }\n        if ( Context.toString( ArgList[0] ).length() == 0 ) {","sourceCodeStart":2651,"sourceCodeEnd":2687,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2651-L2687","documentation":"isEmpty(value) tests whether a string/value is empty. This handler wraps any unexpected exception thrown while evaluating the check (e.g. operating on an object type it cannot handle) and rethrows it as a Rhino runtime error prefixed with 'Error in isEmpty function: '. The suffix message from e.getMessage() identifies the underlying cause.","triggerScenarios":"Calling isEmpty with a value whose evaluation throws — e.g. certain non-string Java objects passed from previous steps, or conversion failures on the argument inside the try block while the argument count itself was valid.","commonSituations":"Passing a Java object (e.g. BigDecimal, binary field) rather than a string; null-plus-method-chain mistakes nearby; upstream field type changes after transformation edits.","solutions":["Convert the argument to string first: isEmpty(value == null ? '' : value.toString()).","Null-check before the call since the wrapped helper may not accept all null shapes in your version.","Read the e.getMessage() suffix in the error to identify the actual failing operation.","Normalize field types in a prior step (Select values / type cast) before scripting."],"exampleFix":"// before\nvar e = isEmpty(myBigDec) ;\n// after\nvar e = isEmpty(myBigDec == null ? '' : myBigDec.toString());","handlingStrategy":"type-guard","validationCode":"function safeIsEmpty(v) { if (v == null) return true; try { return isEmpty(v.toString()); } catch (e) { return false; } }","typeGuard":"function isStringish(v) { return v == null || typeof v === 'string' || (v != null && typeof v.toString === 'function'); }","tryCatchPattern":"try { e = isEmpty(val); } catch (ex) { Logger.LogError('isEmpty failed: ' + ex.message); e = true; /* treat as empty */ }","preventionTips":["Convert non-string fields with toString() before checking","Cast field types in a preceding Select values step","Keep the e.getMessage() suffix when logging for root cause"],"tags":["javascript","scripting","type-mismatch","rhino"],"backgroundTag":"type-mismatch","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"}