<< When The Fail Whale Fails To Show Up, Did It Fail To Fail? | Home | The Wonderful World Of Amazon Spam (Part 5) >>

Friday Java Quiz: What Was The Programmer Thinking?

It's been a while since I last posted a blog entry here (or tweeted over there, for that matter). It mostly have to do with the new schedule I'm trying to maintain with a new client. I use to go to work at 8:45am and arrive at 9:00am. Now I start a 7:50am and arrive at 8:20am. I didn't realize how important that fifty minutes of early morning time is to this blog. The lack of blog entries is definitely *not* the effect of the Java 1.4 on IE 6 corporate standard programming environment. Although the "we are going to yank the Firefox that you installed on our PC (that you are using)" email people get from time to time are a little bit ...[the author redacted five words here].

Today's quiz is a gem that Michael showed me yesterday. It's part of a huge class that compiles, runs without exceptions, and has been in production for a while. So today's question is not along that line. Instead, I ask you to figure out:

Q: What was the programmer thinking? (The code has been hand-obfuscated to remove any hint of the domain model.)

public boolean isXXXXAllowed() {
  boolean rc = false;
  Iterator it = getYYYYList().iterator();

  do {
    if (it.hasNext()) {
      YYYYInfo aTemp = null;
      try {
        aTemp = (YYYYInfo) it.next();
      } catch (NoSuchElementException e) {
        try {
          aTemp = (YYYYInfo) it.next();
        } catch (NoSuchElementException e2) {
          LOGGER.debug("huh");
        }
      }

      if (aTemp.isXXXXAllowed()) {
        rc = true;
        break;
      }
    }
  } while (it.hasNext());
  return (rc);
}
Tags :


Re: Friday Java Quiz: What Was The Programmer Thinking?

I guess that they thought they were writing thread safe code. That seems even more frightening that the idea that they don't understand iterators.

Re: Friday Java Quiz: What Was The Programmer Thinking?

"Hm... the documentation says it might not work, so lets just double-check that again."

Re: Friday Java Quiz: What Was The Programmer Thinking?

I think it's particularly cute that, even if Iterator would continue to iterate over a concurrently modified list, this would always throw an NPE if the list was shortened because after "huh" isXXXXAllowed would be called on null.

Re: Friday Java Quiz: What Was The Programmer Thinking?

Thinking... might not be the right word... and if he/she was thinking, it was not "Thinking in Java" :-)

Re: Friday Java Quiz: What Was The Programmer Thinking?

I sure don't know what the programmer was thinking while committing this crime, but I'm pretty sure that the thought right before coding this was something in the lines of "Let's learn Java, it might be fun!" :-)

Re: Friday Java Quiz: What Was The Programmer Thinking?

This definitely belongs to the dailyWTF!

Add a comment Send a TrackBack