diff --git a/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java b/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java index ca960eebbf7..1b6c9e226e3 100644 --- a/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java +++ b/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java @@ -162,6 +162,8 @@ public String getName() { * Use this method to associate a graph with this weighting to calculate e.g. node locations too. */ public void setGraph(Graph graph) { + if(graph == null) + return; this.na = graph.getNodeAccess(); } } diff --git a/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java b/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java index dde67760969..02f0ca3d14f 100644 --- a/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java +++ b/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java @@ -106,4 +106,11 @@ public void testCalcTime() { EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1); assertEquals(edgeWeight, weighting.calcMillis(edge, false, EdgeIterator.NO_EDGE), .1); } + + @Test + public void testNullGraph() { + ConfigMap cMap = encoder.readStringMap(new PMap()); + GenericWeighting weighting = new GenericWeighting(encoder, cMap); + weighting.setGraph(null); + } }