Browse Source

SONAR-11419 do not fail with NPE in api/components/suggestions

tags/7.5
Sébastien Lesaint 5 years ago
parent
commit
57b9f387ae

+ 6
- 5
server/sonar-server/src/main/java/org/sonar/server/component/ws/SuggestionsAction.java View File

@@ -264,9 +264,7 @@ public class SuggestionsAction implements ComponentsWsAction {
}

String qualifier = SuggestionCategory.getByName(more).getQualifier();
return availableQualifiers.contains(qualifier) ?
singletonList(qualifier)
: emptyList();
return availableQualifiers.contains(qualifier) ? singletonList(qualifier) : emptyList();
}

private SuggestionsWsResponse.Builder buildResponse(Set<String> recentlyBrowsedKeys, Set<String> favoriteUuids, ComponentIndexResults componentsPerQualifiers,
@@ -336,7 +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());
if (result == null) {
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)) {
return null;
}
String organizationKey = organizationByUuids.get(result.getOrganizationUuid()).getKey();
@@ -348,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 (QUALIFIERS_FOR_WHICH_TO_RETURN_PROJECT.contains(result.qualifier())) {
if (returnProject) {
builder.setProject(projectsByUuids.get(result.projectUuid()).getDbKey());
}
return builder.build();

Loading…
Cancel
Save