What causes an endless recursion in AWTEventMulticaster.mouseEntered()?
I've been doing JFrame for a little bit now, and ever since I started using Mouselistener (or any eventlistner for that matter) things would run smooth for about 2 mins or so. Then I would get a ton of repeating errors, the program would still run but I would be able to use any eventlistener. The error is basically this: ...
(couldn't catch top line in time, but something like Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError) (followed by)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
at java.awt.AWTEventMulticaster.mouseEntered(AWTEventMulticaster.java:282)
...
repeating for hundreds of hundred of lines, where mouseEntered could be any of the eventlistners开发者_JS百科.
I've already spent alot of time going through at checking all integers to see if they go too high(found one, fixed it, still happens). I've also checked everywhere for a value that calls its self, but that doesn't make much sense because it happens like 2 mins into it.
I don't think is has to do with any specific code, just tell me what it means and how I could go about fixing it.
I guess the most likely reason for this is that you have put a component into itself (either directly or indirectly).
As noted above, you have a bug in your code pure and simple and until you show us this code, I doubt we can do anything other than guess. Having said that, my SWA-guess is that you're doing recursion, possibly unknowingly, perhaps by adding a MouseListener to a GUI component from within the MouseListener itself.
Regardless, do yourself and all of us a favor and show the pertinent code since most of us really don't like guessing.
I had a similar case, and although the question might be formulated better, it helped me because Hovercraft[^s]+?s gave a good hint (recursion).
Such issue cannot be isolated in a simple code, probably. At least in my case, it occurred in a complex application, with lot of nested Swing components, including JInternalFrames, wrapped in proprietary classes, etc.
In our case, not completely solved yet, we had a poor management of mouse listeners (lot added on each component of a panel to handle the same context menu instead of having a more global management), and listeners were added and removed depending on user operations.
Anyway, I suspect that somewhere we add lot of listeners (really lot!) without properly removing it. In normal operations, we don't have to remove them, it is done automatically when the component is disposed, but here the listeners are added and added without disposing of the component. And the stack overflow is probably just an iteration on a very deep stack...
I am working on analyzing the code to avoid all these useless listener adding (perhaps detecting if it is there before adding it?). Anyway, in the tiny chance the above analysis can be useful to somebody with a similar case, I expose it there.
In my experience repeatedly adding a given control to the same parent then calling doLayout() can cause stackoverflow with AWTEventMulticaster, however this might be only a bug in a specific java version. (jdk_1.6.18) And this re adding operation might seem nonsense, but was a side effect of reusing components.
The AWTEventMulticaster is used for propagation of control movement/resize and KeyEvent processing. Check related operations.
I had the same issue... In my code were added and removed mouse listeners to an object instance dynamically, but it was done wrong... The consequence was that it produced the same error as you describe. Once deleted the addition and deletion of mouse listeners, everything returned to normal operation. Obviously, the solution to this problem is to add and remove listeners correctly.
gossip-automation.
精彩评论