apache/kafka · error · NoSuchElementException
Invalid timestamp type {}
Error message
Invalid timestamp type {} What it means
Thrown by TimestampType.forName(String) when the supplied name does not equal any of the enum's name fields ("NoTimestampType", "CreateTime", "LogAppendTime"). It is a plain java.util.NoSuchElementException because the lookup is an exact-match scan over values() with no fallback. The library uses it to reject unknown timestamp-type strings coming from configuration or protocol parsing before they can be applied to a record batch.
Source
Thrown at clients/src/main/java/org/apache/kafka/common/record/TimestampType.java:43
* The timestamp type of the records.
*/
@InterfaceAudience.Public
public enum TimestampType {
NO_TIMESTAMP_TYPE(-1, "NoTimestampType"), CREATE_TIME(0, "CreateTime"), LOG_APPEND_TIME(1, "LogAppendTime");
public final int id;
public final String name;
TimestampType(int id, String name) {
this.id = id;
this.name = name;
}
public static TimestampType forName(String name) {
for (TimestampType t : values())
if (t.name.equals(name))
return t;
throw new NoSuchElementException("Invalid timestamp type " + name);
}
@Override
public String toString() {
return name;
}
}
View on GitHub (pinned to c31c9215e1)
Solutions
- Use one of the exact enum names: "CreateTime" or "LogAppendTime" (or "NoTimestampType" internally).
- Strip whitespace and verify casing in the config source before it reaches forName().
- If the value comes from user input, validate against TimestampType.values() and surface a clear error rather than letting NoSuchElementException escape.
- Upgrade the client jar to a version whose TimestampType enum contains the name you intend to use.
Example fix
// before
TimestampType t = TimestampType.forName("create_time");
// after
TimestampType t = TimestampType.forName("CreateTime"); Defensive patterns
Strategy: validation
Validate before calling
// Validate timestamp-type name before calling TimestampType.forName(name)
import org.apache.kafka.common.record.TimestampType;
import java.util.Arrays;
String name = /* from config/input */;
boolean known = Arrays.stream(TimestampType.values())
.anyMatch(t -> t.name.equals(name));
if (!known) {
// reject config or default to a valid value (e.g. "CreateTime")
throw new IllegalArgumentException(
"Unknown timestamp type '" + name + "'. Allowed: " +
Arrays.toString(Arrays.stream(TimestampType.values()).map(t -> t.name).toArray()));
}
TimestampType t = TimestampType.forName(name); Type guard
// Narrow a free-form config string to a known TimestampType before use
import org.apache.kafka.common.record.TimestampType;
import java.util.Optional;
Optional<TimestampType> safeForName(String name) {
if (name == null) return Optional.empty();
for (TimestampType t : TimestampType.values()) {
if (t.name.equals(name)) return Optional.of(t);
}
return Optional.empty();
} Try / catch
// forName throws NoSuchElementException on unknown names
try {
TimestampType t = TimestampType.forName(name);
} catch (NoSuchElementException e) {
// config is malformed: fall back to a sane default or surface a config error
log.warn("Invalid timestamp type '{}', defaulting to CREATE_TIME", name);
t = TimestampType.CREATE_TIME;
} Prevention
- Only accept timestamp-type names from a fixed allow-list matching the enum values: NoTimestampType, CreateTime, LogAppendTime.
- Validate user/config input at the configuration boundary (e.g. when parsing kafka client properties), not deep inside record processing.
- Treat the timestamp type as an enum, not an arbitrary string; expose TimestampType directly in your own API rather than passing strings around.
- If the value comes from a property file or remote config, log the offending value before defaulting so misconfiguration is visible.
When it happens
Trigger: Calling TimestampType.forName(name) with a misspelled or differently-cased string (e.g. "create_time", "logappendtime", "Log_Append_Time", "CreateTime " with trailing space). Also triggered when message.format.version / log.message.timestamp.type config is set to a value the running client jar does not recognize (older client seeing a newer name).
Common situations: Misconfiguring log.message.timestamp.type on the broker or message.timestamp.type on the producer/consumer with snake_case instead of the camelCase enum name. Copying a config value from documentation that uses a different casing. Mismatch between a client built against an older Kafka version and a config string introduced later.
Related errors
- Expected value to be a 64-bit integer (long), but it was a v
- Invalid negative offset
- Invalid negative timestamp
- Telemetry is not enabled. Set config `{}` to `true`.
- Tried to force a rebalance but consumer does not have a grou
AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03).
Data as JSON: /data/errors/26b7ed1f2c6a08b3.json.
Report an issue: GitHub.