16th Feb 2008 by Mark Turansky

Beware the non-namespaced classpath resource

Filed under Filed under Engineering

We spent too long hunting down a bug in a database method call that consistently returned “null” in our integration environment, but returned the correct value in a development unit test.

Do you see the problem here? Compare these two screenshots. Both screenshots show a look into two different jars on our classpath. The title of this article is a big hint.

jar_two.JPG jar_one.JPG

Two points goes to the first person to explain the problem. (-2 points for any of my teammates that answer first!)

The moral of the story is that namespaces are one heck of a good idea and that we should always be very careful when relying on classpath-based resources.  I’ll write more about the problem after giving others a chance to solve the puzzle.

What's next? CommentsLeave a comment Digg it Save This Page

2 Responses to “Beware the non-namespaced classpath resource”

  1. Matt Passell Says:

    Let me guess… since each of the JARs has a hibernate.cfg.xml at the top level, it was picking up the first one in the classpath it found. Yup, namespaces can be handy for avoiding such conflicts. :)

  2. Mark Turansky Says:

    Exactly right. Two projects by two different teams and there’s my team attempting an integration effort. It took a lot of digging to figure this out, but now we know. I’ll put a notch in the “experience” part of my brain.

Leave a Reply