Repository navigation
fix(sonarqube): reset the hash before generating each issue code block id - #9391
Open
ShivamSharma43 wants to merge 1 commit into
Open
ShivamSharma43 wants to merge 1 commit into
ShivamSharma43 wants to merge 1 commit into
Conversation
…k id ExtractIssues shares one sha256 hash across all code blocks of the subtask, and generateId wrote into it without resetting it. Each code block id was the hash of every code block extracted before it, so ids changed whenever earlier raw rows changed, and only the first code block of a run got the hash of its own fields. Reset the hash at the start of generateId, add a test that reuses the hash, and update the code block ids in the e2e snapshots. Fixes apache#9389 Generated-by: Claude Code (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Shivam Sharma <192242476+ShivamSharma43@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SonarQube issue code block IDs depended on every code block extracted before them in the same subtask run.
ExtractIssuescreates onesha256hash and passes it togenerateIdfor every code block (the issue's text range and each flow location).generateIdwrote the code block's fields into it and tookSum, butSumdoesn't clear the state and the hash was never reset. So each ID was the hash of all code blocks so far, concatenated, and only the first code block of a run got the hash of its own fields. The same code block got a different ID whenever the raw rows before it changed, for example after a new SonarQube issue was collected. Details in #9389.Changes:
tasks/shared.go:generateIdcallsReset()on the hash before writing, so the ID is the sha256 of the code block's own fields. The format string and the hash function are unchanged.tasks/shared_test.go:TestGenerateIdWithReusedHashreuses one hash the way the extractor does. It checks that the second code block gets the same ID as inTestGenerateId, and that generating the first code block again gives its original ID. It fails without the fix.e2e/snapshot_tables/_tool_sonarqube_issue_code_blocks.csvandissue_code_blocks.csv: new code block IDs. To get them, I first replayed the raw fixture with a running hash, which reproduced all 165 old IDs exactly. Then I replaced each ID with the sha256 of that code block's own fields. 163 IDs change; the first code block of each connection keeps its ID. The new IDs are all unique, and no other columns change. Rows are kept sorted by ID.After upgrading, the next extraction writes code blocks with the new IDs. The extractor deletes the previous rows for the same raw params first, so old IDs don't stay behind.
Does this close any open issues?
Fixes #9389
Screenshots
N/A
Other Information
go test ./plugins/sonarqube/tasks/: pass.go vet ./plugins/sonarqube/tasks/ ./plugins/sonarqube/e2e/,gofmtandgolangci-lint run ./plugins/sonarqube/...: clean. I didn't run the sonarqube e2e tests locally (they needE2E_DB_URL), so the snapshot IDs were computed as described above rather than produced by the test run.pr-type/bug-fix.Generated-by:trailer per the ASF generative tooling guidance.🤖 Generated with Claude Code