Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 308894
Collapse All | Expand All

(-)Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java (+43 lines)
Lines 15-20 Link Here
15
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.ILogListener;
19
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.core.runtime.content.IContentType;
21
import org.eclipse.core.runtime.content.IContentType;
20
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.resource.ImageDescriptor;
Lines 454-457 Link Here
454
		}
456
		}
455
	}
457
	}
456
458
459
	public void testBug308894() throws Throwable {
460
		FileEditorMapping newMapping = new FileEditorMapping("*.abc");
461
		assertNull(newMapping.getDefaultEditor());
462
		
463
		FileEditorMapping[] src = (FileEditorMapping[]) fReg.getFileEditorMappings();
464
		FileEditorMapping[] maps = new FileEditorMapping[src.length + 1];
465
		System.arraycopy(src, 0, maps, 0, src.length);
466
		maps[maps.length - 1] = newMapping;
467
468
		final Throwable[] thrownException = new Throwable[1];
469
		ILogListener listener = new ILogListener() {
470
			public void logging(IStatus status, String plugin) {
471
				Throwable throwable = status.getException();
472
				if (throwable == null) {
473
					thrownException[0] = new CoreException(status);
474
				} else {
475
					thrownException[0] = throwable;
476
				}
477
			}
478
		};
479
		Platform.addLogListener(listener);
480
481
		try {
482
			// invoke the same code that FileEditorsPreferencePage does
483
			((EditorRegistry) fReg).setFileEditorMappings(maps);
484
			((EditorRegistry) fReg).saveAssociations();
485
			PrefUtil.savePrefs();
486
		} finally {
487
			// undo the change
488
			((EditorRegistry) fReg).setFileEditorMappings(src);
489
			((EditorRegistry) fReg).saveAssociations();
490
			PrefUtil.savePrefs();
491
492
			Platform.removeLogListener(listener);
493
			
494
			if (thrownException[0] != null) {
495
				throw thrownException[0];
496
			}
497
		}
498
	}
499
457
}
500
}
(-)Eclipse UI/org/eclipse/ui/internal/PlatformUIPreferenceListener.java (-1 / +1 lines)
Lines 153-159 Link Here
153
						for (int j = 0; j < maps.length; j++) {
153
						for (int j = 0; j < maps.length; j++) {
154
							IFileEditorMapping fileEditorMapping = maps[j];
154
							IFileEditorMapping fileEditorMapping = maps[j];
155
							IEditorDescriptor descriptor = fileEditorMapping.getDefaultEditor();
155
							IEditorDescriptor descriptor = fileEditorMapping.getDefaultEditor();
156
							if (!editorMap.containsKey(descriptor.getId())) {
156
							if (descriptor != null && !editorMap.containsKey(descriptor.getId())) {
157
								editorMap.put(descriptor.getId(), descriptor);
157
								editorMap.put(descriptor.getId(), descriptor);
158
							}
158
							}
159
						}
159
						}

Return to bug 308894