ShivamSharma43 opened a new issue, #9389:
URL: https://github.com/apache/devlake/issues/9389

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/devlake/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### What happened
   
   The SonarQube `extractIssues` subtask gives issue code blocks IDs that 
depend on every code block extracted before them, not just on the code block 
itself.
   
   `ExtractIssues` (`plugins/sonarqube/tasks/issues_extractor.go`) creates one 
`sha256` hash for the whole subtask and passes it to `generateId` for every 
code block (the issue's own text range and each flow location). `generateId` 
(`plugins/sonarqube/tasks/shared.go`) writes into it and takes the sum, but 
never resets it:
   
   ```go
   func generateId(hashCodeBlock hash.Hash, entity 
*models.SonarqubeIssueCodeBlock) {
        hashCodeBlock.Write([]byte(fmt.Sprintf("%s-%s-%d-%d-%d-%d-%s", 
entity.IssueKey, entity.Component, ...)))
        entity.Id = hex.EncodeToString(hashCodeBlock.Sum(nil))
   }
   ```
   
   `Sum` doesn't clear the state, so each ID is the hash of all code blocks so 
far, concatenated. Only the first code block of a run gets the hash of its own 
fields.
   
   As a result, `_tool_sonarqube_issue_code_blocks.id` and 
`cq_issue_code_blocks.id` for the same code block change whenever the raw rows 
before it change: a new or removed SonarQube issue earlier in the raw table 
gives every later code block a new ID. The IDs aren't stable across collections 
and can't be recomputed from the code block's own fields.
   
   I checked this against the e2e fixture: replaying the raw issues in 
`plugins/sonarqube/e2e/raw_tables/_raw_sonarqube_api_issues.csv` with a running 
hash reproduces all 165 IDs in `_tool_sonarqube_issue_code_blocks.csv`; 163 of 
them differ from the hash of the code block alone.
   
   ### What do you expect to happen
   
   A code block's ID is the hash of its own fields (issue key, component, 
lines, offsets, message), as `generateId` intends, so the same code block 
always gets the same ID.
   
   ### How to reproduce
   
   Call `generateId` twice with the same hash, first for one code block and 
then for another: the second ID differs from what `generateId` returns for that 
code block with a fresh hash (`TestGenerateId`'s expected ID).
   
   ### Anything else
   
   Proposed fix (I have a PR ready): reset the hash at the start of 
`generateId`, and update the code block IDs in the e2e snapshots.
   
   ### Version
   
   main
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to