{"record":{"id":"22ce06a6a17153c5","repo":"apache/kafka","slug":"not-implemented-yet","errorCode":null,"errorMessage":"Not implemented yet.","messagePattern":"Not implemented yet\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/MockConsumer.java","lineNumber":631,"sourceCode":"    @Override\n    public synchronized void pause(Collection<TopicPartition> partitions) {\n        for (TopicPartition partition : partitions) {\n            subscriptions.pause(partition);\n            paused.add(partition);\n        }\n    }\n\n    @Override\n    public synchronized void resume(Collection<TopicPartition> partitions) {\n        for (TopicPartition partition : partitions) {\n            subscriptions.resume(partition);\n            paused.remove(partition);\n        }\n    }\n\n    @Override\n    public synchronized Map<TopicPartition, OffsetAndTimestamp> offsetsForTimes(Map<TopicPartition, Long> timestampsToSearch) {\n        throw new UnsupportedOperationException(\"Not implemented yet.\");\n    }\n\n    @Override\n    public synchronized Map<TopicPartition, Long> beginningOffsets(Collection<TopicPartition> partitions) {\n        if (offsetsException != null) {\n            RuntimeException exception = this.offsetsException;\n            this.offsetsException = null;\n            throw exception;\n        }\n        Map<TopicPartition, Long> result = new HashMap<>();\n        for (TopicPartition tp : partitions) {\n            Long beginningOffset = beginningOffsets.get(tp);\n            if (beginningOffset == null)\n                throw new IllegalStateException(\"The partition \" + tp + \" does not have a beginning offset.\");\n            result.put(tp, beginningOffset);\n        }\n        return result;\n    }","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/consumer/MockConsumer.java#L613-L649","documentation":"Thrown by MockConsumer.offsetsForTimes unconditionally; this method is not implemented in MockConsumer. Tests that need offset-by-timestamp semantics must either use a real KafkaConsumer in an integration test or supply a custom stub subclass. Calling it on the stock mock always fails.","triggerScenarios":"Calling mock.offsetsForTimes(...) in a unit test; exercising consumer code paths that internally invoke offsetsForTimes without a stub.","commonSituations":"Test code that mirrors production consumer usage verbatim; windowed/time-based consumer logic under test; refactoring that pulls more behavior into a unit test that previously was integration-only.","solutions":["Move the test to an integration test using a real KafkaConsumer and a broker (or EmbeddedKafka).","Subclass MockConsumer and override offsetsForTimes to return a precomputed map.","Abstract the offsetsForTimes call behind an interface and stub that interface in the unit test."],"exampleFix":"// before\nMap<TopicPartition,OffsetAndTimestamp> r = mock.offsetsForTimes(Map.of(tp, 0L)); // throws\n\n// after (subclass)\nMockConsumer<String,String> mock = new MockConsumer<>(OffsetResetStrategy.EARLIEST) {\n    @Override\n    public synchronized Map<TopicPartition, OffsetAndTimestamp> offsetsForTimes(Map<TopicPartition, Long> tts) {\n        return Map.of(tp, new OffsetAndTimestamp(0L, 0L));\n    }\n};","handlingStrategy":"fallback","validationCode":"// No pre-call validation can make offsetsForTimes succeed; detect the path and avoid it.\nif (consumer instanceof MockConsumer) {\n    throw new UnsupportedOperationException(\"offsetsForTimes is not supported on MockConsumer; use a subclass or integration test\");\n}","typeGuard":"static boolean supportsOffsetsForTimes(Consumer<?,?> c) {\n    return !(c instanceof MockConsumer);\n}","tryCatchPattern":"try {\n    return consumer.offsetsForTimes(timestampsToSearch);\n} catch (UnsupportedOperationException e) {\n    if (\"Not implemented yet.\".equals(e.getMessage()) && consumer instanceof MockConsumer) {\n        return Collections.emptyMap(); // or move the test to integration\n    }\n    throw e;\n}","preventionTips":["Do not call offsetsForTimes on the stock MockConsumer; subclass and override it.","Abstract time-based offset lookups behind an interface so mocks can stub them.","Use an integration test with a real broker for offset-by-time behavior."],"tags":["consumer","mock-consumer","test","unsupported-operation","offsets"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}