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

The protocol generator generated useless condition when a field is made nullable and flexible version is used

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.7.0
    • None
    • None

    Description

      The protocol generator generates useless conditions when a field of type string is made nullable after the request has been converted to using optional fields.

      As an example, we have make the field `ProtocolName` nullable in the `JoinGroupResponse`. The `JoinGroupResponse` supports optional fields since version 6 and the field is nullable since version 7. Under these conditions, the generator generates the following code:

      if (protocolName == null) {
       if (_version >= 7) {
         if (_version >= 6) {
           _writable.writeUnsignedVarint(0);
         } else {
           _writable.writeShort((short) -1);
        }
       } else {
         throw new NullPointerException();
       }
      }
      

      spotbugs raises an `UC_USELESS_CONDITION` because `_version >= 6` is always true.  

      We could optimise the generator to handle this.
       

      Attachments

        Issue Links

          Activity

            People

              dajac David Jacot
              dajac David Jacot
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: