pentaho/pentaho-kettle · error · JavaScriptException

Could not apply the given format on the number

Error message

Could not apply the given format on the number : {e.getMessage()}

What it means

After validating the number, the 1-argument num2str formats it with a default DecimalFormat. If DecimalFormat.format throws IllegalArgumentException, the function rethrows this error embedding the underlying exception message. It means the number formatting operation itself failed unexpectedly.

Solutions

  1. Check the JVM's default locale settings (-Duser.language, -Duser.country) and ensure they form a valid locale.
  2. Use the 2-argument form with an explicit valid format pattern to bypass default-locale formatting.
  3. Inspect e.getMessage() in the error for the concrete DecimalFormat cause and fix that configuration.

Example fix

// before (relies on broken default locale)
var s = num2str(value);

// after (explicit pattern)
var s = num2str(value, "#.##");
Defensive patterns

Strategy: try-catch

Try / catch

// In JS step you cannot catch Rhino runtime errors from added functions reliably;
// fix the environment instead: verify JVM locale flags are valid,
// or bypass the default formatter by passing an explicit pattern.
var s = num2str(value, "#.##");

Prevention

When it happens

Trigger: DecimalFormat.format(double) throwing IllegalArgumentException during default-locale formatting — rare, but triggered by broken default locale configuration (Locale with invalid patterns) or a JVM-level DecimalFormat failure surfaced via the catch block.

Common situations: Pentaho/Kettle server JVM running with a malformed default locale (user.language/user.country settings); custom DecimalFormat provider issues; running under an unusual Java version where default pattern handling changed.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

    String sRC = "";
    switch ( ArgList.length ) {
      case 0:
        throw Context.reportRuntimeError( "The function call num2str requires at least 1 argument." );
      case 1:
        try {
          if ( isNull( ArgList[0] ) ) {
            return null;
          } else if ( isUndefined( ArgList[0] ) ) {
            return (String) Context.getUndefinedValue();
          }
          double sArg1 = Context.toNumber( ArgList[0] );
          if ( Double.isNaN( sArg1 ) ) {
            throw Context.reportRuntimeError( "The first Argument must be a Number." );
          }
          DecimalFormat formatter = new DecimalFormat();
          sRC = formatter.format( sArg1 );
        } catch ( IllegalArgumentException e ) {
          throw Context.reportRuntimeError( "Could not apply the given format on the number : " + e.getMessage() );
        }
        break;
      case 2:
        try {
          if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
            return null;
          } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
            return (String) Context.getUndefinedValue();
          }
          double sArg1 = Context.toNumber( ArgList[0] );
          if ( Double.isNaN( sArg1 ) ) {
            throw Context.reportRuntimeError( "The first Argument must be a Number." );
          }
          String sArg2 = Context.toString( ArgList[1] );
          DecimalFormat formatter = new DecimalFormat( sArg2 );
          sRC = formatter.format( sArg1 );
        } catch ( IllegalArgumentException e ) {
          throw Context.reportRuntimeError( "Could not apply the given format on the number : " + e.getMessage() );

View on GitHub (pinned to f3058517a1)