This might work for a query like "Macau, China", but not for "Taipa, China" (Taipa is an island in Macao). I verified that it works with the fix in its current form.

In general, I made no assumptions about what types the most or least specific features might be, just that the list of features, between them, have different but legal country codes.

Now that I think of it, that was a bad idea, because I find that with the fix in its present form, a query like "Macao, Shanghai" returns Macau with a formatted name of "Macau, Shanghai, Macao"

Instead, I'll change this to only trigger when f (rather than most_specific) is a country, like so:

(f.fmatch.feature.woeType == YahooWoeType.COUNTRY && NameUtils.getDependentCountriesForCountry(f.fmatch.feature.cc).has(most_specific.fmatch.feature.cc))