Matlab reports "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"
Well based on your stack trace probably there's no a definitive answer to your question, as you have already seen in Matlabs forum, but given this line I think there's a possible explanation:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
...
at javax.swing.undo.UndoManager.redoTo(Unknown Source) // <-- here!
at javax.swing.undo.UndoManager.redo(Unknown Source)
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
...
UndoManager class keeps an internal collection of UndoableEdit objects. This collections is actually inherithed from its superclass: CompoundEdit.
The internal implementation of UndoManager#redo() and UndoManager#redoTo(UndoableEdit edit) looks like this:
public class UndoManager extends CompoundEdit implements UndoableEditListener {
...
public synchronized void redo() throws CannotRedoException {
if (inProgress) {
UndoableEdit edit = editToBeRedone();
if (edit == null) {
throw new CannotRedoException();
}
redoTo(edit);
} else {
super.redo();
}
}
...
protected void redoTo(UndoableEdit edit) throws CannotRedoException {
boolean done = false;
while (!done) {
UndoableEdit next = edits.elementAt(indexOfNextAdd++);
next.redo(); // NPE here?
done = next == edit;
}
}
...
}
Considering this implementation and given that Swing's Event Dispatch Thread (EDT) is prone to cause troubles, I think it's probably a threading issue between matlab thread and the EDT. Specifically speaking this matlab invoked method could be the source of the problem:
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
Since you say matlab needs to do heavy work it's not unreasonable think this method is trying to redo some edit that might well not be available anymore or might not be available yet, due to synchronization problems with the EDT.
patrik
Updated on June 21, 2022Comments
-
patrik almost 2 years
Hi wonder about a java error that is repeatedly occurs in matlab. It typically occurs when matlab is doing some heavy stuff with java. This can for example be holding ctrl+z or ctrl+y.
I did by mistake erase the error message before I copied it but I think that I can pass the core of the problem any way.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException ... at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
Does anyone know why this error occur? I have found some information about this from matlab r2007, this due to that java swing is thread unsafe and matlab lacked support to ensure thread safety. However, that is supposed to have been fixed in matlab r2008b. So why do I get it now?
EDIT Here is the full stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at org.netbeans.editor.BaseDocument.notifyUnmodify(BaseDocument.java:1465) at org.netbeans.editor.BaseDocument.notifyModifyCheckEnd(BaseDocument.java:816) at org.netbeans.editor.BaseDocumentEvent.redo(BaseDocumentEvent.java:336) at javax.swing.undo.UndoManager.redoTo(Unknown Source) at javax.swing.undo.UndoManager.redo(Unknown Source) at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255) at org.netbeans.editor.ActionFactory$RedoAction.actionPerformed(ActionFactory.java:767) at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:259) at javax.swing.SwingUtilities.notifyAction(Unknown Source) at javax.swing.JComponent.processKeyBinding(Unknown Source) at javax.swing.JComponent.processKeyBindings(Unknown Source) at javax.swing.JComponent.processKeyEvent(Unknown Source) at com.mathworks.widgets.SyntaxTextPaneBase.processKeyEvent(SyntaxTextPaneBase.java:1187) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source) at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source) at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source) at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source) at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
-
patrik almost 10 yearsThis seems as it could be the root. Thank you for the explanation! I sent a bug report an guess I must hope for the best for the next release.
-
patrik about 8 yearsI am not sure this is the problem. The issue appears only while spawning a lot of events, so it is likely a threading issue. Apart from that I use Windows 7. Maybe I should have written that as well, but I did not see the need back then. This is a java problem so I though it to be fairly system independent. I realize now that this may not be entirely correct, but in that case it should rather be due to different thread handling.