Repository: apache/kafka
File: clients/src/main/java/org/apache/kafka/clients/admin/internals/AlterShareGroupOffsetsHandler.java (Java)

Code before:
    public ApiResult<CoordinatorKey, Map<TopicPartition, ApiException>> handleResponse(Node broker, Set<CoordinatorKey> keys, AbstractResponse abstractResponse) {
        validateKeys(keys);

        AlterShareGroupOffsetsResponse response = (AlterShareGroupOffsetsResponse) abstractResponse;
        final Set<CoordinatorKey> groupsToUnmap = new HashSet<>();
        final Set<CoordinatorKey> groupsToRetry = new HashSet<>();
        final Map<TopicPartition, ApiException> partitionResults = new HashMap<>();

        if (response.data().errorCode() != Errors.NONE.code()) {
            final Errors topLevelError = Errors.forCode(response.data().errorCode());
            final String topLevelErrorMessage = response.data().errorMessage();

            offsets.forEach((topicPartition, offset) ->
                handleError(
                    groupId,
                    topicPartition,
                    topLevelError,
                    topLevelErrorMessage,
                    partitionResults,
                    groupsToUnmap,
                    groupsToRetry
                ));
        } else {
            response.data().responses().forEach(topic -> topic.partitions().forEach(partition -> {
                final Errors partitionError = Errors.forCode(partition.errorCode());
                if (partitionError.code() != Errors.NONE.code()) {
                    String errorMessageToLog = partition.errorMessage() == null ? "" : partition.errorMessage();
                    log.debug("AlterShareGroupOffsets request for group id {} and topic-partition {}-{} failed and returned error {}. {}",
                        groupId.idValue, topic.topicName(), partition.partitionIndex(), partitionError.name(), errorMessageToLog);
                }
                partitionResults.put(new TopicPartition(topic.topicName(), partition.partitionIndex()), partitionError.exception(partition.errorMessage()));
            }));
        }

        if (groupsToUnmap.isEmpty() && groupsToRetry.isEmpty()) {
            return ApiResult.completed(groupId, partitionResults);
        } else {
            return ApiResult.unmapped(new ArrayList<>(groupsToUnmap));
        }
    }

    private void handleError(
        CoordinatorKey groupId,
        TopicPartition topicPartition,
        Errors error,
        String errorMessage,
        Map<TopicPartition, ApiException> partitionResults,
        Set<CoordinatorKey> groupsToUnmap,
        Set<CoordinatorKey> groupsToRetry
    ) {
        String errorMessageToLog = errorMessage == null ? "" : errorMessage;

Review comment (suggestion):
```suggestion
                if (partitionError != Errors.NONE) {
```

Code after:
    public ApiResult<CoordinatorKey, Map<TopicPartition, ApiException>> handleResponse(Node broker, Set<CoordinatorKey> keys, AbstractResponse abstractResponse) {
        validateKeys(keys);

        AlterShareGroupOffsetsResponse response = (AlterShareGroupOffsetsResponse) abstractResponse;
        final Set<CoordinatorKey> groupsToUnmap = new HashSet<>();
        final Set<CoordinatorKey> groupsToRetry = new HashSet<>();
        final Map<TopicPartition, ApiException> partitionResults = new HashMap<>();

        if (response.data().errorCode() != Errors.NONE.code()) {
            final Errors topLevelError = Errors.forCode(response.data().errorCode());
            final String topLevelErrorMessage = response.data().errorMessage();

            offsets.forEach((topicPartition, offset) ->
                handleError(
                    groupId,
                    topicPartition,
                    topLevelError,
                    topLevelErrorMessage,
                    partitionResults,
                    groupsToUnmap,
                    groupsToRetry
                ));
        } else {
            response.data().responses().forEach(topic -> topic.partitions().forEach(partition -> {
                final Errors partitionError = Errors.forCode(partition.errorCode());
                if (partitionError != Errors.NONE) {
                    String errorMessageToLog = partition.errorMessage() == null ? "" : partition.errorMessage();
                    log.debug("AlterShareGroupOffsets request for group id {} and topic-partition {}-{} failed and returned error {}. {}",
                        groupId.idValue, topic.topicName(), partition.partitionIndex(), partitionError.name(), errorMessageToLog);
                }
                partitionResults.put(new TopicPartition(topic.topicName(), partition.partitionIndex()), partitionError.exception(partition.errorMessage()));
            }));
        }

        if (groupsToUnmap.isEmpty() && groupsToRetry.isEmpty()) {
            return ApiResult.completed(groupId, partitionResults);
        } else {
            return ApiResult.unmapped(new ArrayList<>(groupsToUnmap));
        }
    }

    private void handleError(
        CoordinatorKey groupId,
        TopicPartition topicPartition,
        Errors error,
        String errorMessage,
        Map<TopicPartition, ApiException> partitionResults,
        Set<CoordinatorKey> groupsToUnmap,
        Set<CoordinatorKey> groupsToRetry
    ) {
        String errorMessageToLog = errorMessage == null ? "" : errorMessage;