public static int getCodeIndex(Location location) {
    try {
      return Math.toIntExact(location.codeIndex());
    }
    catch (InternalError | IllegalArgumentException e) {
      return -1;
    }
  }
public static int getCodeIndex(Location location)