diff options
| author | Andrey Loskutov | 2016-10-02 19:08:15 +0000 |
|---|---|---|
| committer | Andrey Loskutov | 2016-10-06 19:02:43 +0000 |
| commit | a5de7a28e73b045e9dd2255256ee305c96bec0c5 (patch) | |
| tree | fb6f0435f06200eb1e8363c24b857bcc14d51266 | |
| parent | 6dc528992eac66814e45417a81b68ff87949503b (diff) | |
| download | eclipse.platform.ui-a5de7a28e73b045e9dd2255256ee305c96bec0c5.tar.gz eclipse.platform.ui-a5de7a28e73b045e9dd2255256ee305c96bec0c5.tar.xz eclipse.platform.ui-a5de7a28e73b045e9dd2255256ee305c96bec0c5.zip | |
Bug 502514 - NPE in ProgramImageDescriptor.hashCode
Don't allow invalid or system descriptors to be saved to the custom
editor table. Check if the custom editor is the already known system one
on loading memento.
Change-Id: I3fed81365babe70277ff948e40be8e9fc5452606
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
| -rw-r--r-- | bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java index fac7fa2f6fb..1f7b71124c3 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java @@ -653,7 +653,14 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx if (!valid) { continue; } - if (editor.getPluginID() != null) { + if (isSystem(editor.getId())) { + // bug 502514: check if there is internal editor + // descriptor (they are always recreated via + // addSystemEditors(Map<String, IEditorDescriptor>)) + lookupEditorFromTable(editorTable, editor); + continue; + } + if (editor.getPluginID() != null) { //If the editor is from a plugin we use its ID to look it // up in the mapping of editors we //have obtained from plugins. This allows us to verify that @@ -661,24 +668,25 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx //and allows us to get the editor description from the // mapping table which has //a valid config element field. - IEditorDescriptor validEditorDescritor = mapIDtoEditor.get(editor.getId()); - if (validEditorDescritor != null) { - editorTable.put(validEditorDescritor.getId(), - validEditorDescritor); - } - } else { //This is either from a program or a user defined - // editor - ImageDescriptor descriptor; - if (editor.getProgram() == null) { - descriptor = new ProgramImageDescriptor(editor - .getFileName(), 0); - } else { - descriptor = new ExternalProgramImageDescriptor(editor - .getProgram()); + lookupEditorFromTable(editorTable, editor); + continue; + } + // This is either from a program or a user defined editor + ImageDescriptor descriptor; + if (editor.getProgram() == null) { + String fileName = editor.getFileName(); + if (fileName == null) { + String error = "Both editor program and path are null for descriptor id: "; //$NON-NLS-1$ + error += editor.getId() + " with name: " + editor.getLabel(); //$NON-NLS-1$ + WorkbenchPlugin.log(error, new IllegalStateException()); + continue; } - editor.setImageDescriptor(descriptor); - editorTable.put(editor.getId(), editor); - } + descriptor = new ProgramImageDescriptor(fileName, 0); + } else { + descriptor = new ExternalProgramImageDescriptor(editor.getProgram()); + } + editor.setImageDescriptor(descriptor); + editorTable.put(editor.getId(), editor); } } catch (IOException e) { //Ignore this as the workbench may not yet have saved any state @@ -703,6 +711,25 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx } /** + * @param id + * descriptor id + * @return true if the id is one of the system internal id's: + * {@link IEditorRegistry#SYSTEM_EXTERNAL_EDITOR_ID} or + * {@link IEditorRegistry#SYSTEM_INPLACE_EDITOR_ID} + */ + private static boolean isSystem(String id) { + return IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID.equals(id) + || IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID.equals(id); + } + + private void lookupEditorFromTable(Map<String, IEditorDescriptor> editorTable, EditorDescriptor editor) { + IEditorDescriptor validEditorDescritor = mapIDtoEditor.get(editor.getId()); + if (validEditorDescritor != null) { + editorTable.put(validEditorDescritor.getId(), validEditorDescritor); + } + } + + /** * Read the file types and associate them to their defined editor(s). * * @param editorTable @@ -1013,6 +1040,12 @@ public class EditorRegistry extends EventManager implements IEditorRegistry, IEx memento = XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_EDITORS); for (IEditorDescriptor editor : editors) { + if (isSystem(editor.getId())) { + // bug 502514: don't persist internal editor descriptors, + // they are always recreated via addSystemEditors(Map<String, + // IEditorDescriptor>) + continue; + } IMemento editorMemento = memento .createChild(IWorkbenchConstants.TAG_DESCRIPTOR); ((EditorDescriptor) editor).saveValues(editorMemento); |
