Commit 00e0150b authored by Johannes Roith's avatar Johannes Roith

Fix a crash that occurs when a document is opened and closed quickly.

parent eb64dc1e
......@@ -27,8 +27,12 @@ class CallbackJob extends UIJob {
for(JobStatus status:jobStatusList)
Controller.getInstance(editor).notifyObserversOfJobStatus(status);
if (editor == null || editor.hasBeenDisposed())
return Status.CANCEL_STATUS;
Model model = Model.getInstanceForDocument(editor.getDocument());
model.setControllerStatistics(controllerStats);
if (model != null)
model.setControllerStatistics(controllerStats);
Controller.getInstance(editor).notifyChangeJobFinished();
return Status.OK_STATUS;
......
......@@ -47,14 +47,16 @@ public class Controller {
if (instances.containsKey(editor))
instances.remove(editor);
}
public static Controller getInstance(CupTextEditor edit) {
Controller instance = instances.get(edit);
if (instance != null) {
public static Controller getInstance(CupTextEditor editor) {
if (editor == null)
throw new RuntimeException("editor must not be null.");
Controller instance = instances.get(editor);
if (instance != null)
return instance;
} else {
instances.put(edit, new Controller(edit));
return instances.get(edit);
else {
instances.put(editor, new Controller(editor));
return instances.get(editor);
}
}
......
......@@ -29,6 +29,9 @@ public class LaLrResultJob extends UIJob {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (editor == null || editor.hasBeenDisposed())
return Status.CANCEL_STATUS;
IDocument document = editor.getDocument();
if (document != null) {
Model model = Model.getInstanceForDocument(document);
......
......@@ -30,6 +30,9 @@ class ParserResultJob extends UIJob {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (editor == null || editor.hasBeenDisposed())
return Status.CANCEL_STATUS;
IDocument document = editor.getDocument();
if (document != null) {
Model model = Model.getInstanceForDocument(document);
......
......@@ -25,6 +25,9 @@ class StatisticsIfFailedJob extends UIJob {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (editor == null || editor.hasBeenDisposed())
return Status.CANCEL_STATUS;
IDocument document = editor.getDocument();
if (document != null) {
Model model = Model.getInstanceForDocument(document);
......
......@@ -126,7 +126,11 @@ public class CupTextEditor extends TextEditor
IDocumentProvider provider = getDocumentProvider();
if (provider != null)
return provider.getDocument(getEditorInput());
return null;
// This exception is here on purpose, because it should never
// happen. If it does, this indicates a bug elsewhere.
// Please fix that bug instead and do not remove this.
throw new RuntimeException("IDocumentProvider is null!");
}
public static boolean hasOpened(IDocument document) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment