- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
public static class FuckMeGentlyWithAChainsaw {
/* This wrapper class exists to work around the possibly most
* stupid Java bug ever (and that's saying a lot): That
* URL.equals and URL.hashCode do DNS lookups and
* block. Which, of course, not only sucks performance-wise
* but also breaks actual correct URL equality. */
public final URL url;
public FuckMeGentlyWithAChainsaw(URL url) {
this.url = url;
}
}
Two hosts are considered equivalent if both host names can be resolved into the same IP addresses; else if either host name can't be resolved, the host names must be equal without regard to case; or both host names equal to null.
Since hosts comparison requires name resolution, this operation is a blocking operation.
И не было ещё понимания, что URL - это синтаксическая конструкция, и что сравнивать её нужно синтаксически. Сановцы, поди, думали (писалось-то это в суровые девяностые и предназначалось в основном для загрузки всяких картинок в апплеты): вот мы какие опупеть крутые, сравниваем URL семантически!
И не было понимания того, что в equals и hashCode нельзя выполнять дорогие операции.
Кстати в документации ниже об этом сказано:
Note: The defined behavior for equals is known to be inconsistent with virtual hosting in HTTP.