{"record":{"id":"1a58291646bad13e","repo":"apache/iceberg","slug":"invalid-bound-type-primitive","errorCode":null,"errorMessage":"Invalid bound type: <primitive>","messagePattern":"Invalid bound type: <primitive>","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"parquet/src/main/java/org/apache/iceberg/parquet/ParquetVariantUtil.java","lineNumber":174,"sourceCode":"      case DOUBLE:\n        return (T) value;\n      case INT8:\n        return (T) (Byte) ((Number) value).byteValue();\n      case INT16:\n        return (T) (Short) ((Number) value).shortValue();\n      case DECIMAL4:\n      case DECIMAL8:\n        return (T) BigDecimal.valueOf(((Number) value).longValue(), scale);\n      case DECIMAL16:\n        return (T) new BigDecimal(new BigInteger(((Binary) value).getBytes()), scale);\n      case BINARY:\n        return (T) ((Binary) value).toByteBuffer();\n      case STRING:\n        return (T) ((Binary) value).toStringUsingUTF8();\n      case UUID:\n        return (T) UUIDUtil.convert(((Binary) value).getBytes());\n      default:\n        throw new IllegalStateException(\"Invalid bound type: \" + primitive);\n    }\n  }\n\n  /**\n   * Returns a comparator for values of the given primitive {@link PhysicalType type}.\n   *\n   * @param primitive a primitive variant {@link PhysicalType}\n   * @param <T> Java type used for values of the given Variant physical type\n   * @return a comparator for in-memory values of the given type\n   */\n  @SuppressWarnings(\"unchecked\")\n  static <T> Comparator<T> comparator(PhysicalType primitive) {\n    switch (primitive) {\n      case BINARY:\n        return (Comparator<T>) Comparators.unsignedBytes();\n      case STRING:\n        return (Comparator<T>) Comparators.charSequences();\n      default:","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/parquet/src/main/java/org/apache/iceberg/parquet/ParquetVariantUtil.java#L156-L192","documentation":"ParquetVariantUtil.convertValue() converts a Parquet Binary-backed primitive bound value into the target type for STRING, UUID and Binary->ByteBuffer cases. For any other primitive physical type it throws IllegalStateException, because the bound value's type cannot be converted.","triggerScenarios":"Calling convertValue on a variant bound/primitive value whose PhysicalType is not STRING, UUID or a Binary-backed type — e.g. INT32/INT64/FLOAT/DOUBLE or DATE/TIME types reaching the Binary conversion branch.","commonSituations":"Shredding schemas that bind literal values of numeric primitives; bugs in variant predicate/literal conversion paths; version drift between the shredding spec support and this converter.","solutions":["Only pass STRING, UUID, or binary-backed primitives to convertValue; handle numeric/date primitives with dedicated branches","Add a conversion branch for the offending PhysicalType if it should be supported","Validate the variant metadata's primitive type before calling convertValue"],"exampleFix":"// before: passing an INT32 bound value into convertValue\nObject v = ParquetVariantUtil.convertValue(PhysicalType.INT32, binary);\n// after: branch on type first\nswitch (type) { case INT32: return binary.getInteger(); case STRING: ... }","handlingStrategy":"type-guard","validationCode":"Preconditions.checkArgument(\n    primitive == PhysicalType.STRING || primitive == PhysicalType.UUID,\n    \"convertValue only supports binary-backed primitives, got %s\", primitive);","typeGuard":"boolean isBinaryBackedPrimitive(PhysicalType p) {\n  return p == PhysicalType.STRING || p == PhysicalType.UUID;\n}","tryCatchPattern":"try {\n  value = ParquetVariantUtil.convertValue(primitive, binary);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Invalid bound type\")) {\n    // handle numeric/date primitives on a dedicated path\n  } else throw e;\n}","preventionTips":["Match literal conversion branches to all PhysicalType values you can encounter","Only use convertValue on string/uuid/binary bounds","Add exhaustive switch tests for PhysicalType conversions"],"tags":["variant","type-conversion","shredding"],"backgroundTag":"type-mismatch","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}