NASA-PDS / harvest

Standalone Harvest client application providing the functionality for capturing and indexing product metadata into the PDS Registry system (https://github.com/nasa-pds/registry).
https://nasa-pds.github.io/registry
Other
4 stars 3 forks source link

FIX Possible null pointer exception and UPDATE error message in createSearchIdsRequest() #99

Closed ramesh-maddegoda closed 2 years ago

ramesh-maddegoda commented 2 years ago

FIX Possible null pointer exception in idExists(String id), when calling retIds.isEmpty() UPDATE error message in createSearchIdsRequest() method when ids == null || ids.isEmpty()

🗒️ Summary

In the following code it returns null when (ids == null || ids.isEmpty()).

public Set<String> getNonExistingIds(Collection<String> ids) throws Exception
    {
        if(ids == null || ids.isEmpty()) return null;
        Response resp = searchIds(ids);

        NonExistingIdsResponse idsResp = new NonExistingIdsResponse(ids);
        parser.parseResponse(resp, idsResp);

        return idsResp.getIds();
    }

However, above method is called by idExists(String id) and it is expecting to have a non-null retIds object to call retIds.isEmpty();.

public boolean idExists(String id) throws Exception
    {
        List<String> ids = new ArrayList<>(1);
        ids.add(id);

        Collection<String> retIds = getNonExistingIds(ids);
        return retIds.isEmpty();
    }

The getNonExistingIds(Collection<String> ids) should return an empty Set<String> instead of null, when (ids == null || ids.isEmpty()).

♻️ Related Issues

Refer to the issue NASA-PDS/harvest#96