by jeroenhd · 3y ago · 0 comments
equals
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.
If you're doing bulk operations on stored URLs, you may just be sending out tons of DNS resolutions without ever calling an obvious networking API (like openConnection). If your DNS is down or slow, equals() will block.I'm sure most Java programmer here has learned this lesson, but new programmers get surprised by this every time.
> The java.net.URL constructors are deprecated. Developers are encouraged to use java.net.URI to parse or construct a URL.
I don't recall the exact case, but when I was trying to toleratly parse a URI, I fall back a URL and then convert it to a URI.
Also, URI not URL has been the preferred choice for years and years and years.
But the footgun persists, for backwards compatibility
To sum things up: never ever use java.net.URL, it's a bad http client and it's worse at everything else you might expect it to be.
URL is one of those "it seemed like a good idea in the 90s" legacy warts.