Solved

StackOverflowError

Posted on 2011-09-22
5
204 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
Comment Utility
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
Comment Utility
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
Comment Utility
Are you running it in the same version of Java as your customer?
0
 
LVL 4

Expert Comment

by:stachenov
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countHi challenge 25 84
mapAB Challlenge 35 84
best (free) software to access postgres db (java) 1 17
Free Alternative to JIRA 4 53
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 video teaches viewers about errors in exception handling.

743 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

17 Experts available now in Live!

Get 1:1 Help Now