pentaho/pentaho-kettle · error · JavaScriptException

Could not apply local format for

Error message

Could not apply local format for {sArg1} : {e.getMessage()}

What it means

Parsing failure in the 1-argument branch of str2date: the input string could not be parsed with the default locale SimpleDateFormat. The generic catch wraps the underlying ParseException message, naming the offending input (sArg1).

Solutions

  1. Pass a matching format pattern as the second argument, e.g. str2date("31/01/2024", "dd/MM/yyyy")
  2. Verify the input string actually contains a parseable date
  3. Add a locale and timezone if the default locale misinterprets the string
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1039 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

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

    String sArg4 = "";
    switch ( ArgList.length ) {
      case 0:
        throw Context.reportRuntimeError( "Please provide a valid string to the function call str2date." );
      case 1:
        try {
          if ( isNull( ArgList[0] ) ) {
            return null;
          } else if ( isUndefined( ArgList[0] ) ) {
            return Context.getUndefinedValue();
          }
          sArg1 = Context.toString( ArgList[0] );
          Format dfFormatter = new SimpleDateFormat();
          oRC = dfFormatter.parseObject( sArg1 );
          // if(Double.isNaN(sArg1)) throw Context.reportRuntimeError("The first Argument must be a Number.");
          // DecimalFormat formatter = new DecimalFormat();
          // sRC= formatter.format(sArg1);
        } catch ( Exception e ) {
          throw Context.reportRuntimeError( "Could not apply local format for " + sArg1 + " : " + e.getMessage() );
        }
        break;
      case 2:
        try {
          if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
            return null;
          } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
            return Context.getUndefinedValue();
          }
          sArg1 = Context.toString( ArgList[0] );
          sArg2 = Context.toString( ArgList[1] );
          Format dfFormatter = new SimpleDateFormat( sArg2 );
          oRC = dfFormatter.parseObject( sArg1 );
        } catch ( Exception e ) {
          throw Context.reportRuntimeError( "Could not apply the given format "
            + sArg2 + " on the string for " + sArg1 + " : " + e.getMessage() );
        }
        break;

View on GitHub (pinned to f3058517a1)