Despite numerous detractors to Jakarta’s Commons Collections project, I will occassionally find a use for it. Some of their Comparator classes are handy, as well as the utility classes for manipulating various collections. It has saved me time, and that’s always a good thing. However, after the error I ran into today, I am starting to side with its detractors.
I wanted to use a Predicate to filter out unwanted items from a list. A Predicate is a simple interface with one method: evaluate(Object):boolean. You can use the ListUtils.predicatedList(List,Predicate):List method to return a list of items that evaluate to true in the Predicate. Simple enough.
After implementing the Predicate interface, I wrote and ran simple test case that should have removed five items from the list I passed in. Instead of the green bar, I was greeted with an IllegalArgumentException. It turns out that the class used to create a predicated list will throw that exception when it encounters an item that evaluates to false.
This means that the utility methods, like ListUtils.predicatedList(List,Predicate):List and SetUtils.predicatedSet(Set,Predicate):Set will throw an exception when you least expect it. The contract for these methods says that an IAE will be thrown if the passed collection is null, but nothing about items failing to evaluate.
Besides violating the Principle of Least Astonishment, I had to waste time digging through their code trying to find the cause of this mystery exception.
I normally side with the Jakarta people when questions about code quality come up. They have a hard job, and a lot of eyes are on their code. Because of their visibility, they should be more diligent to test for bugs like this.
I’ve filed this issue as a bug on the Jakarta site. Hopefully it will be addressed.
nick Uncategorized
The good folks at Apache have installed a new Struts wiki, using MoinMoin. At this time, I’m not sure if the old content is going to be copied over, but there wasn’t much there to begin with.
Hopefully, this will be a step towards removing some of the idiocy from the Struts user mailing list, but don’t count on it.
nick Uncategorized
Microsoft has released the second service pack for all editions of Windows XP. While only a release candidate, this SP seems to be primarily about tightening up the generally loose security around the MSFT operating system. According to the change log abstract, this release centers on improving the resistance to malicious attacks.
Should you believe it? Probably not. Microsoft has yet to properly address the problem of shoddy code and bug-ridden operating systems, and it’s not likely they will anytime soon. Let’s face it: if they release the perfect OS, you’re not likely to upgrade as quickly.
nick Uncategorized
Just in from the Apache board meeting:
The Apache Jakarta Struts project requested to become a “top level” project of the ASF. The Board definitely agreed with their request, and passed the resolution unanimously with little discussion. Craig McClanahan will be the Chair of the new Apache Struts PMC.
Congrats to the Struts developers. I think it was far too long in coming.
nick Uncategorized
Standard & Poor’s cut Sun Microsystems bond rating from BBB to BB-plus, citing lack of consistent profitability, over a billion dollars in debt, and a changing technology landscape. What does this mean for Sun and Java in the short- and long-term? Probably little.
A company’s bond status can change market perception, but has little impact on the underlying financials of the company, other than higher borrowing costs. SUNW fell by 5% at the time of this posting, the share price has been falling lately anyway. The updated bond rating could only accelerate the fall, but I believe that any price over $4/share is a gift to McNealy.
nick Uncategorized
In various projects I’ve had the need to parse HTML. Falling back to the poorly-written Swing HTML parser wasn’t acceptable. Using a tool like JavaCC proved too cumbersome. Thankfully, Andy Clark wrote an extension to Xerces, called CyberNeko, that allows you to treat just about any HTML document as well-formed XML. DOM and SAX parsing methods are available, and it’s still quite fast.
The next time you need to parse HTML, try this package. It will likely save you hours, if not days, of frustration.
nick Uncategorized