19 Iulii 2006

Java is evil, part 4132

So I’ve got this one collection that the sponsoring body doesn’t want people idly browsing. (Yes, the items are already off-limits, but even the browse pages are spoilerrific.) Okay, um, maybe I can hack the JSP, let me see… yes, I can. Grab the collection handle, test it against the proscribed collection, if it’s the proscribed collection kill the browse links. Easy-peasy.

(Yes, I know that smart people could hand-construct a browse URL, and the items can still be picked out of all-of-DSpace browses. If anyone’s willing to work that hard, fine. When I told the collection sponsor this, he was fine with it too.)

Except. It. Didn’t. Work. It didn’t kill DSpace. It didn’t break anything. It just plain didn’t work.

WTF?

In any decent language, my first attempt at the if clause would have worked:

<% if (handle == "1234/5678") { %>

But this is Java, which regards decency toward programmers as a matter for its inferiors, so we can’t use ==; we have to use the .equals method on the string. Oh, and heaven forbid the incorrect == syntax should, you know, fire an error or anything, because of course Real Programmers never need to know where they’ve screwed up. Silent failure will be just peachy.

For the record, though, <% if (handle.equals("1234/5678")) { %> worked fine, and the collection is now off-limits to casual browsing.

Java. Is. Teh. EEEEEEVIL!