Now we check the result of mergeWithCHA()
@@ -329,22 +329,27 @@ public class SearchEngine {
}
}
- /** Use the given {@link DatabaseMerger} to get the stitched graph for the given artifact.
+ /**
+ * Use the given {@link DatabaseMerger} to get the stitched graph for the given artifact.
*
* @param dm the {@link DatabaseMerger} to be used.
* @param groupId the groupId of the artifact to be produced.
* @param artifactId the artifactId of the artifact to be produced.
* @param version the version of the artifact to be produced.
- * @return the stitched graph.
+ * @return the stitched graph, or {@code null} if {@link DatabaseMerger#mergeWithCHA(long)} returns
+ * {@code null} (usually because the provided artifact is not present in the graph
+ * database).
*/
private DirectedGraph getStitchedGraph(final DatabaseMerger dm, final String groupId, final String artifactId, final String version) {
- String identifier = groupId + ":" + artifactId + ":" + version;
+ final String identifier = groupId + ":" + artifactId + ":" + version;
DirectedGraph result = stitchedGraphCache.getAndMoveToFirst(identifier);
if (result == null) {
result = dm.mergeWithCHA(identifier);
+ if (result != null) {
stitchedGraphCache.putAndMoveToFirst(identifier, result);
if (stitchedGraphCache.size() > STITCHED_MAX_SIZE) stitchedGraphCache.removeLast();
}
+ }
return result;
}
@@ -480,6 +485,8 @@ public class SearchEngine {
final var stitchedGraph = getStitchedGraph(dm, groupId, artifactId, version);
stitchingTime += System.nanoTime();
+ if (stitchedGraph == null) throw new NullPointerException("mergeWithCHA() returned null");
+
LOGGER.debug("Stiched graph has " + stitchedGraph.numNodes() + " nodes");
final ObjectLinkedOpenHashSet<Result> results = new ObjectLinkedOpenHashSet<>();
