Blog Post RSS ?

Blogs » Java EE » Tomcat sucks… Is Apache flawed?
 

Tomcat sucks… Is Apache flawed?

by Kevin Yank

High on my list of Java blogs is Hani Suleiman’s The BileBlog, in which he gives unapologetically abrasive reviews of popular Java projects and the people behind them. In the past, he has had been less than complimentary of the Apache Project’s various open source (”opensores”) Java offerings like Maven and Struts. Today, he took Tomcat to task.

Tomcat, of course, provides the reference implementations for the Servlet and JSP specifications, but by virtue of the fact that it is free, it’s also the server of choice for many small-to-medium businesses. I took a critical look at Tomcat myself awhile back, while looking for a beginner-friendly Java web application server (I’m still looking).

Suleiman’s critique of Tomcat is based, somewhat refreshingly (he often resorts to unpersuasive, if entertaining, personal attacks on the developers), on the quality of the project’s code–or rather its lack thereof. Choosing a pivotal but relatively uncomplicated class (DefaultServlet, which is responsible for serving static resources like HTML/CSS/JavaScript files and images), he points out many examples of terrible coding practice, of which these are only a sampling:

Initialization code that lazily catches Throwable
        // Set our properties from the initialization parameters
        String value = null;
        try {
            value = getServletConfig().getInitParameter("debug");
            debug = Integer.parseInt(value);
        } catch (Throwable t) {
            ;
        }
        try {
            value = getServletConfig().getInitParameter("input");
            input = Integer.parseInt(value);
        } catch (Throwable t) {
            ;
        }

Throwable is the base interface for all Java exceptions an errors, many of which have no business being caught by this sort of code, let alone being ignored as this code will do. If the server happens to run out of memory while initializing a DefaultServlet, for example, this code will ignore the resulting error and attempt to continue running.

Attempts to identify particular exceptions by portions of their message strings
        try {
            serveResource(request, response, true);
        } catch( IOException ex ) {
            // we probably have this check somewhere else too.
            if( ex.getMessage() != null
                && ex.getMessage().indexOf("Broken pipe") >= 0 ) {
                // ignore it.
            }
            throw ex;
        }

Fortunately, the if statement in question (which, from the comment, it seems the developer was rather uncertain about) doesn’t actually cause the exceptions it identifies to be ignored (as the second comment says it should do), so this confusing twist of poor programming is actually useless anyway.

A method that returns an exception instead of throwing it
    protected IOException copyRange(InputStream istream,
                                  ServletOutputStream ostream) {

        // Copy the input stream to the output stream
        IOException exception = null;
        ...
            try {
                ...
            } catch (IOException e) {
                exception = e;
                ...
            }
        ...
        return exception;

    }

As a believer in open source development, I looked at every issue he pointed out to give it the benefit of the doubt. “Okay, it looks silly, but there must be a good reason that they did that.” There wasn’t, of course, unless you consider laziness or ignorance a good reason.

For a project produced under the public scrutiny of the open source development, these are disturbingly fundamental issues indeed. For me, the most important question becomes not whether or not Tomcat sucks, but whether this level of code quality is the exception or the norm in the Apache camp.

I know for a fact that there is plenty of good quality open source Java code in the wild. I’ve probed into the code of Jetty a number of times, for instance, and have been pleasantly surprised by what I found there. I also know that poor open source code isn’t just a problem that faced by Java. But Apache is supposed to be a leader in the field.

If the repeated condemnations of The BileBlog are any indication, the majority of the web could be running software like this–code that looks like it was written in a desperate push to meet a deadline with something that works… most of the time… just barely.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Ping.fm
  • Twitthis

Related posts:

  1. How to Install Apache Web Server on Windows Professional web developers need a web server and Apache is...
  2. How to Test Multiple Websites on One PC With Apache Virtual Hosts Testing one website on your local web server is easy....
  3. Free PHP Webinar: How to Increase Performance with Caching Zend are running a free webinar today, with a live...
  4. Truthy and Falsy: When All is Not Equal in JavaScript Anything in JavaScript can be considered to be either truthy...
  5. Server-side JavaScript Will Be as Common as PHP Despite the fact that JavaScript has been typecast as the...

This post has 22 responses so far

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Follow SitePoint on...