This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help, Vector not being passed correctly!

 
Jeremy Jenkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a problem passing an object to a Stateless Session Bean that contains a Vector. I can verify that my object's Vector contains data at the client end, but in my EJB, the Vector is empty. All my contents are serializable, and to prove it to myself, I broke my problem into this simplified version:
Client code:


Bean's method's code:

In the client, if I use a LinkedList, then all works fine. If I use a Vector, the bean returns false, and prints "size=0" in my app server's console. In another experiment while using the Vector as the parameter, ".size()" returns 0, but ".capacity()" throws a null pointer exception from within the Vector class.
Any ideas what might be going on here? I'm stumped.
I'm running SUN ONE 7.0.0_01 on Win2K.
 
Jeremy Jenkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems it's a problem with JVM versions. I checked my app server's jvm and it's 1.4.1_01. I was running the client on 1.4.2_01. Downgrading my client to 1.4.1_01 fixes the problem with Vector. This isn't a good overall solution for my case though. But at least I know what trigger's the problem.
Looks like a bug report to me... Has anyone had success with these combinations of jvm's? Or might this be a SUN ONE specific issue.
 
Howard Kushner
author
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jeremy,
I must confess that I am confused by your example. Why would one have a stateless session maintain some conversational state (i.e. maintain a reference to a vector)?
An EJB is a remote object. Your client (unless it is local to the bean) does not maintain a reference to the bean instance. Rather it is using a proxy that communicates indirectly with the bean via the container.
Since you say it is a stateless session bean, the container can use any available instance which it may have pooled. In other words, you are not guaranteed to be talking to the same bean from one method invocation to the next.
Hope this helps. Please let me know if there is anything more I can do to help clarify.
Regards,
 
Jeremy Jenkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Howard,
Thanks for your reply. I have a bean that does some calculations. I give it a Vector, and it uses the objects contained within it to do some calculations. It then returns the "answer".
I populate the data Vector on the Client end, pass the vector to my remote stateless session bean (It doesn't need to keep track of state, only do "simple" calculations based on the arguments provided). The bean does the calculations and passes the answer back to my Client. I can verify that my data is within my collection on the Client end before the EJB call. Once in the EJB, I get puzzling behavior:
Using a Vector to pass data does *NOT* work.
Using an ArrayList to pass data *DOES* work.
Using a LinkedList to pass data *DOES* work.
Vector reports a size() of 0, and throws a null pointer exception upon calling capacity() (Coming from within the Vector... not that the Vector itself is null). The two other Collections work perfectly well.
This only happens when my client and app server are using differing JVM versions. When they match, Vector works. This seems like a rather significant bug to me.
 
Howard Kushner
author
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Now I get it. So let me ask this... do you really need such a fancy collection? Are there truly arbitrary objects? If not then you could simplify your life perhaps with a simple array of some type, for example:

 
Jeremy Jenkins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, the collection can have 0 or more objects contained within it.
The situation is complicated by the fact that what is passed to the EJB is really an object that contains the collection I've described. I simplified my example test case to isolate the fact that the problem was being caused by the remote passing of a Vector argument. Anyway, the amount of bookeeping I would have to add to be able to use a plain array, would be reinventing a collection. As it is, I'm converting everything to an ArrayList (Which is a better solution anyway) to get around this problem.
I'm suprised noone else has seen this, however.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic