Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-3075

java.util.HashMap cannot be cast to scala.collection.immutable.Map When using ZookeeperConsumerConnector.commitOffsets

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.0.0
    • Fix Version/s: 0.9.0.1
    • Component/s: consumer
    • Labels:
      None

      Description

      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) }

        Attachments

          Activity

            People

            • Assignee:
              ijuma Ismael Juma
              Reporter:
              pengwei Pengwei
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: