We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aa780a9 commit 9d86ee7Copy full SHA for 9d86ee7
1 file changed
src/main/java/com/thealgorithms/datastructures/graphs/Dijkstra.java
@@ -171,9 +171,15 @@ public String toString() {
171
172
// another pass to set neighbouring vertices
173
for (Edge e : edges) {
174
- graph.get(e.v1).neighbours.put(graph.get(e.v2), e.dist);
175
- // graph.get(e.v2).neighbours.put(graph.get(e.v1), e.dist); // also do this for an
176
- // undirected graph
+ var v1 = graph.get(e.v1);
+ var v2 = graph.get(e.v2);
+
177
+ // this null-check satisfies Infer static analyzer
178
+ if (v1 != null && v2 != null) {
179
+ v1.neighbours.put(v2, e.dist);
180
+ // v2.neighbours.put(v1, e.dist); // also do this for an
181
+ // undirected graph
182
+ }
183
}
184
185
0 commit comments