Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 87819

Summary: [EditorMgmt] NPE changing default file association
Product: [Eclipse Project] Platform Reporter: Jared Burns <jared_burns>
Component: UIAssignee: Andrey Loskutov <loskutov>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Andrei.Pozolotin, eclipse, loskutov, trevor
Version: 3.1   
Target Milestone: 4.7 M1   
Hardware: PC   
OS: All   
See Also: https://git.eclipse.org/r/74351
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=de87d4bf278f2eb79b43f63e0a8ae6c50cb05514
Whiteboard:
Attachments:
Description Flags
data/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs none

Description Jared Burns CLA 2005-03-11 15:55:05 EST
Build 20050308

I got the following NPE when I changed a default file association. The change
seemed to take effect despite the NPE.

!ENTRY org.eclipse.core.runtime 4 0 2005-03-11 12:52:50.515
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException
	at
org.eclipse.ui.internal.registry.EditorRegistry.addExternalEditorsToEditorMap(EditorRegistry.java:213)
	at
org.eclipse.ui.internal.registry.EditorRegistry.rebuildEditorMap(EditorRegistry.java:835)
	at
org.eclipse.ui.internal.registry.EditorRegistry.setFileEditorMappings(EditorRegistry.java:964)
	at
org.eclipse.ui.internal.dialogs.FileEditorsPreferencePage.performOk(FileEditorsPreferencePage.java:446)
	at org.eclipse.jface.preference.PreferenceDialog$12.run(PreferenceDialog.java:853)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1015)
	at org.eclipse.core.runtime.Platform.run(Platform.java:757)
	at
org.eclipse.jface.preference.PreferenceDialog.okPressed(PreferenceDialog.java:833)
	at
org.eclipse.jface.preference.PreferenceDialog.buttonPressed(PreferenceDialog.java:220)
	at
org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.buttonPressed(WorkbenchPreferenceDialog.java:243)
	at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:554)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2777)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2471)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:801)
	at org.eclipse.jface.window.Window.open(Window.java:779)
	at org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:66)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:1003)
	at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:557)
	at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:507)
	at
org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:421)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2777)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2471)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1514)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1478)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:297)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
	at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:228)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:338)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:151)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:582)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:268)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:260)
	at org.eclipse.core.launcher.Main.run(Main.java:887)
	at org.eclipse.core.launcher.Main.main(Main.java:871)
Comment 1 Douglas Pollock CLA 2005-03-14 10:37:23 EST
Kim: Do you have any ideas about this?  Perhaps changes recently that might have
set this off?  The problem appears to happen if a null editor descriptor can get
set through the FileEditorMapping.setDefaultEditor(EditorDescriptor) method.
Comment 2 Trevor Robinson CLA 2005-08-04 15:28:28 EDT
I also hit this bug in I20050627-1435 (3.1). I got it when adding some
associations, and also when simply making an existing association the default.
The NPE occurs when clicking OK. The changes do seem to take effect anyway.
Comment 3 Michael Van Meekeren CLA 2006-04-21 13:19:22 EDT
Moving Dougs bugs
Comment 4 Susan McCourt CLA 2009-07-09 19:06:55 EDT
As per http://wiki.eclipse.org/Platform_UI/Bug_Triage_Change_2009
Comment 5 Boris Bokowski CLA 2009-11-17 13:07:21 EST
Remy is now responsible for watching the [EditorMgmt] component area.
Comment 6 Andrei Pozolotin CLA 2016-06-01 10:05:28 EDT
started to happen again:

java.lang.NullPointerException
	at org.eclipse.ui.internal.registry.EditorRegistry.addExternalEditorsToEditorMap(EditorRegistry.java:292)
	at org.eclipse.ui.internal.registry.EditorRegistry.rebuildEditorMap(EditorRegistry.java:981)
	at org.eclipse.ui.internal.registry.EditorRegistry.setFileEditorMappings(EditorRegistry.java:1129)
	at org.eclipse.ui.internal.dialogs.FileEditorsPreferencePage.performOk(FileEditorsPreferencePage.java:506)
	at org.eclipse.jface.preference.PreferenceDialog$12.run(PreferenceDialog.java:925)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
	at org.eclipse.jface.preference.PreferenceDialog.okPressed(PreferenceDialog.java:909)
	at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.okPressed(FilteredPreferenceDialog.java:409)
	at org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.okPressed(WorkbenchPreferenceDialog.java:168)
	at org.eclipse.jface.preference.PreferenceDialog.buttonPressed(PreferenceDialog.java:233)
	at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:619)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4481)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1329)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3819)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3430)
	at org.eclipse.jface.window.Window.runEventLoop(Window.java:827)
	at org.eclipse.jface.window.Window.open(Window.java:803)
	at org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.open(WorkbenchPreferenceDialog.java:211)
	at org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:63)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511)
	at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4481)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1329)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3819)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3430)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1488)

