diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-11-03 15:18:17 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-11-04 15:05:18 +0100 |
commit | e02bf2d08e32bdbcc95a7ef0645049cfb5728451 (patch) | |
tree | 0db2c718ed8250e6c25b4468b05b046806fb9a6d | |
parent | aa429b085e1edd36650b4200438bc877ea29be0f (diff) | |
download | sonarqube-e02bf2d08e32bdbcc95a7ef0645049cfb5728451.tar.gz sonarqube-e02bf2d08e32bdbcc95a7ef0645049cfb5728451.zip |
SONAR-5742 Add explicit error messages when matching components and projects
-rw-r--r-- | server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java index 2a22865aaf1..7c55aa257bf 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -19,9 +19,7 @@ */ package org.sonar.server.issue.ws; -import com.google.common.base.Predicate; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; import com.google.common.io.Resources; import org.sonar.api.i18n.I18n; @@ -580,14 +578,26 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> { } private Map<String, ComponentDto> getProjectsByComponentUuid(Collection<ComponentDto> components, Collection<ComponentDto> projects) { + Map<String, ComponentDto> projectsByUuid = newHashMap(); + for (ComponentDto project: projects) { + if (project == null) { + throw new IllegalStateException("Found a null project in issues"); + } + if (project.uuid() == null) { + throw new IllegalStateException("Project has no UUID: " + project.getKey()); + } + projectsByUuid.put(project.uuid(), project); + } + Map<String, ComponentDto> projectsByComponentUuid = newHashMap(); - for (final ComponentDto component : components) { - projectsByComponentUuid.put(component.uuid(), Iterables.find(projects, new Predicate<ComponentDto>() { - @Override - public boolean apply(@Nullable ComponentDto project) { - return project != null && project.uuid().equals(component.projectUuid()); - } - })); + for (ComponentDto component : components) { + if (component.uuid() == null) { + throw new IllegalStateException("Component has no UUID: " + component.getKey()); + } + if (!projectsByUuid.containsKey(component.projectUuid())) { + throw new IllegalStateException("Project cannot be found for component: " + component.getKey()); + } + projectsByComponentUuid.put(component.uuid(), projectsByUuid.get(component.projectUuid())); } return projectsByComponentUuid; } |