diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2018-11-28 10:57:43 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-11-30 11:20:47 +0100 |
commit | 417280ac3f309cc5ac019849a616c34ac042ccd4 (patch) | |
tree | dc98d34a4d837d432e16c91bd76aa258afcbe6c0 /server/sonar-server/src | |
parent | 57b9f387ae8352e858cab7a4954419d52ef29b69 (diff) | |
download | sonarqube-417280ac3f309cc5ac019849a616c34ac042ccd4.tar.gz sonarqube-417280ac3f309cc5ac019849a616c34ac042ccd4.zip |
SONAR-11419 fix NPE introduced by the fix :/
Diffstat (limited to 'server/sonar-server/src')
2 files changed, 24 insertions, 3 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java index 8a87eed27b1..b3ba3409e7f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java @@ -334,10 +334,10 @@ public class SuggestionsAction implements ComponentsWsAction { private static Suggestion toSuggestion(ComponentHit hit, Set<String> recentlyBrowsedKeys, Set<String> favoriteUuids, Map<String, ComponentDto> componentsByUuids, Map<String, OrganizationDto> organizationByUuids, Map<String, ComponentDto> projectsByUuids) { ComponentDto result = componentsByUuids.get(hit.getUuid()); - boolean returnProject = QUALIFIERS_FOR_WHICH_TO_RETURN_PROJECT.contains(result.qualifier()); if (result == null // SONAR-11419 this has happened in production while code does not really allow it. An inconsistency in DB may be the cause. - || (returnProject && projectsByUuids.get(result.projectUuid()) == null)) { + || (QUALIFIERS_FOR_WHICH_TO_RETURN_PROJECT.contains(result.qualifier()) && projectsByUuids.get(result.projectUuid()) == null) + ) { return null; } String organizationKey = organizationByUuids.get(result.getOrganizationUuid()).getKey(); @@ -349,7 +349,7 @@ public class SuggestionsAction implements ComponentsWsAction { .setMatch(hit.getHighlightedText().orElse(HtmlEscapers.htmlEscaper().escape(result.name()))) .setIsRecentlyBrowsed(recentlyBrowsedKeys.contains(result.getDbKey())) .setIsFavorite(favoriteUuids.contains(result.uuid())); - if (returnProject) { + if (QUALIFIERS_FOR_WHICH_TO_RETURN_PROJECT.contains(result.qualifier())) { builder.setProject(projectsByUuids.get(result.projectUuid()).getDbKey()); } return builder.build(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java index 325784e3c55..cd151f01eb0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/SuggestionsActionTest.java @@ -393,6 +393,27 @@ public class SuggestionsActionTest { } @Test + public void should_not_return_suggestion_on_non_existing_project() { + ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); + + componentIndexer.indexOnStartup(null); + authorizationIndexerTester.allowOnlyAnyone(project); + + db.getDbClient().componentDao().delete(db.getSession(), project.getId()); + db.commit(); + + SuggestionsWsResponse response = ws.newRequest() + .setMethod("POST") + .setParam(PARAM_QUERY, project.getDbKey()) + .executeProtobuf(SuggestionsWsResponse.class); + + // assert match in qualifier "TRK" + assertThat(response.getResultsList()) + .filteredOn(q -> q.getItemsCount() > 0) + .isEmpty(); + } + + @Test public void must_not_search_if_no_valid_tokens_are_provided() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("SonarQube")); |