News for hackers. Stuff that matters.
Re:Kotlin vs. Java by ivolimmen on Tuesday December 17, 2019 @12:54AM (#21811047)
It's worse. In 1.4 they added URI because URL is very flawed. You should never use URL. The equals method actually does a DNS resolve and compares the ip addresses. This means that comparing two URL's on the same server will always return true when compared. A lot of URL's you compare will give you true as there are a lot of sites run on the same machine with the same ip address.
Re:Kotlin vs. Java by sebcat on Tuesday December 17, 2019 @02:39AM (#21811504)
Had this happen in production in a third party library we used many moons ago. Sysop came and asked us why we did six figure DNS lookups over a short period of time (24h? Less? Don't remember).

Would probably have gone unoticed at most AWS/GCP/Azure shops today.

Re:Kotlin vs. Java by swish_bob on Tuesday December 17, 2019 @04:05AM (#21811916)
Worse was when I had somebody adding the ip address as an Inet4Address on every message passed between machines in a production environment that explicitly didn't have DNS (banks have occasionally very odd ideas about securing subnets). Every single message was doing a reverse DNS lookup and then timing out. And there were a _lot_ of messages.
Re:Kotlin vs. Java by franga2000 on Tuesday December 17, 2019 @02:45AM (#21811530)
Wait, seriously? Did whoever designed that have any idea what URLs actually were? Even without DNS, comparing the hosts is no way to compare URLs. I can't think of a single example of two 'equal' URLs whose strings don't match (up until the parameters, at least)...
Re:Kotlin vs. Java by matthewmacleod on Tuesday December 17, 2019 @02:59AM (#21811589)
Yes - bear in mind the URL class has been around since 1995, when the landscape was somewhat different!

At that point, URLs resolving to the same IP were considered equal, even if the host names were different. Even now, there’s no real difference between say “http://example.xn--com-9o0a and “http://example.com:80”; it would have been reasonable to consider these equal.

Re:Kotlin vs. Java by benibela on Tuesday December 17, 2019 @06:09AM (#21812482)
Re:Kotlin vs. Java by twic on Tuesday December 17, 2019 @03:07AM (#21811630)
Re:Kotlin vs. Java by franga2000 on Tuesday December 17, 2019 @03:52AM (#21811858)
Those are certainly not equivalent, as the 1st would not even resolve in the majority of environments. I'm assuming the 2nd host is a reverse proxy for the 1st? Unless that fact is part of your design assumptions (which it certainly can't be for a general URL class in a standard library), those should be considered different.
Re:Kotlin vs. Java by twic on Tuesday December 17, 2019 @09:03AM (#21813484)
If the two hostnames resolve to the same IP address, they are equivalent. This could happen if initech.com was a default domain. This is a very standard situation in internal networks which i am surprised you are not familiar with.
Re:Kotlin vs. Java by franga2000 on Tuesday December 17, 2019 @09:38AM (#21813814)
I am quite familiar with that kind of setup and it's even further from equivalent than what I assumed you were referring to. Shared web hosting is the common example, but some other protocols are capable of distinguishing between hostnames.

google.com and maps.google.com resolve to the same address but are not equivalent. Even if your example and many others are equivalent, there are many that aren't. A general library should not make assumptions like that, unless they hold 100% of the time.

Re:Kotlin vs. Java by twic on Tuesday December 17, 2019 @10:56AM (#21814757)
You asked for a single example of two 'equal' URLs whose strings don't match up, and now you've got one.
Re:Kotlin vs. Java by franga2000 on Tuesday December 17, 2019 @11:32AM (#21815202)
Looking back, I did phrase it ambiguously. What I meant was two URLs that are equal by definition, (no matter the server config, assuming standards compliance). A (general) library should make no more assumptions than the standard it implements. What I was asking about were cases, similar to http://h/p?x1=a&x2=b being equal to http://h/p?x2=b&x1=a since query parameter order is defined to not matter.

The spec I am mostly familiar with is, however, rather new, and whatever standard controlled URLs at the time (if any) might have made more assumptions.

Re:Kotlin vs. Java by davedx on Tuesday December 17, 2019 @06:42AM (#21812602)
Wow. And of course .equals is a synchronous method, so the whole thread blocks on a network operation whenever you do that.

Helluva way to thread starve your application. :(

https://docs.oracle.com/javase/7/docs/api/java/net/URL.html#...