{"record":{"id":"fc0bf70bc7058a14","repo":"pentaho/pentaho-kettle","slug":"the-round-custom-arg-c-has-incorrect-value-valuec","errorCode":null,"errorMessage":"The 'round_custom' arg C has incorrect value: ${valueC}","messagePattern":"The 'round_custom' arg C has incorrect value: (.+?)","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/ValueDataUtil.java","lineNumber":1331,"sourceCode":"   * @param metaB\n   *          Metadata of decimal places\n   * @param dataB\n   *          decimal places\n   * @param metaC\n   *          Metadata of rounding mode\n   * @param dataC\n   *          rounding mode, e.g. java.math.BigDecimal.ROUND_HALF_EVEN\n   * @return The rounded value\n   * @throws KettleValueException\n   */\n  public static Object round( ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB,\n      ValueMetaInterface metaC, Object dataC ) throws KettleValueException {\n    if ( dataA == null || dataB == null || dataC == null ) {\n      return null;\n    }\n    Long valueC = metaC.getInteger( dataC );\n    if ( valueC == null || valueC < Const.ROUND_HALF_CEILING || valueC > BigDecimal.ROUND_HALF_EVEN ) {\n      throw new KettleValueException( \"The 'round_custom' arg C has incorrect value: \" + valueC );\n    }\n    int roundingMode = valueC.intValue();\n    return round( metaA, dataA, metaB, dataB, roundingMode );\n  }\n\n  public static Object ceil( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {\n    if ( dataA == null ) {\n      return null;\n    }\n    switch ( metaA.getType() ) {\n      case ValueMetaInterface.TYPE_NUMBER:\n        return new Double( Math.ceil( metaA.getNumber( dataA ).doubleValue() ) );\n      case ValueMetaInterface.TYPE_INTEGER:\n        return metaA.getInteger( dataA );\n      case ValueMetaInterface.TYPE_BIGNUMBER:\n        return new BigDecimal( Math.ceil( metaA.getNumber( dataA ).doubleValue() ) );\n\n      default:","sourceCodeStart":1313,"sourceCodeEnd":1349,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/ValueDataUtil.java#L1313-L1349","documentation":"The round_custom helper takes a third argument C specifying the rounding mode, validated to be between Const.ROUND_HALF_CEILING and BigDecimal.ROUND_HALF_EVEN inclusive. If C is null or outside that range, this KettleValueException is thrown with the offending value. This guards against arbitrary integers being used as Java rounding modes.","triggerScenarios":"Calling round_custom (Calculator 'Round custom') where field C converts to an Integer outside the valid rounding-mode constants (e.g. 5, -1, or an empty/null field), because valid modes here span only 1..7 (ROUND_HALF_CEILING..ROUND_HALF_EVEN).","commonSituations":"User enters a rounding mode number that is not one of the documented PDI rounding constants; field C is empty or contains a garbage value; passing java.math.RoundingMode ordinals that don't line up with the accepted legacy int constants.","solutions":["Set field C to a valid rounding mode constant: use 1 (ROUND_HALF_CEILING/default), 2 (ROUND_HALF_DOWN), 4 (ROUND_HALF_UP), 5 (HALF_EVEN), 6 (CEILING), or the documented PDI range values.","Ensure the C field is non-null and typed Integer in the Calculator step.","Use a Value Mapper or Case step to normalize arbitrary mode inputs to supported constants before the calculation."],"exampleFix":"// before: round_custom(A, B, C) with C=9\n// after: round_custom(A, B, C) with C=4  // BigDecimal.ROUND_HALF_UP, inside valid range","handlingStrategy":"validation","validationCode":"Long valueC = metaC.getInteger(dataC);\nint min = Const.ROUND_HALF_CEILING;\nint max = BigDecimal.ROUND_HALF_EVEN;\nif (valueC == null || valueC < min || valueC > max) {\n  throw new KettleValueException(\"rounding mode must be between \" + min + \" and \" + max + \", got \" + valueC);\n}","typeGuard":"public static boolean isValidRoundingMode(Long mode) {\n  return mode != null && mode >= Const.ROUND_HALF_CEILING && mode <= BigDecimal.ROUND_HALF_EVEN;\n}","tryCatchPattern":"try {\n  result = ValueDataUtil.roundCustom(metaA, dataA, metaB, dataB, metaC, dataC);\n} catch (KettleValueException e) {\n  logError(\"Invalid rounding mode in arg C: \" + e.getMessage());\n  result = ValueDataUtil.round(metaA, dataA, metaB, dataB); // fallback to default rounding\n}","preventionTips":["Only pass documented PDI rounding constants (values within ROUND_HALF_CEILING..ROUND_HALF_EVEN), not arbitrary ints or java.math.RoundingMode ordinals.","Ensure the mode field is populated for every row (default empty values with an 'If field is null' step).","Use a Value Mapper to normalize free-text rounding names to supported constants."],"tags":["kettle","pdi","rounding","argument-validation"],"backgroundTag":"value-out-of-range","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"}