pentaho/pentaho-kettle · error · RuntimeException

Could not apply the local format for locale " + sArg3 + "…

Error message

Could not apply the local format for locale " + sArg3 + " with the given format " + sArg2 + " on the string for " + sArg1 + " : " + e.getMessage()

What it means

Catch-all rethrow in the 3-argument branch of str2date: any exception while parsing (bad format pattern, unparseable date string, invalid locale, null args) is wrapped into this RuntimeException with the locale, format, and input string plus the underlying message. It means the date string could not be parsed using the given pattern in the given locale.

Solutions

  1. Read e.getMessage() appended to this error: it names the real cause (e.g. Unparseable date).
  2. Make the format argument exactly match the input string (test the pattern with the same locale in plain Java).
  3. Ensure the third argument is a 2-letter locale code.
  4. Guard null/empty input before calling str2date, or rely on the built-in isNull handling by passing valid data only.
  5. Use a try/catch in the script to log the offending row value and skip or default it.

Example fix

// before
var d = str2date(dateField, 'MM/dd/yyyy', 'en'); // dateField is '2024-01-01'
// after
var d = str2date(dateField, 'yyyy-MM-dd', 'en');
Defensive patterns

Strategy: try-catch

Validate before calling

function safeStr2date(s, fmt, loc) {
  if (s == null || s === '') return null;
  if (typeof loc === 'string' && loc.length !== 2) loc = loc.substring(0, 2);
  // verify pattern matches shape before parsing
  return str2date(s, fmt, loc);
}

Type guard

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

Try / catch

try { var d = str2date(s, fmt, loc); } catch (e) { Logger.log('str2date failed for value=[' + s + '] fmt=[' + fmt + '] loc=[' + loc + ']: ' + e.message); d = null; }

Prevention

When it happens

Trigger: str2date(dateStr, format, locale) where SimpleDateFormat.parseObject throws — pattern mismatch (e.g. str2date('01/02/2024','yyyy-MM-dd','en')), locale whose month/day names don't match the string, or the nested 'Locale is not 2 characters long' error.

Common situations: Format string doesn't match the actual date layout; input field is not a string or contains extra whitespace; locale given in wrong case or wrong length; data contains null/empty values reaching the parser.

Related errors


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

Appendix: source

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

        try {
          if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
            return null;
          } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
            return undefinedValue;
          }
          sArg1 = (String) ArgList[0];
          Format dfFormatter;
          sArg2 = (String) ArgList[1];
          sArg3 = (String) ArgList[2];
          if ( sArg3.length() == 2 ) {
            Locale dfLocale = EnvUtil.createLocale( sArg3 );
            dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
            oRC = dfFormatter.parseObject( sArg1 );
          } else {
            throw new RuntimeException( "Locale " + sArg3 + " is not 2 characters long." );
          }
        } catch ( Exception e ) {
          throw new RuntimeException( "Could not apply the local format for locale "
            + sArg3 + " with the given format " + sArg2 + " on the string for " + sArg1 + " : " + e.getMessage() );
        }
        break;
      case 4:
        try {
          if ( isNull( ArgList, new int[] { 0, 1, 2, 3 } ) ) {
            return null;
          } else if ( isUndefined( ArgList, new int[] { 0, 1, 2, 3 } ) ) {
            return undefinedValue;
          }
          sArg1 = (String) ArgList[0];
          DateFormat dfFormatter;
          sArg2 = (String) ArgList[1];
          sArg3 = (String) ArgList[2];
          sArg4 = (String) ArgList[3];

          // If the timezone is not recognized, java will automatically
          // take GMT.

View on GitHub (pinned to f3058517a1)