Solved

StackOverflowError

Posted on 2011-09-22
5
205 Views
Last Modified: 2012-05-12
A customer is receiving a StackOverflowError with a 1024 lines of the following:
at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:312)

This happens over and over.

This is being reported by a customer and I am at a loss as to which component is causing it and I can't seem to duplicate it myself.  What might be causing this or what should I be looking for?

Thanks.
0
Comment
Question by:gpman65
  • 3
5 Comments
 
LVL 4

Expert Comment

by:stachenov
ID: 36581722
Usually this happens because of infinite recursion, but I can't think of any possible way to cause infinite recursion with this class. Well, except for subclassing it and passing "this" to the superclass constructor, but that's not something easily done by mistake. When used in normal way, add() functions create nodes at the root of the listener tree, and there is no way to change deeper nodes to point above themselves, thus creating an event loop.

Perhaps it is not an infinite recursion, but just too much listeners in the tree? Although it is quite hard to imagine having that many listeners.

Or it could be that one of the listeners calls the root listener recursively. But then that particular listener would turn up in the stack trace as well, which apparently isn't happening. Of course it is possible that it also adds another listener at the top of the tree and only then calls the (new) top listener. This sounds too crazy to be true, but it would lead to the tree constantly growing until it gets too large.

Sorry for being so vague, but it is hard to say more without more details about how multicasters are used.
0
 
LVL 4

Accepted Solution

by:
stachenov earned 500 total points
ID: 36581802
Come to think of it, it is not necessary that listeners are added inside other listeners. The "too many listeners" case could be caused by something (anywhere in the program) periodically adding those listeners until the tree grows too large. So the first thing to check is all add() calls. How often are they called? Don't they add the same listeners again and again?

Another thing to do is to change the order of the arguments for add(). The thing is that the listeners are called in the order they are passed to add(). If the listener returned by the previous invocation of add() is passed first, then the event is first propagated down to the deepest node and then listeners are called while the stack "unwinds". The bad thing is that in this case all you get is those "AWTEventMulticaster.java:312" lines. On the other hand, if the root listener returned by add() is passed as the second argument, then it would call the latest listener first, then go down by one level, call the previous listener, and so on. The order would be reversed, but you'll see in the stack trace which listeners are being called, and that could mean easier debugging.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36581813
Are you running it in the same version of Java as your customer?
0
 
LVL 4

Expert Comment

by:stachenov
ID: 36581849
Regarding my last comment: even if the order of the listeners is reversed, you'll only see the listener that was called last, and only if you're lucky enough. Still, it is better than nothing I guess.
0
 

Author Closing Comment

by:gpman65
ID: 36581926
I found where I was adding the same listener over and over again.  I would not have expected a stackoverflow from this, but that does seem to be the cause.  Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now