{"record":{"id":"7a26f068b823ae8a","repo":"pentaho/pentaho-kettle","slug":"scriptvaluesmetamod-exception-numberformatexception","errorCode":null,"errorMessage":"ScriptValuesMetaMod.Exception.NumberFormatException","messagePattern":"ScriptValuesMetaMod\\.Exception\\.NumberFormatException","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java","lineNumber":186,"sourceCode":"        }\n      }\n\n      // set the optimization level\n      data.cx = ContextFactory.getGlobal().enterContext();\n\n      try {\n        String optimizationLevelAsString = environmentSubstitute( meta.getOptimizationLevel() );\n        if ( !Utils.isEmpty( Const.trim( optimizationLevelAsString ) ) ) {\n          data.cx.setOptimizationLevel( Integer.parseInt( optimizationLevelAsString.trim() ) );\n          logBasic( BaseMessages.getString( PKG, \"ScriptValuesMod.Optimization.Level\", environmentSubstitute( meta\n            .getOptimizationLevel() ) ) );\n        } else {\n          data.cx.setOptimizationLevel( Integer.parseInt( ScriptValuesMetaMod.OPTIMIZATION_LEVEL_DEFAULT ) );\n          logBasic( BaseMessages.getString(\n            PKG, \"ScriptValuesMod.Optimization.UsingDefault\", ScriptValuesMetaMod.OPTIMIZATION_LEVEL_DEFAULT ) );\n        }\n      } catch ( NumberFormatException nfe ) {\n        throw new KettleStepException( BaseMessages.getString(\n          PKG, \"ScriptValuesMetaMod.Exception.NumberFormatException\", environmentSubstitute( meta\n            .getOptimizationLevel() ) ) );\n      } catch ( IllegalArgumentException iae ) {\n        throw new KettleException( iae.getMessage() );\n      }\n\n      data.scope = data.cx.initStandardObjects( null, false );\n\n      bFirstRun = true;\n\n      Scriptable jsvalue = Context.toObject( this, data.scope );\n      data.scope.put( \"_step_\", data.scope, jsvalue );\n\n      // Adding the existing Scripts to the Context\n      for ( int i = 0; i < meta.getNumberOfJSScripts(); i++ ) {\n        Scriptable jsR = Context.toObject( jsScripts[ i ].getScript(), data.scope );\n        data.scope.put( jsScripts[ i ].getScriptName(), data.scope, jsR );\n      }","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java#L168-L204","documentation":"When no explicit Rhino optimization level is set, ScriptValuesMod falls back to parsing ScriptValuesMetaMod.OPTIMIZATION_LEVEL_DEFAULT with Integer.parseInt(); a NumberFormatException is caught and rethrown as a KettleStepException with the message ScriptValuesMetaMod.Exception.NumberFormatException. It means the configured (or substituted) optimization-level value is not a valid integer.","triggerScenarios":"environmentSubstitute(meta.getOptimizationLevel()) yields a string that Integer.parseInt() cannot parse — e.g. a variable like ${OPT_LEVEL} resolves to empty, non-numeric text, or contains whitespace/units, and the code attempts Integer.parseInt on the default/actual value inside addValues().","commonSituations":"Optimization level field left blank or containing a Kettle variable that is undefined at runtime (substitutes to empty or literal '${VAR}'); user typed '0.5' or '-1 fast' or a thousand-separated number; value comes from an environment variable set on a server with the wrong content.","solutions":["Open the step's Optimization level field and set a plain integer (typically -1 for interpreted mode or 0/9 for Rhino levels).","If a Kettle variable is used, verify it is defined (kettle.properties / transformation parameter) and resolves to digits only at runtime.","Trim the value: remove spaces, quotes, or trailing characters; enter exactly one integer token.","Remove any units or comments from the field; the parser accepts only [-+]?digits."],"exampleFix":"// before (step dialog / ktr XML)\n<optimizationLevel>${JS_OPT_LEVEL}</optimizationLevel>  <!-- variable undefined -> substitution empty -->\n// after\n<optimizationLevel>-1</optimizationLevel>  <!-- or define JS_OPT_LEVEL=-1 in kettle.properties -->","handlingStrategy":"validation","validationCode":"// Java, validate the optimization level before building the step meta\nString lvl = environmentSubstitute(meta.getOptimizationLevel());\nif (lvl != null) {\n  try { Integer.parseInt(lvl.trim()); }\n  catch (NumberFormatException nfe) {\n    throw new IllegalArgumentException(\"Optimization level must be an integer, got: '\" + lvl + \"'\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  transformation.execute(params);\n} catch (KettleStepException e) {\n  if (e.getMessage().contains(\"NumberFormatException\")) {\n    // fix the Optimization level field or the Kettle variable it references, retry\n  } else { throw e; }\n}","preventionTips":["Enter only plain integers (-1, 0, 9) in the Optimization level field.","If using a variable, define it in kettle.properties or as a parameter and confirm its value at runtime.","Avoid whitespace, units, decimals, and comments in numeric config fields.","Add a transformation-level parameter with a numeric default so the substitution is never empty."],"tags":["kettle","pentaho","number-format","configuration"],"backgroundTag":"invalid-argument-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"}