eclipse.buildId=4.5.2.M20160212-1500
java.version=1.8.0_77
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments:  -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.jee.product -clean
Comment 7 Andrey Loskutov CLA 2016-06-01 10:12:41 EDT
(In reply to Andrei Pozolotin from comment #6)
> started to happen again:

Steps to reproduce?
Comment 8 Andrey Loskutov CLA 2016-06-01 10:14:10 EDT
(In reply to Andrey Loskutov from comment #7)
> (In reply to Andrei Pozolotin from comment #6)
> > started to happen again:
> 
> Steps to reproduce?

Please with Neon (4.6) RC.
Comment 9 Andrei Pozolotin CLA 2016-06-01 10:29:10 EDT
steps to reproduce:

1) navigate
Window -> Preferences -> General -> Editors -> File Associations

2) select
File types: Add -> "*.tester"
Associated editors: Add -> "Properties File Editor"

3) click OK
now error log consistently shows same exception:
java.lang.NullPointerException
    at org.eclipse.ui.internal.registry.EditorRegistry.addExternalEditorsToEditorMap(EditorRegistry.java:292)

the association works during current session, and is lost upon eclipse restart

the persistence file 
data/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs

does not show any changes in content or time stamp

I think this started to happen after upgrade to eclipse.buildId=4.5.2.M20160212-1500
Comment 11 Andrei Pozolotin CLA 2016-06-01 10:31:40 EDT
work around:

manually add required entries to *.prefs
data/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs

for example

<info extension\="service" name\="*">\n<editor id\="org.eclipse.jdt.ui.PropertiesFileEditor"/>\n</info>\n
Comment 12 Andrey Loskutov CLA 2016-06-01 10:36:42 EDT
(In reply to Andrei Pozolotin from comment #10)
> source 
> 
> https://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/bundles/org.
> eclipse.ui.workbench/Eclipse%20UI/org/eclipse/ui/internal/registry/
> EditorRegistry.java#n270

Andrei, can you please grab 4.6 RC3 from http://download.eclipse.org/eclipse/downloads/drops4/S-4.6RC3-201605252000/ and try to reproduce your issue with it? The source you've referring to is evolved and the stack doesn't match to the code.
Comment 13 Andrei Pozolotin CLA 2016-06-01 13:37:32 EDT
ok, will do
Comment 14 Andrei Pozolotin CLA 2016-06-01 22:24:29 EDT
test result:
the exception is gone with 
eclipse-jee-neon-RC2-linux-gtk-x86_64.tar.gz
(and whole workspace/prefs migrated 4.5 -> 4.6 on start)
Comment 15 Andrey Loskutov CLA 2016-06-02 04:01:09 EDT
(In reply to Andrei Pozolotin from comment #14)
> test result:
> the exception is gone with 
> eclipse-jee-neon-RC2-linux-gtk-x86_64.tar.gz
> (and whole workspace/prefs migrated 4.5 -> 4.6 on start)

Strange. I hoped to get a fresh stack trace. Anyway, the old stack was referring to this code in EditorRegistry:

FileEditorMapping map = maps[i];
IEditorDescriptor[] descArray = map.getEditors();
for (int n = 0; n < descArray.length; n++) {
     desc = descArray[n];
     mapIDtoEditor.put(desc.getId(), desc); // <-- NPE here
}

The code is still same in head, so I will put some guards into FileEditorMapping which allows today adding "null" editors.
Comment 16 Eclipse Genie CLA 2016-06-02 04:16:26 EDT
New Gerrit change created: https://git.eclipse.org/r/74351
Comment 17 Andrei Pozolotin CLA 2016-06-02 09:56:59 EDT
tested few more times, it is reproducible:

1) exception is thrown in:
Version: Mars.2 Release (4.5.2)
Build id: 20160218-0600

2) exception is not present in:
Version: Neon Release Candidate 2 (4.6.0RC2)
Build id: 20160526-1324

there is also new "suspicious" :-) behavior in 4.6: 
when you type in dialog (first time after start):
"Add File Type : Define a New File Type"
there is a visible delay; probably some cache/search function?
Comment 18 Andrei Pozolotin CLA 2016-06-02 10:03:00 EDT
Created attachment 262202 [details]
data/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs

this is the org.eclipse.ui.workbench.prefs which consistently produces exception;
may be the file itself content gets corrupt as so to produce "null" editors?
Comment 19 Andrei Pozolotin CLA 2016-06-02 10:16:53 EDT
more mystery: the diff on 
org.eclipse.ui.workbench.prefs 
in 4.5 vs 4.6 worksapce shows the files are the same
Comment 20 Andrey Loskutov CLA 2016-06-03 12:49:31 EDT
(In reply to Andrei Pozolotin from comment #19)
> more mystery: the diff on 
> org.eclipse.ui.workbench.prefs 
> in 4.5 vs 4.6 worksapce shows the files are the same

OK, let assume this was fixed in 4.6. Thanks for testing, and feel free to reopen this bug if you will find a way to reproduce it on 4.6+.

BTW, because 4.6 is closed for fixes now, I will push the remaining gerrit patch to 4.7 and close the bug.
Comment 21 Andrei Pozolotin CLA 2016-06-05 14:52:10 EDT
great, thank you.