{"record":{"id":"ec89562be09b9145","repo":"apache/iceberg","slug":"cannot-create-expression-literal-from-s-s","errorCode":null,"errorMessage":"Cannot create expression literal from %s: %s","messagePattern":"Cannot create expression literal from (.+?): (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/expressions/Literals.java","lineNumber":92,"sourceCode":"    } else if (value instanceof Float) {\n      return (Literal<T>) new Literals.FloatLiteral((Float) value);\n    } else if (value instanceof Double) {\n      return (Literal<T>) new Literals.DoubleLiteral((Double) value);\n    } else if (value instanceof CharSequence) {\n      return (Literal<T>) new Literals.StringLiteral((CharSequence) value);\n    } else if (value instanceof UUID) {\n      return (Literal<T>) new Literals.UUIDLiteral((UUID) value);\n    } else if (value instanceof byte[]) {\n      return (Literal<T>) new Literals.FixedLiteral(ByteBuffer.wrap((byte[]) value));\n    } else if (value instanceof ByteBuffer) {\n      return (Literal<T>) new Literals.BinaryLiteral((ByteBuffer) value);\n    } else if (value instanceof BigDecimal) {\n      return (Literal<T>) new Literals.DecimalLiteral((BigDecimal) value);\n    } else if (value instanceof Variant) {\n      return (Literal<T>) new Literals.VariantLiteral((Variant) value);\n    }\n\n    throw new IllegalArgumentException(\n        String.format(\n            \"Cannot create expression literal from %s: %s\", value.getClass().getName(), value));\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  static <T> AboveMax<T> aboveMax() {\n    return AboveMax.INSTANCE;\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  static <T> BelowMin<T> belowMin() {\n    return BelowMin.INSTANCE;\n  }\n\n  private abstract static class BaseLiteral<T> implements Literal<T> {\n    private final T value;\n    private transient volatile ByteBuffer byteBuffer = null;\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/expressions/Literals.java#L74-L110","documentation":"Literals.from(Object) converts a Java value into an Iceberg expression Literal, but only for the supported value types (Boolean, Integer, Long, Float, Double, String, byte[]/ByteBuffer, UUID, CharSequence-based types, BigDecimal, Variant, etc.). For any other object type it throws IllegalArgumentException naming the class and value. It means the value's type has no corresponding Iceberg literal representation.","triggerScenarios":"Calling Literals.from(value) — directly or via Expressions.predicate/expressions built from arbitrary Java objects — with an unsupported type such as a custom POJO, java.util.Date, Instant, OffsetDateTime, LocalDate, or a collection, instead of the expected Iceberg-representable types.","commonSituations":"Building filter predicates from engine-specific types (Spark TimestampType values as java.sql.Timestamp, java.time types) without converting to Iceberg's expected representations (LocalDate, LocalDateTime, OffsetDateTime handled elsewhere or via proper conversion); passing boxed collection types instead of scalars.","solutions":["Convert the value to a supported type before calling Literals.from (e.g. java.sql.Date -> LocalDate, Timestamp -> LocalDateTime, BigInteger -> BigDecimal)","Use the typed literal constructors directly (Literals.of, or Expressions.literal with a supported value)","If the type is legitimately needed, extend via string/decimal representation or convert with TypeUtil/DateTimeUtil helpers"],"exampleFix":"// before\nLiteral<?> lit = Literals.from(java.sql.Timestamp.valueOf(\"2024-01-01 10:00:00\")); // IllegalArgumentException\n// after\nLiteral<?> lit = Literals.from(\n    java.sql.Timestamp.valueOf(\"2024-01-01 10:00:00\").toLocalDateTime());","handlingStrategy":"validation","validationCode":"static boolean supportedLiteralType(Object v) {\n  return v instanceof Boolean || v instanceof Integer || v instanceof Long\n      || v instanceof Float || v instanceof Double || v instanceof String\n      || v instanceof byte[] || v instanceof ByteBuffer || v instanceof UUID\n      || v instanceof BigDecimal || v instanceof Variant;\n}\n// validate before: if (!supportedLiteralType(value)) throw ...","typeGuard":null,"tryCatchPattern":"try {\n  Literal<?> lit = Literals.from(value);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Cannot create expression literal from\")) {\n    value = convertToSupportedType(value); // e.g. Timestamp -> LocalDateTime\n    return Literals.from(value);\n  }\n  throw e;\n}","preventionTips":["Convert engine-specific date/time types to java.time types Iceberg supports before building literals","Never pass POJOs, collections, or java.util.Date/java.sql.* directly to Literals.from","Check the value's class against Literals' supported types when building filters from dynamic input"],"tags":["java","literals","type-mismatch","illegal-argument"],"backgroundTag":"invalid-argument-value","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"}