pentaho/pentaho-kettle · error · KettleValueException

<toString()> : couldn't convert String to Integer

Error message

<toString()> : couldn't convert String to Integer

What it means

Generic fallback in ValueMetaBase.convertStringToInteger: any unexpected Exception while parsing/formatting the string as an integer is rethrown as a KettleValueException with this message and the original cause attached. It covers everything not caught earlier, e.g. unparseable text, null format issues, or non-numeric strings.

Solutions

  1. Inspect the chained cause (getCause()) to see the underlying parse problem, then fix the offending data.
  2. Set the correct conversion mask / locale (setDecimalFormatSymbol/locale) on the ValueMeta so the string parses.
  3. Handle empty/placeholder strings before conversion (map '', 'NULL', '-' to null via the input step's null-if settings).
  4. Convert the field to String first, clean it (trim, strip grouping separators), then convert to Integer.

Example fix

// before: '1.234,5' with default US locale fails
ValueMetaInterface vm = new ValueMetaInteger("qty");
vm.setConversionMask("####0");
// after: set the right grouping/decimal symbols or clean input
vm.setGroupingSymbol(".");
vm.setDecimalSymbol(","); // now '1.234,5' parses
Defensive patterns

Strategy: validation

Validate before calling

if (s == null || s.trim().isEmpty() || !s.trim().matches("-?\\d+(\\.0+)?")) {
    throw new IllegalArgumentException("Not an integer: " + s);
}

Type guard

static boolean isParseableInteger(String s) { try { Long.parseLong(s.trim()); return true; } catch (Exception e) { return false; } }

Try / catch

try {
    Integer v = (Integer) valueMeta.convertData(stringMeta, raw);
} catch (KettleValueException e) {
    log.warn("Conversion failed for field " + valueMeta.getName() + ": " + e.getCause());
}

Prevention

When it happens

Trigger: convertStringToInteger(String) receives a string that NumberFormat.parse / the internal path cannot handle (e.g. '', 'abc', locale-formatted '1,234' under a mismatched locale) causing an exception inside the try block.

Common situations: CSV/text input columns typed as Integer containing blanks or garbage; locale mismatch (decimal comma vs point); null-ish placeholder strings like 'NULL' or '-' being converted.

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/ca3026b1a37360a3. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java:1360

            + " : couldn't convert String to number : non-numeric character found at position "
            + ( parsePosition.getIndex() + 1 ) + " for value [" + string + "]" );
        }
      }

      if ( number instanceof Double && ( number.doubleValue() < Long.MIN_VALUE
        || number.doubleValue() > Long.MAX_VALUE ) ) {
        log.logBasic( "Value [" + string + "] is out of range for Integer." );
        if ( !ignoreOutOfRange ) {
          throw new KettleValueException( toString()
            + " : couldn't convert String to Integer : value Out of Range [" + string
            + "]. Change the destination data type or round to the nearest value possible for Integer by setting "
            + "property KETTLE_IGNORE_OUT_OF_RANGE_EXCEPTION to \"Y\". " );
        }
      }

      return new Long( number.longValue() );
    } catch ( Exception e ) {
      throw new KettleValueException( toString() + " : couldn't convert String to Integer", e );
    }
  }

  protected synchronized String convertBigNumberToString( BigDecimal number ) throws KettleValueException {
    if ( number == null ) {
      return null;
    }

    try {
      return getDecimalFormat( bigNumberFormatting ).format( number );
    } catch ( Exception e ) {
      throw new KettleValueException( toString() + " : couldn't convert BigNumber to String ", e );
    }
  }

  protected synchronized BigDecimal convertStringToBigNumber( String string ) throws KettleValueException {
    string = Const.trimToType( string, getTrimType() ); // see if trimming needs
    // to be performed before

View on GitHub (pinned to f3058517a1)