{"record":{"id":"72bc279e34fa6616","repo":"pentaho/pentaho-kettle","slug":"i-don-t-know-how-to-convert-an-integer-to-binary","errorCode":null,"errorMessage":" : I don't know how to convert an integer to binary.","messagePattern":" : I don't know how to convert an integer to binary\\.","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":2405,"sourceCode":"            throw new KettleValueException( toString() + \" : Unknown storage type \" + storageType + \" specified.\" );\n        }\n      case TYPE_DATE:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a date to binary.\" );\n      case TYPE_STRING:\n        switch ( storageType ) {\n          case STORAGE_TYPE_NORMAL:\n            return convertStringToBinaryString( (String) object );\n          case STORAGE_TYPE_BINARY_STRING:\n            return (byte[]) object;\n          case STORAGE_TYPE_INDEXED:\n            return convertStringToBinaryString( (String) index[( (Integer) object ).intValue()] );\n          default:\n            throw new KettleValueException( toString() + \" : Unknown storage type \" + storageType + \" specified.\" );\n        }\n      case TYPE_NUMBER:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a number to binary.\" );\n      case TYPE_INTEGER:\n        throw new KettleValueException( toString() + \" : I don't know how to convert an integer to binary.\" );\n      case TYPE_BIGNUMBER:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a bignumber to binary.\" );\n      case TYPE_BOOLEAN:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a boolean to binary.\" );\n      case TYPE_SERIALIZABLE:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a serializable to binary.\" );\n\n      default:\n        throw new KettleValueException( toString() + \" : Unknown type \" + type + \" specified.\" );\n    }\n  }\n\n  @Override\n  public byte[] getBinaryString( Object object ) throws KettleValueException {\n    // If the input is a binary string, we should return the exact same binary\n    // object IF\n    // and only IF the formatting options for the storage metadata and this\n    // object are the same.","sourceCodeStart":2387,"sourceCodeEnd":2423,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L2387-L2423","documentation":"ValueMetaBase.getBinary() cannot convert TYPE_INTEGER (long) values into binary bytes; it throws KettleValueException. Binary conversion is only implemented for string-typed values, so integers must be stringified first.","triggerScenarios":"Calling getBinary(object) on a value meta whose type is ValueMetaInterface.TYPE_INTEGER.","commonSituations":"Binary file output of integer fields; plugin code calling getBinary on all row fields regardless of type; serialization utilities applied to numeric columns.","solutions":["Convert the integer to a string first (vm.getString(value)) then call getBinary on a TYPE_STRING meta.","Change the field's value meta to TYPE_STRING if byte output is required.","Use getString() with a conversion mask instead of binary access.","Catch KettleValueException and format integer fields explicitly."],"exampleFix":"// before\nValueMetaInterface vm = new ValueMeta(\"i\", ValueMetaInterface.TYPE_INTEGER);\nbyte[] b = vm.getBinary(42L); // throws\n// after\nString s = vm.getString(42L);\nValueMetaInterface vmStr = new ValueMeta(\"i\", ValueMetaInterface.TYPE_STRING);\nbyte[] b = vmStr.getBinary(s);","handlingStrategy":"type-guard","validationCode":"if (meta.getType() == ValueMetaInterface.TYPE_INTEGER) { throw new IllegalArgumentException(\"Field \" + meta.getName() + \" is an integer; convert to String before getBinary()\"); }","typeGuard":"boolean isBinaryReadable(ValueMetaInterface vm) { return vm.getType() == ValueMetaInterface.TYPE_STRING || vm.getType() == ValueMetaInterface.TYPE_BINARY; }","tryCatchPattern":"try { byte[] b = vm.getBinary(value); } catch (KettleValueException e) { byte[] b = vm.getString(value).getBytes(StandardCharsets.UTF_8); }","preventionTips":["Stringify integers before byte-level output.","Check meta.getType() before calling getBinary().","Prefer getString() as the universal accessor.","Normalize types early with Select Values conversions."],"tags":["kettle","binary","type-mismatch"],"backgroundTag":"incompatible-source-type","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"}