Never thought Even constants(public static final) could be Bad

  

Don’t get me wrong. Using Constants are good. But I am just facing a situation where I feel terribly bad on why I did.

Let me explain the background. We make software. As in, Big software. At least So big that we cannot re-deliver the whole code to the client every time we make a change. So, obviously, we deliver patches that contains only the files that got modified as a part of a bug fix. We also take pride of having a beautiful patching system that when given the names of the class files that changed, will automatically make a patch(zip) out of the class files, download it at the client end, unzip it, replace it at correct locations and restart the customer’s server.
This time, the bug I fixed was simple. All I had to do was modify the value of a constant , like for eg., from
public static final int A_CONST = 10;
to
public static final int A_CONST = 20;

that’s it. So as usual, I made this change, gave it to the patching system ,which took the new class file made a zip downloaded it at the customer’s end and replaced the new class file. What do you know, it din’t work. I should have guessed. But I din’t.
The problem was this. In Java when constants are being referred from other files, it doesn’t read the value from the other variable dynamically, but copies the value within itself during compile time. For eg., when class “AnotherClass” access A_CONST, using code, say,
int b = ConstantClass.A_CONST;
it’s replaced to
int b = 10; within the class file.

So Iam off, making a patch by recompiling all the other (nearly 100) java files, and making a patch out of all those :(.







3 Responses to 'Never thought Even constants(public static final) could be Bad'

  1. Arturo Munive - October 5th, 2008 at 11:42 am

    Thankxs man, is very util your words about this theme.

  2. Shelby Watkins - November 12th, 2008 at 9:48 pm

    5f7jyil9aj4hhkjm

  3. Jannie Louwrens - November 18th, 2008 at 7:36 am

    So true, I have not thought about this before. Thanx for sharing.

    I am interested in your “beautiful patching system”, do you have any pointers or links how to build/implement/use susch a process?

    Thank you


Leave a Reply





Popular Articles

Blog Categories

Monthly Archives

Resources