### Question:
DijkstraOneToMany extends AbstractRoutingAlgorithm { public int findEndNode(int from, int to) { if (weights.length < 2) return NOT_FOUND; this.to = to; if (doClear) { doClear = false; int vn = changedNodes.size(); for (int i = 0; i < vn; i++) { int n = changedNodes.get(i); weights[n] = Double.MAX_VALUE; parents[n] = EMPTY_PARENT; edgeIds[n] = EdgeIterator.NO_EDGE; } heap.clear(); changedNodes.elementsCount = 0; currNode = from; if (!traversalMode.isEdgeBased()) { weights[currNode] = 0; changedNodes.add(currNode); } } else { int parentNode = parents[to]; if (parentNode != EMPTY_PARENT && weights[to] <= weights[currNode]) return to; if (heap.isEmpty() || isMaxVisitedNodesExceeded()) return NOT_FOUND; currNode = heap.poll_element(); } visitedNodes = 0; if (finished()) { if (heap.isEmpty()) doClear = true; return currNode; } while (true) { visitedNodes++; EdgeIterator iter = outEdgeExplorer.setBaseNode(currNode); while (iter.next()) { int adjNode = iter.getAdjNode(); int prevEdgeId = edgeIds[adjNode]; if (!accept(iter, prevEdgeId)) continue; double tmpWeight = weighting.calcWeight(iter, false, prevEdgeId) + weights[currNode]; if (Double.isInfinite(tmpWeight)) continue; double w = weights[adjNode]; if (w == Double.MAX_VALUE) { parents[adjNode] = currNode; weights[adjNode] = tmpWeight; heap.insert_(tmpWeight, adjNode); changedNodes.add(adjNode); edgeIds[adjNode] = iter.getEdge(); } else if (w > tmpWeight) { parents[adjNode] = currNode; weights[adjNode] = tmpWeight; heap.update_(tmpWeight, adjNode); changedNodes.add(adjNode); edgeIds[adjNode] = iter.getEdge(); } } if (heap.isEmpty() || isMaxVisitedNodesExceeded() || isWeightLimitExceeded()) return NOT_FOUND; currNode = heap.peek_element(); if (finished()) return currNode; heap.poll_element(); } } DijkstraOneToMany(Graph graph, Weighting weighting, TraversalMode tMode); @Override Path calcPath(int from, int to); @Override Path extractPath(); DijkstraOneToMany clear(); double getWeight(int endNode); int findEndNode(int from, int to); @Override boolean finished(); void setWeightLimit(double weightLimit); void close(); @Override int getVisitedNodes(); @Override String getName(); String getMemoryUsageAsString();  }### Answer:
@Test public void testIssue239_and362() { GraphHopperStorage g = createGHStorage(false); g.edge(0, 1, 1, true); g.edge(1, 2, 1, true); g.edge(2, 0, 1, true); g.edge(4, 5, 1, true); g.edge(5, 6, 1, true); g.edge(6, 4, 1, true); DijkstraOneToMany algo = (DijkstraOneToMany) createAlgo(g); assertEquals(-1, algo.findEndNode(0, 4)); assertEquals(-1, algo.findEndNode(0, 4)); assertEquals(1, algo.findEndNode(0, 1)); assertEquals(1, algo.findEndNode(0, 1)); }