Initializing Vectors with objects.

Hi all,

I am investigating a problem and have narrowed down to a section of code where the Vector.get() method returns an empty string instead of null when the key queried doesnt exist. I know I can alter the code to check for null or empty string but I wanted to find out why?

I am not sure if initializing a Vector variable with an existing object is the cause Here is a line from the code:

Vector result = oracleWrapper.getCodeList (regionCode);//This call returns a vector.

In test I ran this code a million times but couldnt recreate it but in production, after a few days (since the server bounce (JRun 4x)) of normal behaviour, it just starts returning empty string instead of null for keys that dont exist in the Vector! Restarting the server is the solution for now!

What I want to find out:

1. Is initializing Vectors like in the snippet above fine?

2. Are there any known issues similar to this scenario?

3. Is call to a constructor explicitly required to guarantee its integrity?

Thanks a mill,

Jay

[1117 byte] By [JayRoya] at [2007-11-27 11:32:56]
# 1

1. You are not initializing any Vector in that line, you are assigning the return value of getCodeList to a Vector reference called result.

2. I'm sure the issue lies within the getCodeList method not within Vector.

3. You can't initialize a Vector without a call to one of it's constructors at some place (most likely this is happening within getCodeList.

So without seeing the getCodeList method, I can't comment any further.

dwga at 2007-7-29 16:48:26 > top of Java-index,Core,Core APIs...
# 2

Thanks dwg for the reply,

I was reading OracleWrapper class (on which the getCodeList is called) and can see a class level private static Vector variable is being populated with the result from the ResultSet and that is returned to the caller! The method itself isn't synchronized but it populates this private static variable before returning it to the caller!

oo00(I hate it when people make things complicated for no reason...)

OracleWraper is a utility class for managing calls to Oracle (public class)

I know a few things are just not right here but want a second opinion.

Please let me know.

Thanks,

Jay

JayRoya at 2007-7-29 16:48:26 > top of Java-index,Core,Core APIs...
# 3

Also I forgot to mention, the getCodeList function actually calls another function where it constructs a local Vector variable, populates it and returns it to getCodeList where it receives it in the private static Vector variable, which is then returned to the caller!

So, yes, there is a time during this function's execution where a vector variable is being constructed as expected, populated and stored into a private static Vector before being returned to the caller.

Your turn!

Thanks,

Jay

PS: Sorry for not being able to past the code snippet! Its a financial system.

JayRoya at 2007-7-29 16:48:26 > top of Java-index,Core,Core APIs...
# 4

Guess what? I just discovered its not returning empty string but an incomplete string with bits of information missing within delimiters! They printed fine before they were put in the vector! The value missing is put in by a string buffer which is an empty string but is delimited (<dataset><zone>1</zone><code></code></dataset>#) in the vector. There still is a problem with the Vector, why is it returning this incorrect value at all when the key doesnt match none in the Vector?

JayRoya at 2007-7-29 16:48:26 > top of Java-index,Core,Core APIs...
# 5

Vector.get() matches on whatever the equals() method does.

This is not a problem in Vector.

ejpa at 2007-7-29 16:48:26 > top of Java-index,Core,Core APIs...
# 6

True and I have already removed the Vector from my list of suspects because this problem only happens after a few days of normal functioning and the vector still contains an incomplete string when the error starts. I am on the look for statements that may be resulting in memory leaks and temporarily have a Properties object in my list of suspects along with a few StringBuffers.

The code has a statement Properties props = null;

and then after a few lines a value from a Vector object is put into it!

props= (Properties) result.elementAt(idx);

I have load tested it but cant get it to break!

I have spent way too long on this and may be rewriting it would have been quicker! But cant :(

I am soo stuck.

JayRoya at 2007-7-29 16:48:26 > top of Java-index,Core,Core APIs...
# 7

If the Vector returns an empty string you must be putting an empty string into it somewhere.

ejpa at 2007-7-29 16:48:26 > top of Java-index,Core,Core APIs...