Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE when querying component metadata for projects without findings #765

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.jdo.Query;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -254,6 +255,10 @@ public synchronized RepositoryMetaComponent synchronizeRepositoryMetaComponent(f
* @since 4.9.0
*/
public List<RepositoryMetaComponent> getRepositoryMetaComponents(final List<RepositoryQueryManager.RepositoryMetaComponentSearch> list) {
if (list == null || list.isEmpty()) {
return Collections.emptyList();
}

final Query<RepositoryMetaComponent> query = pm.newQuery(RepositoryMetaComponent.class);

// Dynamically build the filter string and populate the parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ public void getFindingsByProjectTest() {
);
}

@Test
public void getFindingsByProjectEmptyTest() {
final var metaComponent = new RepositoryMetaComponent();
metaComponent.setRepositoryType(RepositoryType.MAVEN);
metaComponent.setNamespace("com.acme");
metaComponent.setName("acme-lib");
metaComponent.setLatestVersion("1.2.3");
metaComponent.setLastCheck(new Date());
qm.persist(metaComponent);

final var project = new Project();
project.setName("acme-app");
qm.persist(project);

final Response response = jersey.target(V1_FINDING + "/project/" + project.getUuid())
.request()
.header(X_API_KEY, apiKey)
.get();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeaderString(TOTAL_COUNT_HEADER)).isEqualTo("0");
assertThat(getPlainTextBody(response)).isEqualTo("[]");
}

@Test
public void getFindingsByProjectInvalidTest() {
Response response = jersey.target(V1_FINDING + "/project/" + UUID.randomUUID().toString()).request()
Expand Down