Skip to content

KAFKA-20404: Replace bulk StreamsPartitionAssignor atomicity exclude with field-level suppressions#22341

Open
Phixsura wants to merge 1 commit into
apache:trunkfrom
Phixsura:07-KAFKA-20404-spotbugs-atomicity-streams-partition-assignor
Open

KAFKA-20404: Replace bulk StreamsPartitionAssignor atomicity exclude with field-level suppressions#22341
Phixsura wants to merge 1 commit into
apache:trunkfrom
Phixsura:07-KAFKA-20404-spotbugs-atomicity-streams-partition-assignor

Conversation

@Phixsura
Copy link
Copy Markdown

Background

KAFKA-20404 tracks replacing the bulk SpotBugs atomicity excludes (introduced when SpotBugs was upgraded from 4.8.6 to 4.9.4) with per-field investigations. This PR handles StreamsPartitionAssignor, the fourth class in the series after StreamThread (#22320), DefaultStateUpdater (#22333), and TaskManager (#22340).

Investigation

After removing StreamsPartitionAssignor from the single bulk AT_STALE_THREAD_WRITE_OF_PRIMITIVE block it appeared in (trunk line 600), SpotBugs reports two fields with warnings:

  • uniqueField at StreamsPartitionAssignor.java:232, flagged at line 266 (configure(Map)) and line 288 (subscriptionUserData(Set)).
  • usedSubscriptionMetadataVersion at StreamsPartitionAssignor.java:223, flagged at line 1432 and line 1447 (both inside maybeUpdateSubscriptionVersion(int, int)).

Walking the call sites:

  • configure, subscriptionUserData, and onAssignment are all ConsumerPartitionAssignor / Configurable interface methods. The Kafka consumer invokes them from inside poll() (e.g. ConsumerCoordinator.java:311 calls assignor.subscriptionUserData(...), line 370 calls assignor.onAssignment(...)).
  • maybeUpdateSubscriptionVersion is protected and only called from maybeScheduleFollowupRebalance (line 1544), which is itself reached from onAssignment.
  • The package-private uniqueField() getter is only invoked by StreamsPartitionAssignorTest.

KafkaConsumer.poll() is driven by the StreamThread, so both fields are thread-confined and the SpotBugs warnings are false positives.

Changes

  • Remove StreamsPartitionAssignor from the bulk <Or> block.
  • Add a single targeted <Match> block scoped to the class with an <Or> over both fields, with a rationale comment.

Verification

  • :streams:spotbugsMain --rerun-tasks clean.
  • :streams:spotbugsTest / :streams:checkstyleMain / :streams:checkstyleTest clean.
  • :streams:test --tests "*StreamsPartitionAssignor*" all green.

…with field-level suppressions

Removes StreamsPartitionAssignor from the bulk Or block for
AT_STALE_THREAD_WRITE_OF_PRIMITIVE and adds a targeted suppression for the two
fields SpotBugs flags: uniqueField and usedSubscriptionMetadataVersion.

Both fields are accessed only from ConsumerPartitionAssignor callbacks
(configure, subscriptionUserData, onAssignment) that KafkaConsumer invokes from
poll(); poll() in turn is driven by the StreamThread, so the read-modify-write
happens on a single thread and the SpotBugs warnings are false positives.

Fourth PR in the KAFKA-20404 series after StreamThread (apache#22320),
DefaultStateUpdater (apache#22333), and TaskManager (apache#22340).
@github-actions github-actions Bot added build Gradle build or GitHub Actions small Small PRs triage PRs from the community labels May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Gradle build or GitHub Actions ci-approved small Small PRs triage PRs from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants