Fix NPE in getPathSegment