September 10, 2004
Rotten Statics

We had rather an obscure issue today.

Rather against my advice, we have a class to keep all our string constants in - Constants.java. I wanted to keep these strings either in the classes to which that naturally belong, or in a configuration file if they were likely to change.

What can I say? I was outvoted. ;-)

Anyway, Constants.java consists of nothing but a bunch of lines like this:

public static final String PRINCIPAL_SESSION_ATTRIBUTE = "principal";

At the last minute before going live, the value of one of these strings changed. We ran our dist target, and installed.

One of our classes, let's call it Skippy.java, refers to this string - and we were finding that it was picking up the old value. We were, to say the least, perplexed. We removed the web application completely from Tomcat, and deleted WARs and classes from all over the shop before reinstalling the app. No dice - it still picked up the old value. We bounced Tomcat, which didn't help. We rebooted the server, ditto.

We even decompiled Constants.class. It contained the new value.

In the end, I tried decompiling Skippy.class. Lo and behold, there it was - the old value. WTF was it doing in there? It should have referred to the value in Constants.class, shouldn't it? Why did it have its own copy? And if Skippy.class was supposed to have its own copy of the literal, why didn't Ant recompile it for us?

Anyway, we only had to run ant clean dist, and install the WAR file we got from that, and all was well.

Lessons learned today:

  • Really don't use a bloody constants class.
  • Make your dist target dependent on your clean target.
  • Nobody likes it when you tell them "I told you so". ;-)

Posted to Java by Simon Brunning at September 10, 2004 04:40 PM
Comments
Post a comment
Name:


Email Address:


URL:



Comments:


Remember info?