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

Kafka Streams ConsumerRecordFactory yields difficult compiler error about generics

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.4.0
    • streams
    • None

    Description

      When using the ConsumerRecordFactory, it's convenient to specify a default topic to create records with:

      ConsumerRecordFactory<String, User> inputFactory = new ConsumerRecordFactory<>(inputTopic, keySerializer, valueSerializer);
      

      However, when the factory is used to create a record with a String key:

      inputFactory.create("any string", user)
      

      Compilation fails with the following warning:

      Ambiguous method call. Both:
      
      create(String, User) in ConsumerRecordFactory and
      create(String, User) in ConsumerRecordFactory match
      

      At first glance, this is a really confusing error to see during compilation. What's happening is that there are two clashing signatures for `create`: create(K, V) and create(String, V). The latter signature represents a topic name.

      It seems like fixing this would require breaking the existing interface. This is a really opaque problem to hit though, and it would be great if we could avoid having users encounter this.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mdrogalis Michael Drogalis
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: