{"record":{"id":"52967884db09c7c5","repo":"pentaho/pentaho-kettle","slug":"unexpected-conversion-error-while-converting-value-tostring-529678","errorCode":null,"errorMessage":"Unexpected conversion error while converting value [\" + toString() + \"] to a BigNumber","messagePattern":"Unexpected conversion error while converting value \\[\" \\+ toString\\(\\) \\+ \"\\] to a BigNumber","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":2222,"sourceCode":"          switch ( storageType ) {\n            case STORAGE_TYPE_NORMAL:\n              return convertBooleanToBigNumber( (Boolean) object );\n            case STORAGE_TYPE_BINARY_STRING:\n              return convertBooleanToBigNumber( (Boolean) convertBinaryStringToNativeType( (byte[]) object ) );\n            case STORAGE_TYPE_INDEXED:\n              return convertBooleanToBigNumber( (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 BigDecimals.\" );\n        case TYPE_SERIALIZABLE:\n          throw new KettleValueException( toString() + \" : I don't know how to convert serializable values to BigDecimals.\" );\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 a BigNumber\", e );\n    }\n  }\n\n  @Override\n  public Boolean getBoolean( Object object ) throws KettleValueException {\n    if ( object == null ) {\n      return null;\n    }\n    switch ( type ) {\n      case TYPE_BOOLEAN:\n        switch ( storageType ) {\n          case STORAGE_TYPE_NORMAL:\n            return (Boolean) object;\n          case STORAGE_TYPE_BINARY_STRING:\n            return (Boolean) convertBinaryStringToNativeType( (byte[]) object );\n          case STORAGE_TYPE_INDEXED:\n            return (Boolean) index[( (Integer) object ).intValue()];","sourceCodeStart":2204,"sourceCodeEnd":2240,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L2204-L2240","documentation":"ValueMetaBase.getBigNumber() wraps any unexpected exception thrown during conversion (ClassCastException, NumberFormatException, NPE inside a convert* method, etc.) into a KettleValueException with the message 'Unexpected conversion error while converting value [<field>] to a BigNumber'. The original exception is attached as the cause. It is a defensive wrapper, so the real bug is in the cause chain or in the value's actual type vs declared type.","triggerScenarios":"Any conversion path inside getBigNumber throwing at runtime: e.g. an indexed-storage Integer out of index bounds, a String that fails BigDecimal parsing, a binary-string storage whose native decode yields a non-numeric object.","commonSituations":"Dirty source data (non-numeric text in a numeric column) during ETL; storage-type/index arrays inconsistent with the stored value after metadata cloning; legacy metadata where STORAGE_TYPE_INDEXED points at the wrong value array.","solutions":["Inspect the KettleValueException.getCause() to find the real failure (parse error, cast, index)","Verify the value's runtime class matches the metadata type and storage type before conversion (typeMismatch check)","Sanitize input strings (trim, handle empty/null, conversion mask) or set lenient conversion options"],"exampleFix":"// before\ntry { BigDecimal v = meta.getBigNumber(val); }\ncatch (KettleValueException e) { log.error(e.getMessage()); } // cause swallowed\n// after\ntry { BigDecimal v = meta.getBigNumber(val); }\ncatch (KettleValueException e) {\n  Throwable cause = e.getCause();\n  log.error(\"Field \" + meta.getName() + \" failed: \" + (cause != null ? cause.toString() : e.getMessage()));\n}","handlingStrategy":"try-catch","validationCode":"Object v0 = value;\nif (v0 == null) return null; // nulls are expected, skip conversion\nif (meta.isStorageBinaryString()) v0 = meta.convertBinaryStringToNativeType((byte[]) v0);\nif (!(v0 instanceof BigDecimal || v0 instanceof Number || v0 instanceof String)) {\n  throw new IllegalStateException(\"Value of \" + v0.getClass() + \" will not convert to BigDecimal\");\n}","typeGuard":"boolean convertibleToBigNumber(Object o) {\n  return o == null || o instanceof BigDecimal || o instanceof Number || o instanceof String;\n}","tryCatchPattern":"try {\n  BigDecimal v = meta.getBigNumber(value);\n} catch (KettleValueException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof NumberFormatException) { /* sanitize/repair the string */ }\n  else if (cause instanceof ClassCastException) { /* fix metadata/storage mismatch */ }\n  throw new DataException(\"Field \" + meta.getName(), e);\n}","preventionTips":["Always inspect getCause() on 'Unexpected conversion error' — it names the real bug","Sanitize numeric strings (trim, empty-to-null, locale/decimal separator) before conversion","Keep storage type and stored value class consistent when building rows manually"],"tags":["kettle","pdi","type-conversion","wrapped-exception"],"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"}