diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2022-09-01 11:04:31 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-09-02 20:02:49 +0000 |
commit | 4dc16a2b763ed795bc2a97bdda53f34ed6f021bf (patch) | |
tree | 0fa55ad50a065e0d22db998605681dd9b180041d /server | |
parent | 1efc533bdf465a1a8f94a3d2a407049fe85ce680 (diff) | |
download | sonarqube-4dc16a2b763ed795bc2a97bdda53f34ed6f021bf.tar.gz sonarqube-4dc16a2b763ed795bc2a97bdda53f34ed6f021bf.zip |
SONAR-17263 Rule Search WS fails if rule has a note and its author was deleted
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java | 2 | ||||
-rw-r--r-- | server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java index e1c09617814..ed0141577ec 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java @@ -397,7 +397,7 @@ public class RuleMapper { ruleResponse.setMdNote(noteData); } String userUuid = ruleDto.getNoteUserUuid(); - if (shouldReturnField(fieldsToReturn, FIELD_NOTE_LOGIN) && userUuid != null) { + if (shouldReturnField(fieldsToReturn, FIELD_NOTE_LOGIN) && userUuid != null && usersByUuid.containsKey(userUuid)) { ruleResponse.setNoteLogin(usersByUuid.get(userUuid).getLogin()); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java index da911be2d8e..fc332643679 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java @@ -194,6 +194,22 @@ public class SearchActionTest { } @Test + public void dont_fail_if_note_author_no_longer_exists() { + // note: this can only happen due to DB corruption (user deleted) + RuleDto rule1 = db.rules().insert(r -> r.setNoteUserUuid("non-existent")); + indexRules(); + + SearchResponse result = ws.newRequest() + .setParam("f", "noteLogin") + .executeProtobuf(SearchResponse.class); + + assertThat(result.getRulesList()) + .extracting(Rule::getKey, Rule::getNoteLogin) + .containsExactlyInAnyOrder( + tuple(rule1.getKey().toString(), "")); + } + + @Test public void filter_by_rule_key() { RuleDto rule1 = db.rules().insert(r1 -> r1.setLanguage("java").setNoteUserUuid(null)); db.rules().insert(r1 -> r1.setLanguage("java").setNoteUserUuid(null)); |