{"record":{"id":"0a0e2949b64d7cc4","repo":"apache/iceberg","slug":"apply-value-is-deprecated-use-bind-type-apply-v-0a0e29","errorCode":null,"errorMessage":"apply(value) is deprecated, use bind(Type).apply(value)","messagePattern":"apply\\(value\\) is deprecated, use bind\\(Type\\)\\.apply\\(value\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/transforms/Truncate.java","lineNumber":83,"sourceCode":"      default:\n        throw new UnsupportedOperationException(\"Cannot truncate type: \" + type);\n    }\n  }\n\n  @SuppressWarnings(\"checkstyle:VisibilityModifier\")\n  protected final int width;\n\n  Truncate(int width) {\n    this.width = width;\n  }\n\n  public Integer width() {\n    return width;\n  }\n\n  @Override\n  public T apply(T value) {\n    throw new UnsupportedOperationException(\n        \"apply(value) is deprecated, use bind(Type).apply(value)\");\n  }\n\n  @Override\n  public SerializableFunction<T, T> bind(Type type) {\n    Preconditions.checkArgument(canTransform(type), \"Cannot bind to unsupported type: %s\", type);\n    return (SerializableFunction<T, T>) get(type, width);\n  }\n\n  @Override\n  public boolean canTransform(Type type) {\n    switch (type.typeId()) {\n      case INTEGER:\n      case LONG:\n      case STRING:\n      case BINARY:\n      case DECIMAL:\n        return true;","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/transforms/Truncate.java#L65-L101","documentation":"Truncate explicitly overrides the deprecated Transform.apply(value) to throw UnsupportedOperationException with the migration message. Like all transforms, Truncate must be bound to a concrete type via bind(Type) so the correct truncation function (int, long, decimal, string, or ByteBuffer) is selected; the unbound apply() cannot know how to truncate.","triggerScenarios":"Directly calling Truncate.of(width).apply(value) instead of Truncate.of(width).bind(type).apply(value) — e.g. legacy partitioning code or the testDeprecatedTruncateInteger path.","commonSituations":"Code written before the bind() API that was upgraded; examples/tutorial code using the deprecated unbound call on truncate transforms.","solutions":["Replace apply(value) with bind(type).apply(value), where type is the column's Iceberg Type","Use canTransform(type) to verify the type is truncatable before binding","Audit and update deprecated Transform.apply call sites when upgrading Iceberg"],"exampleFix":"// before\nInteger truncated = Truncate.of(10).apply(value);\n// after\nInteger truncated = Truncate.of(10).bind(IntegerType.get()).apply(value);","handlingStrategy":"type-guard","validationCode":"// migrate: use the bound function\nSerializableFunction<Integer, Integer> fn = Truncate.of(10).bind(IntegerType.get());\nInteger truncated = fn.apply(value);","typeGuard":"static <S, T> SerializableFunction<S, T> boundFn(Transform<S, T> t, Type type) { return t.bind(type); }","tryCatchPattern":"try { return truncate.bind(type).apply(value); } catch (UnsupportedOperationException e) { throw new IllegalStateException(\"Deprecated unbound Truncate.apply used; bind first\", e); }","preventionTips":["Never call the deprecated Truncate.apply(value); always bind to the column type first","Update legacy partitioning code when upgrading Iceberg versions","Cover truncate usage in tests via the bind() API"],"tags":["java","iceberg","transform","truncate","deprecated"],"backgroundTag":"deprecated-api-usage","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}