mjsax commented on a change in pull request #9309: URL: https://github.com/apache/kafka/pull/9309#discussion_r497991052
########## File path: clients/src/test/java/org/apache/kafka/clients/producer/MockProducerTest.java ########## @@ -765,6 +766,16 @@ public void shouldThrowOnFlushProducerIfProducerIsClosed() { fail("Should have thrown as producer is already closed"); } catch (IllegalStateException e) { } } + + @Test + @SuppressWarnings("unchecked") + public void shouldThrowClassCastException() { + try (MockProducer<Integer, String> producer = new MockProducer<>(true, new IntegerSerializer(), new StringSerializer());) { + ProducerRecord record = new ProducerRecord(topic, "key1", "value1"); + producer.send(record); + fail("Should have thrown ClassCastException because record cannot be casted with serializers"); Review comment: Oh, I see. We actually want to pass in an incorrect key-type to get the `ClassCastException`. So you are right, for this case we cannot specify the generics. Keeping the code as-is an to suppress the warning is fine than. Totally missed this. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org