[ https://issues.apache.org/jira/browse/KAFKA-3075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15123723#comment-15123723 ]
Ismael Juma commented on KAFKA-3075: ------------------------------------ Not related to the bug report, but you may consider using the new Java consumer if possible: http://www.confluent.io/blog/tutorial-getting-started-with-the-new-apache-kafka-0.9-consumer-client > java.util.HashMap cannot be cast to scala.collection.immutable.Map When using > ZookeeperConsumerConnector.commitOffsets > ----------------------------------------------------------------------------------------------------------------------- > > Key: KAFKA-3075 > URL: https://issues.apache.org/jira/browse/KAFKA-3075 > Project: Kafka > Issue Type: Bug > Components: consumer > Affects Versions: 0.9.0.0 > Reporter: Pengwei > Assignee: Ismael Juma > Fix For: 0.9.0.1 > > > When using java api's commit offset : > public void commitOffsets(Map<TopicAndPartition, OffsetAndMetadata> > offsetsToCommit, boolean retryOnFailure); > and pass a Java Hash Map to this interface, will found: > java.lang.ClassCastException: java.util.HashMap cannot be cast to > scala.collection.immutable.Map > at > kafka.javaapi.consumer.ZookeeperConsumerConnector.commitOffsets(ZookeeperConsumerConnector.scala:118) > at > kafka.examples.CommitExceptionTest.testCommitNotExistTopicShoudThrowException(CommitExceptionTest.java:55) > at kafka.examples.CommitExceptionTest.main(CommitExceptionTest.java:20) > Test case testCommitNotExistTopicShoudThrowException OK. > Exception in thread "main" java.lang.ClassCastException: java.util.HashMap > cannot be cast to scala.collection.immutable.Map > at > kafka.javaapi.consumer.ZookeeperConsumerConnector.commitOffsets(ZookeeperConsumerConnector.scala:118) > at > kafka.examples.CommitExceptionTest.testCommitOffsetOutOfRange(CommitExceptionTest.java:95) > at kafka.examples.CommitExceptionTest.main(CommitExceptionTest.java:22) > The Origin Code: > def commitOffsets(offsetsToCommit: java.util.Map[TopicAndPartition, > OffsetAndMetadata], retryOnFailure: Boolean) { > > underlying.commitOffsets(offsetsToCommit.asInstanceOf[immutable.Map[TopicAndPartition, > OffsetAndMetadata]], retryOnFailure) > } > I try to fix like this, it is OK: > def commitOffsets(offsetsToCommit: java.util.Map[TopicAndPartition, > OffsetAndMetadata], retryOnFailure: Boolean) { > import scala.collection.JavaConverters._ > underlying.commitOffsets(offsetsToCommit.asScala.toMap, retryOnFailure) > } -- This message was sent by Atlassian JIRA (v6.3.4#6332)