| Forum | GitHub | Maps | Blog

Zero speed error when calculating shortest distance



Following an example, I wrote a simple Java code that makes graphhopper calculate fastest route distances for many routes offline on OSM maps of the Czech Republic. However, the code fails when I switch from fastest to shortest distance, and I get the following run-time error:

Exception in thread "main" java.lang.IllegalStateException: Speed cannot be 0 for unblocked edge, use access properties to mark edge blocked! Should only occur for shortest path calculation. See #242.

I set the graphhopper engline like this (where NAVIGATION_TYPE is either “fastest” or “shortest”):

hopper.init(new CmdArgs().
        put("prepare.min_network_size", "200").
        put("prepare.min_one_way_network_size", "200").
        put("", NAVIGATION_TYPE));

Could you possibly hint me what’s the problem and how to solve it?

Many thanks. Michal


For which start+end points did you get this exception?



My code, the used map, the list of all routes calculated, and the list of failed routes (log.log) is available at

Best wishes,


When you switch the NAVIGATION_TYPE - did you remove the graph folder before the restart?

E.g. on GH Maps your request seems to work ok.

If you think it is a bug can you create a code snippet that reproduces the issue using a current OSM file (or a file you uploaded)?



  1. I do use a different map folder for each NAVIGATION_TYPE.

  2. Doesn’t the web use the fastest route? My code works ok for fastest routes too. It is shortest routes where I get the run-time error. And even this way the code fails for about 40 routes out of about 170,000.

  3. I do not claim this is a GraphHopper bug—more likely, my code misses some setting that the web version has.

Minimal example is:

package com.prgosek.minitest;

import com.graphhopper.*;
import com.graphhopper.reader.osm.*;
import com.graphhopper.routing.util.*;
import com.graphhopper.util.*;

public class MiniTest {

    private static final String NAVIGATION_TYPE = "shortest";
    private static final String MAP_FILE = "maps/czech-republic-latest.osm.pbf";
    private static final String GRAPH_FOLDER = "graphFolder_" + NAVIGATION_TYPE;

    public static void main(String[] args) {
        GraphHopper hopper = new GraphHopperOSM();
        hopper.init(new CmdArgs().
                put("prepare.min_network_size", "200").
                put("prepare.min_one_way_network_size", "200").
                put("", NAVIGATION_TYPE));
        hopper.setEncodingManager(new EncodingManager("car"));

        // 50.04961,15.198803,50.047056,15.219416
        // 50.047056,15.219416,50.04961,15.198803
        GHRequest req = new GHRequest(50.04961,15.198803,50.047056,15.219416).
        GHResponse rsp = hopper.route(req);
        if (rsp.hasErrors()) {
            System.out.println("ERROR" + rsp.getErrors());
        } else {
            PathWrapper path = rsp.getBest();
            System.out.println("Estimated distance is " + path.getDistance());

Could you possibly help me?

Many thanks,


Probably this is a bug in the ShortestWeighting. Can you modify it and before returning edge.getDistance() using these lines:

double speed = reverse ? flagEncoder.getReverseSpeed(edge.getFlags()) : flagEncoder.getSpeed(edge.getFlags());
if (speed == 0)
  return Double.POSITIVE_INFINITY;