File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Passing LinkedList from one class to another and list comes empty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Passing LinkedList from one class to another and list comes empty" Watch "Passing LinkedList from one class to another and list comes empty" New topic
Author

Passing LinkedList from one class to another and list comes empty

Daniel Goldman
Greenhorn

Joined: Mar 25, 2011
Posts: 7
Hi all,


I have a messaging service webapp running through Tomcat 7. Recently I ran into this problem where A method from class Alpha returns LinkedList with few elements in it; B method in Beta class gets the list that is empty.

Weird thing is that this used to work fine, and I did not change any code. I am suspecting this could be either Tomcat or JVM issue. Did anyone run into this problem before? If so, can you help me out to find the solution?

Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

I'm sure we could help with your problem. And the way to start would be to look at your code. Yes, that code which you didn't change. Along with other information which could help us understand that code, such as identifying the line where the method call occurs (you were asking about a method call when you said "passing LinkedList from one class to another", weren't you?) and the way that you saw that the data was vanishing at exactly that location.
Daniel Goldman
Greenhorn

Joined: Mar 25, 2011
Posts: 7
So here's what I did:




and now I try to call receiveMessage function from another class




and if I call retrive() in class B's main method, it will say the size is 0. This has never happen to me in my life before.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

But you're calling a static method from the "B" code. You haven't showed us that method.
Daniel Goldman
Greenhorn

Joined: Mar 25, 2011
Posts: 7
Do you mean the call from main()? I do not quiet understand what you think my static call is. Also I should add another piece of detail. This method is called from a servlet. So assume that the servlet has doGet() method, and retrieve() in B class is called in doGet method. I do not know if this would help.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

Daniel Goldman wrote:Do you mean the call from main()?


I couldn't possibly have meant that, because you didn't post any code for "main". What I meant was the call to the static method here:


And what's that about servlets? You are making me suspect that the code you are posting isn't the actual code that you are having a problem with. Which would be a waste of my time and yours, wouldn't it?
Daniel Goldman
Greenhorn

Joined: Mar 25, 2011
Posts: 7
You are right. I am not allowed to post the code since it belongs to my company. I just wrote an example that is very much the same thing w/o some other operations. Anyway, I will try to ask Sr. engineers within the company if you think I need to show more code. This might take more time but I do not have another option. Thank you for the help though.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18135
    
    8

Yes... if the question is "This code doesn't appear to be doing the right thing" then there's no alternative to looking at the code. Looking at paraphrases isn't very practical since in making the paraphrase you may have accidentally removed the bug.

Since you mentioned servlets, though, let me just mention that intermittent problems in the servlet world are often caused by concurrency problems. So if you put instance variables in a servlet, you could get concurrency problems. Or if you used static variables somewhere in beans used by your servlet. Even using session attributes can cause concurrency problems if you get two almost-simultaneous requests from the same client.
Daniel Goldman
Greenhorn

Joined: Mar 25, 2011
Posts: 7
Ok, I will remember that for future reference. Anyway, I found out the solution. The classes were compiled in 64 bit Centos. That machine died when the cloud server failed. 64bit images were invalid, so I used 32bit Centos for my new tomcat server box. I recompiled and jared it up again. Now it works. It must have been one of those strange JVM issues. Java isn't perfectly portable. *sigh. Well, thank you for the help thou
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing LinkedList from one class to another and list comes empty
 
Similar Threads
collections...urgent
ListIterator()
LinkedList
Linked List Sorting Problems
Linked List Sorting Problem