private double calcDistance(ReaderWay way, WaySegmentParser.CoordinateSupplier coordinateSupplier) {
        LongArrayList nodes = way.getNodes();
        // every way has at least two nodes according to our acceptWay function
        GHPoint3D prevPoint = coordinateSupplier.getCoordinate(nodes.get(0));
        if (prevPoint == null)
            return Double.NaN;
        boolean is3D = !Double.isNaN(prevPoint.ele);
        double distance = 0;
        for (int i = 1; i < nodes.size(); i++) {
            GHPoint3D point = coordinateSupplier.getCoordinate(nodes.get(i));
            if (point == null)
                return Double.NaN;
            if (Double.isNaN(point.ele) == is3D)
                throw new IllegalStateException("There should be elevation data for either all points or no points at all. OSM way: " + way.getId());
            distance += is3D
                    ? distCalc.calcDist3D(prevPoint.lat, prevPoint.lon, prevPoint.ele, point.lat, point.lon, point.ele)
                    : distCalc.calcDist(prevPoint.lat, prevPoint.lon, point.lat, point.lon);
            prevPoint = point;
        }
        return distance;
    }
@Test
    public void testDoNotRejectEdgeIfFirstNodeIsMissing_issue2221() {
        GraphHopper hopper = new GraphHopperFacade("test-osm9.xml").importOrLoad();
        BaseGraph graph = hopper.getBaseGraph();
        assertEquals(2, graph.getNodes());
        assertEquals(1, graph.getEdges());
        AllEdgesIterator iter = graph.getAllEdges();
        iter.next();
        assertEquals(0, iter.getBaseNode());
        assertEquals(1, iter.getAdjNode());
        assertEquals(51.21, graph.getNodeAccess().getLat(0), 1.e-3);
        assertEquals(9.41, graph.getNodeAccess().getLon(0), 1.e-3);
        assertEquals(51.22, graph.getNodeAccess().getLat(1), 1.e-3);
        assertEquals(9.42, graph.getNodeAccess().getLon(1), 1.e-3);
        assertEquals(DistanceCalcEarth.DIST_EARTH.calcDistance(iter.fetchWayGeometry(FetchMode.ALL)), iter.getDistance(), 1.e-3);
        assertEquals(1312.1, iter.getDistance(), 1.e-1);
        assertEquals(1312.1, DistanceCalcEarth.DIST_EARTH.calcDistance(iter.fetchWayGeometry(FetchMode.ALL)), 1.e-1);
        assertFalse(iter.next());
    }