{"record":{"id":"4b9ad0b8133949cf","repo":"pentaho/pentaho-kettle","slug":"unexpected-conversion-error-while-converting-value-tostring-4b9ad0","errorCode":null,"errorMessage":"Unexpected conversion error while converting value [\" + toString() + \"] to an Integer","messagePattern":"Unexpected conversion error while converting value \\[\" \\+ toString\\(\\) \\+ \"\\] to an Integer","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":2136,"sourceCode":"            case STORAGE_TYPE_NORMAL:\n              return convertBooleanToInteger( (Boolean) object );\n            case STORAGE_TYPE_BINARY_STRING:\n              return convertBooleanToInteger( (Boolean) convertBinaryStringToNativeType( (byte[]) object ) );\n            case STORAGE_TYPE_INDEXED:\n              return convertBooleanToInteger( (Boolean) index[( (Integer) object ).intValue()] );\n            default:\n              throw new KettleValueException( toString() + \" : Unknown storage type \" + storageType + \" specified.\" );\n          }\n        case TYPE_BINARY:\n          throw new KettleValueException( toString() + \" : I don't know how to convert binary values to integers.\" );\n        case TYPE_SERIALIZABLE:\n          throw new KettleValueException( toString()\n              + \" : I don't know how to convert serializable values to integers.\" );\n        default:\n          throw new KettleValueException( toString() + \" : Unknown type \" + type + \" specified.\" );\n      }\n    } catch ( Exception e ) {\n      throw new KettleValueException( \"Unexpected conversion error while converting value [\" + toString()\n          + \"] to an Integer\", e );\n    }\n  }\n\n  @Override\n  public BigDecimal getBigNumber( Object object ) throws KettleValueException {\n    try {\n      if ( isNull( object ) ) {\n        return null;\n      }\n      switch ( type ) {\n        case TYPE_BIGNUMBER:\n          switch ( storageType ) {\n            case STORAGE_TYPE_NORMAL:\n              return (BigDecimal) object;\n            case STORAGE_TYPE_BINARY_STRING:\n              return (BigDecimal) convertBinaryStringToNativeType( (byte[]) object );\n            case STORAGE_TYPE_INDEXED:","sourceCodeStart":2118,"sourceCodeEnd":2154,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L2118-L2154","documentation":"This is the catch-all wrapper in ValueMetaBase.getInteger(): any Exception thrown while converting the value to a Long (typically ClassCastException, NullPointerException on casts, or NumberFormatException inside converters) is rethrown as KettleValueException 'Unexpected conversion error while converting value [<meta>] to an Integer' with the original as cause. It means the stored object's runtime class did not match what the metadata type/storage type promised.","triggerScenarios":"Any mismatch between the object's actual runtime type and the metadata's declared type/storage type inside getInteger(Object): e.g. a String stored under TYPE_INTEGER+STORAGE_TYPE_NORMAL, a byte[] not decoded where expected, or an indexed storage value of wrong element type. Check getCause() for the real exception.","commonSituations":"Steps writing raw strings into nominally numeric fields; data migrated from CSV/database steps without proper conversion metadata; plugins that construct rows manually without respecting rowMeta types.","solutions":["Inspect the cause chain (KettleValueException.getCause()) to see the real ClassCastException/NumberFormatException","Make the value's runtime class match the metadata: use meta.convertData(sourceMeta, data) or write the value via the correct typed meta","Normalize incoming data with a 'Value Mapper'/'Fieldtype change' or call ValueDataUtil / StringMeta conversion before numeric access","If data comes from text, declare the field TYPE_STRING with STORAGE_TYPE_BINARY_STRING so Kettle parses it lazily with the conversion mask"],"exampleFix":"// before\n// row field declared Long (TYPE_INTEGER) but contains String \"123\"\nLong n = valueMeta.getInteger(row[i]); // ClassCastException -> wrapped\n// after\nValueMetaInterface stringMeta = new ValueMetaString(\"col\");\nrow[i] = valueMeta.convertData(stringMeta, row[i]); // parse string to Long\nLong n = valueMeta.getInteger(row[i]);","handlingStrategy":"try-catch","validationCode":"// verify runtime type matches declared metadata before converting\nif (object != null && meta.getType() == ValueMetaInterface.TYPE_INTEGER\n    && !(object instanceof Long)) {\n  object = meta.convertData(new ValueMetaString(meta.getName()), object); // coerce\n}","typeGuard":"boolean matchesDeclaredType(ValueMetaInterface m, Object v) {\n  if (v == null) return true;\n  switch (m.getType()) {\n    case ValueMetaInterface.TYPE_INTEGER: return v instanceof Long;\n    case ValueMetaInterface.TYPE_NUMBER: return v instanceof Double;\n    case ValueMetaInterface.TYPE_BIGNUMBER: return v instanceof java.math.BigDecimal;\n    case ValueMetaInterface.TYPE_STRING: return v instanceof String;\n    case ValueMetaInterface.TYPE_DATE: return v instanceof java.util.Date;\n    case ValueMetaInterface.TYPE_BOOLEAN: return v instanceof Boolean;\n    default: return true;\n  }\n}","tryCatchPattern":"try {\n  Long n = meta.getInteger(object);\n} catch (KettleValueException e) {\n  Throwable cause = e.getCause();\n  log.error(\"Conversion failed for \" + meta.getName() + \": \"\n      + (cause != null ? cause.toString() : e.getMessage()));\n  // send row to error stream\n}","preventionTips":["Always check getCause() on wrapped KettleValueExceptions","Use meta.convertData(sourceMeta, data) for cross-type assignment","Inspect incoming data types with a sample row before wiring conversions","Use Kettle's 'Fields select'/calculator steps instead of manual casts"],"tags":["kettle","pdi","classcastexception","type-mismatch","conversion"],"backgroundTag":"type-mismatch","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"}