{"id":"26b7ed1f2c6a08b3","repo":"apache/kafka","slug":"invalid-timestamp-type","errorCode":null,"errorMessage":"Invalid timestamp type {}","messagePattern":"Invalid timestamp type (.+?)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/record/TimestampType.java","lineNumber":43,"sourceCode":" * The timestamp type of the records.\n */\n@InterfaceAudience.Public\npublic enum TimestampType {\n    NO_TIMESTAMP_TYPE(-1, \"NoTimestampType\"), CREATE_TIME(0, \"CreateTime\"), LOG_APPEND_TIME(1, \"LogAppendTime\");\n\n    public final int id;\n    public final String name;\n\n    TimestampType(int id, String name) {\n        this.id = id;\n        this.name = name;\n    }\n\n    public static TimestampType forName(String name) {\n        for (TimestampType t : values())\n            if (t.name.equals(name))\n                return t;\n        throw new NoSuchElementException(\"Invalid timestamp type \" + name);\n    }\n\n    @Override\n    public String toString() {\n        return name;\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":51,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/record/TimestampType.java#L25-L51","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nTimestampType t = TimestampType.forName(\"create_time\");\n\n// after\nTimestampType t = TimestampType.forName(\"CreateTime\");","handlingStrategy":"validation","validationCode":"// Validate timestamp-type name before calling TimestampType.forName(name)\nimport org.apache.kafka.common.record.TimestampType;\nimport java.util.Arrays;\n\nString name = /* from config/input */;\nboolean known = Arrays.stream(TimestampType.values())\n        .anyMatch(t -> t.name.equals(name));\nif (!known) {\n    // reject config or default to a valid value (e.g. \"CreateTime\")\n    throw new IllegalArgumentException(\n        \"Unknown timestamp type '\" + name + \"'. Allowed: \" +\n        Arrays.toString(Arrays.stream(TimestampType.values()).map(t -> t.name).toArray()));\n}\nTimestampType t = TimestampType.forName(name);","typeGuard":"// Narrow a free-form config string to a known TimestampType before use\nimport org.apache.kafka.common.record.TimestampType;\nimport java.util.Optional;\n\nOptional<TimestampType> safeForName(String name) {\n    if (name == null) return Optional.empty();\n    for (TimestampType t : TimestampType.values()) {\n        if (t.name.equals(name)) return Optional.of(t);\n    }\n    return Optional.empty();\n}","tryCatchPattern":"// forName throws NoSuchElementException on unknown names\ntry {\n    TimestampType t = TimestampType.forName(name);\n} catch (NoSuchElementException e) {\n    // config is malformed: fall back to a sane default or surface a config error\n    log.warn(\"Invalid timestamp type '{}', defaulting to CREATE_TIME\", name);\n    t = TimestampType.CREATE_TIME;\n}","preventionTips":["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."],"tags":["config","timestamp","enum-lookup","producer","consumer"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}