pentaho/pentaho-kettle · error · RuntimeException

Could not apply local format for

Error message

Could not apply local format for 

What it means

When str2date() is called with one argument, it parses the string with the JVM's default locale SimpleDateFormat. If parsing fails (ParseException or the argument is not a string), it throws this RuntimeException including the offending string and the parser's message. It means the string does not match the default locale's date format.

Solutions

  1. Always pass an explicit format: str2date(value, 'dd/MM/yyyy') instead of relying on the locale default.
  2. Check the JVM default locale (-Duser.language/-Duser.country) and align it with your data.
  3. Trim or validate the input string; empty strings fail parsing.
  4. Pre-validate the string matches the expected pattern before calling str2date.

Example fix

// before
var d = str2date(row.dateString); // depends on JVM locale
// after
var d = str2date(row.dateString, 'dd/MM/yyyy');
Defensive patterns

Strategy: try-catch

Validate before calling

if (s == null || !/\d{2}\/\d{2}\/\d{4}/.test(String(s))) { logError('bad date string: ' + s); } else { var d = str2date(s, 'dd/MM/yyyy'); }

Type guard

function looksLikeDate(v) { return v != null && String(v).trim().length > 0; }

Try / catch

try { var d = str2date(s); } catch (e) { logError('parse failed for ' + s + ': ' + e.message); d = null; }

Prevention

When it happens

Trigger: Calling str2date('13/09/2026') on a JVM whose default locale expects MM/dd/yyyy, or passing a non-parseable string like 'not-a-date'.

Common situations: Locale mismatch between the machine that produced the data and the Kettle server (e.g. German dd.MM.yyyy data parsed with US locale); running on a server with a different default locale than the developer workstation; empty or whitespace strings.

Related errors


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

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1009

    String sArg4 = "";
    switch ( ArgList.length ) {
      case 0:
        throw new RuntimeException( "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 undefinedValue;
          }
          sArg1 = (String) ArgList[0];
          Format dfFormatter = new SimpleDateFormat();
          oRC = dfFormatter.parseObject( sArg1 );
          // if(Double.isNaN(sArg1)) throw new RuntimeException("The first Argument must be a Number.");
          // DecimalFormat formatter = new DecimalFormat();
          // sRC= formatter.format(sArg1);
        } catch ( Exception e ) {
          throw new RuntimeException( "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 undefinedValue;
          }
          sArg1 = (String) ArgList[0];
          sArg2 = (String) ArgList[1];
          Format dfFormatter = new SimpleDateFormat( sArg2 );
          oRC = dfFormatter.parseObject( sArg1 );
        } catch ( Exception e ) {
          throw new RuntimeException( "Could not apply the given format "
            + sArg2 + " on the string for " + sArg1 + " : " + e.getMessage() );
        }
        break;

View on GitHub (pinned to f3058517a1)