In #Java, two entirely different URLs may be considered equal. Sometimes. Why? DNS. It's always DNS. Well, Java works this way: "Two hosts are considered equivalent if both host names can be resolved into the same IP addresses". Let's dig (no pun intended!) a little bit deeper 🧵
Using dig we notice that these domains (Polish president and some dating site) point to the same servers. Scandal? No. CDN. These are #Cloudflare IPs:
Trying to access this IP directly fails. But just add Host header to HTTP request and everything works just fine:
The best part: the fact that these two URLs are equal is temporary. They'll become unequal if DNS becomes unreachable or returns different IP. TL;DR: URL.equals() in Java is broken beyond comprehension. It makes a network call, it's slow, unreliable and is a terrible HashMap key
• • •
Missing some Tweet in this thread? You can try to
force a refresh