{"record":{"id":"9a63305a1e2c50a0","repo":"pentaho/pentaho-kettle","slug":"could-not-apply-local-format-for","errorCode":null,"errorMessage":"Could not apply local format for ","messagePattern":"Could not apply local format for ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1009,"sourceCode":"    String sArg4 = \"\";\n    switch ( ArgList.length ) {\n      case 0:\n        throw new RuntimeException( \"Please provide a valid string to the function call str2date.\" );\n      case 1:\n        try {\n          if ( isNull( ArgList[0] ) ) {\n            return null;\n          } else if ( isUndefined( ArgList[0] ) ) {\n            return undefinedValue;\n          }\n          sArg1 = (String) ArgList[0];\n          Format dfFormatter = new SimpleDateFormat();\n          oRC = dfFormatter.parseObject( sArg1 );\n          // if(Double.isNaN(sArg1)) throw new RuntimeException(\"The first Argument must be a Number.\");\n          // DecimalFormat formatter = new DecimalFormat();\n          // sRC= formatter.format(sArg1);\n        } catch ( Exception e ) {\n          throw new RuntimeException( \"Could not apply local format for \" + sArg1 + \" : \" + e.getMessage() );\n        }\n        break;\n      case 2:\n        try {\n          if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n            return null;\n          } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n            return undefinedValue;\n          }\n          sArg1 = (String) ArgList[0];\n          sArg2 = (String) ArgList[1];\n          Format dfFormatter = new SimpleDateFormat( sArg2 );\n          oRC = dfFormatter.parseObject( sArg1 );\n        } catch ( Exception e ) {\n          throw new RuntimeException( \"Could not apply the given format \"\n            + sArg2 + \" on the string for \" + sArg1 + \" : \" + e.getMessage() );\n        }\n        break;","sourceCodeStart":991,"sourceCodeEnd":1027,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L991-L1027","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","solutions":["Always pass an explicit format: str2date(value, 'dd/MM/yyyy') instead of relying on the locale default.","Check the JVM default locale (-Duser.language/-Duser.country) and align it with your data.","Trim or validate the input string; empty strings fail parsing.","Pre-validate the string matches the expected pattern before calling str2date."],"exampleFix":"// before\nvar d = str2date(row.dateString); // depends on JVM locale\n// after\nvar d = str2date(row.dateString, 'dd/MM/yyyy');","handlingStrategy":"try-catch","validationCode":"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'); }","typeGuard":"function looksLikeDate(v) { return v != null && String(v).trim().length > 0; }","tryCatchPattern":"try { var d = str2date(s); } catch (e) { logError('parse failed for ' + s + ': ' + e.message); d = null; }","preventionTips":["Always pass an explicit format string","Pin -Duser.language/-Duser.country on servers","Trim inputs before parsing"],"tags":["date","locale","parsing","scripting"],"backgroundTag":"invalid-date-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"}