{"record":{"id":"ee1471196f7d2832","repo":"pentaho/pentaho-kettle","slug":"error-in-ismailvalid-function","errorCode":null,"errorMessage":"Error in isMailValid function: ","messagePattern":"Error in isMailValid function: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2699,"sourceCode":"        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 ) {\n          return Boolean.FALSE;\n        }\n\n        String email = Context.toString( ArgList[0] );\n        if ( email.indexOf( '@' ) == -1 || email.indexOf( '.' ) == -1 ) {\n          return Boolean.FALSE;\n        }\n\n        isValid = Boolean.TRUE;\n\n      } catch ( Exception e ) {\n        throw Context.reportRuntimeError( \"Error in isMailValid function: \" + e.getMessage() );\n      }\n      return isValid;\n    } else {\n      throw Context.reportRuntimeError( \"The function call isMailValid is not valid\" );\n    }\n  }\n\n  public static String escapeXml( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      return Const.escapeXML( Context.toString( ArgList[0] ) );\n    } else {\n      throw Context.reportRuntimeError( \"The function call escapeXml requires 1 argument.\" );\n\n    }\n  }\n\n  public static String escapeHtml( Context actualContext, Scriptable actualObject, Object[] ArgList,","sourceCodeStart":2681,"sourceCodeEnd":2717,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2681-L2717","documentation":"isMailValid(value) checks an email address format and returns a Boolean. Any exception during validation (conversion or pattern-check failure on the given value) is rethrown with this prefix and the underlying message appended. The value must be convertible to a string for the regex/format test to run.","triggerScenarios":"Calling isMailValid with a null or non-convertible value whose processing throws inside the try block, while the argument count is otherwise correct.","commonSituations":"Email field null from source data; field typed as non-string; internationalized/odd encodings breaking conversions; upstream step delivering binary instead of string.","solutions":["Coerce and null-check first: var ok = (email != null) && isMailValid(email.toString()).","Validate the field is a String in a prior step (Select values type cast).","Treat null emails separately from invalid emails in your logic.","Inspect the appended e.getMessage() to pinpoint the conversion that failed."],"exampleFix":"// before\nvar ok = isMailValid(emailField); // may throw when null\n// after\nvar ok = (emailField != null) && isMailValid(emailField.toString());","handlingStrategy":"validation","validationCode":"function safeMailCheck(v) { if (v == null) return false; try { return isMailValid(v.toString()); } catch (e) { return false; } }","typeGuard":"function isEmailString(v) { return typeof v === 'string' && v.length > 0; }","tryCatchPattern":"try { ok = isMailValid(email); } catch (e) { Logger.LogError('isMailValid failed: ' + e.message); ok = false; }","preventionTips":["Null-check the email field before validation","Ensure the field is typed as String upstream","Route null emails and invalid emails to separate handling paths"],"tags":["javascript","scripting","validation","email"],"backgroundTag":"invalid-argument-format","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"}