public RegionLocations removeElementsWithNullLocation() {
    HRegionLocation[] newLocations = new HRegionLocation[locations.length];
    boolean hasNonNullElement = false;
    for (int i = 0; i < locations.length; i++) {
      if (locations[i] != null && locations[i].getServerName() != null) {
        hasNonNullElement = true;
        newLocations[i] = locations[i];
      }
    }
    return hasNonNullElement ? new RegionLocations(newLocations) : null;
  }
Set the element to null if its getServerName method returns null. Returns null if all the
elements are removed.
hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLocations.java