dajac opened a new pull request #8793:
URL: https://github.com/apache/kafka/pull/8793


   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.
   
   This PR fixes the bug by propagating the outer versions to the underlying 
`VersionConditional` so it can generate the code accordingly.
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


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


Reply via email to