Dec 052006
 

Okay, I’m totally hacked! java.net.URL class officially sucks! The equals method on this shining example of the JDK API mess actually does a blocking DNS lookup on the host string to resolve to an IP address and then compares the IP addresses rather than the host string. What freakin’ sense does that make?

Simple example:

Let’s say these map to these IP addresses:

Here’s the scary part:

These two URLs are NOT equal, ever! They could be different web apps, have different failure IPs and even different servers using a load balancer. At 2AM they might have the same IP, at 2PM they might have different ones. They might be in different states or different countries. And here is the kicker! URL’s equals method isn’t idempotent! If you call it with an Internet connection you might get a different result than if you call it without one! Seriously! I disconnected my ethernet card and got this:

Plus, if you have an Internet connection you have to do a DNS lookup in the equals method of URL to compare IP addresses. This is horribly slow and just a plain old bad idea. You can’t use these in Maps, Sets, Sorted anything or just ever call equals because it takes nearly a second best case to resolve the host name, even on a fast connection.

This code took over 4 minutes to execute:

Argh! This class sucks and I refuse to ever use it again. I’ll always use URI from now on since it doesn’t suck.

The author tag still says James Gosling, so I ask you Mr. Gosling, what were you thinking?

Dec 042006
 

I went with my cousins to the Denver Parade of Lights on Saturday night and had an interesting run in with some technology there. We drove down because it was a bit cold outside and we didn’t want to wait for a bus with Eliot (our 2 year old). Parking was easy to find and fairly inexpensive.

After waiting in line for 10 minutes to pay for parking, I finally make it to the head of the line. There is a big green button that says, “Press to start” and in smaller letters underneath is says, “press again to add time.” Above me there is a large sign that dictates the rates of this parking lot. I went back on Sunday to snap a shot of the sign.

Parking sign

This seems pretty simple. During the day you can only be charged $6 and at night you can only be charged $10. If you just want an hour, it’s simply $3. Seems pretty straightforward to me. We arrived at 5:15PM and so we were in the evenings block and it should cost $10.

So, I naturally hit the green button and then quickly insert my credit card and 2 minutes later (must be using a modem) I have my receipt. I look down at the receipt and notice that I’ve been charged $13 dollars. I ask the attendant what happened and he says, “you must have hit the green button.” Well, of course I hit the green “start” button. As it turns out, this payment device has so many bugs that I just had to share.

1. In the evenings or during special events it isn’t necessary to hit the green button. The machine is always in the “ready” state.
2. If you hit the green button during these times it adds additional hours to your bill. Since the evening rate is $10 and the hourly is $3, hitting the green button makes your total $13.
3. The machine is not programmed to realize the maximum limit of the current purchase. It will happily charge you $31 dollars if you hit the button 7 times.

So, what’s the moral right? The moral is test edge cases. The programmers for this device should have realized there are different maximums at different times during the day. This should be easily set by an administrator and probably changes infrequently. The machine should never allow anyone to add more time than the maximum allows, especially for fixed rate times such as 4PM-6AM. The main test cases would ensure that all the buttons work, the addition of money works, the credit card routines work and all that Jazz. The edge cases are all the little things like adding too much time at 5:15PM or having buttons whose function changes without warning or notice.

Just remember to test the edge cases. They usually end up being the worst bugs and cause the most headaches.