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

Bug 323519

Summary: [RAP/EMF]ExtendedImageRegistry NullPointerException after session time out
Product: [Modeling] EMF Reporter: chengdong Mising name <chengdong.li>
Component: EditAssignee: Kenn Hussey <Kenn.Hussey>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Kenn.Hussey
Version: 2.6.0Flags: Kenn.Hussey: helios+
Target Milestone: SR1   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
library model used as a test case.
none
proposed changes
none
propsed patch for ExtendedImageRegistry
none
better patch none

Description chengdong Mising name CLA 2010-08-24 12:52:04 EDT
Build Identifier: 2.6.0

The ExtendedImageRegistry is a singleton, and it does not allow dispose images when display is disposed or session time out (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=314239). This cause following problem:

In the current EMF generated EMF/RAP editor, after the session timeout, if user restart the session, there will be a java.lang.NullPointerException from ExtendedImageRegistry:93.

Exeptions stack print out:

!ENTRY org.eclipse.rap.jface 4 2 2010-08-09 14:32:43.504
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.rap.jface".
!STACK 0
java.lang.NullPointerException
    at org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry.getImage(ExtendedImageRegistry.java:92)
    at org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider.getImageFromObject(AdapterFactoryLabelProvider.java:365)
    at org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider.getImage(AdapterFactoryLabelProvider.java:336)
    at org.eclipse.jface.viewers.WrappedViewerLabelProvider.getImage(WrappedViewerLabelProvider.java:117)
    at org.eclipse.jface.viewers.WrappedViewerLabelProvider.update(WrappedViewerLabelProvider.java:165)
    at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:153)
    at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:916)
    at org.eclipse.jface.viewers.AbstractTreeViewer$UpdateItemSafeRunnable.run(AbstractTreeViewer.java:102)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.runtime.Platform.run(Platform.java:888)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:996)
    at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:481)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.core.runtime.Platform.run(Platform.java:888)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2142)
    at org.eclipse.jface.viewers.AbstractTreeViewer.createTreeItem(AbstractTreeViewer.java:811)
    at org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractTreeViewer.java:786)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:66)
    at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren(AbstractTreeViewer.java:760)
    at org.eclipse.jface.viewers.TreeViewer.createChildren(TreeViewer.java:640)
    at org.eclipse.jface.viewers.AbstractTreeViewer.internalInitializeTree(AbstractTreeViewer.java:1474)
    at org.eclipse.jface.viewers.TreeViewer.internalInitializeTree(TreeViewer.java:829)
    at org.eclipse.jface.viewers.AbstractTreeViewer$5.run(AbstractTreeViewer.java:1458)
    at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1423)
    at org.eclipse.jface.viewers.TreeViewer.preservingSelection(TreeViewer.java:403)
    at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1384)
    at org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(AbstractTreeViewer.java:1451)
    at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:274)
    at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1665)
    at org.eclipse.example.library.presentation.LibraryEditor.createPages(LibraryEditor.java:935)
    at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:310)
    at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:658)
    at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:429)
    at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:594)
    at org.eclipse.ui.internal.EditorAreaHelper.setVisibleEditor(EditorAreaHelper.java:263)
    at org.eclipse.ui.internal.EditorManager.setVisibleEditor(EditorManager.java:1414)
    at org.eclipse.ui.internal.EditorManager$3.runWithException(EditorManager.java:947)
    at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:32)
    at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:187)
    at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
    at org.eclipse.swt.widgets.Display.syncExec(Display.java:1019)
    at org.eclipse.ui.internal.StartupThreading.runWithThrowable(StartupThreading.java:97)
    at org.eclipse.ui.internal.EditorManager.restoreState(EditorManager.java:942)
    at org.eclipse.ui.internal.WorkbenchPage.restoreState(WorkbenchPage.java:3021)
    at org.eclipse.ui.internal.WorkbenchWindow.restoreState(WorkbenchWindow.java:2154)
    at org.eclipse.ui.internal.Workbench.doRestoreState(Workbench.java:3366)
    at org.eclipse.ui.internal.Workbench.restoreState(Workbench.java:2076)
    at org.eclipse.ui.internal.Workbench.access$26(Workbench.java:2061)
    at org.eclipse.ui.internal.Workbench$45.run(Workbench.java:1912)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.Workbench.restoreState(Workbench.java:1850)
    at org.eclipse.ui.internal.WorkbenchConfigurer.restoreState(WorkbenchConfigurer.java:181)
    at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:783)
    at org.eclipse.ui.internal.Workbench$25.runWithException(Workbench.java:1341)
    at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:32)
    at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:187)
    at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
    at org.eclipse.swt.widgets.Display.syncExec(Display.java:1019)
    at org.eclipse.ui.internal.StartupThreading.runWithoutExceptions(StartupThreading.java:110)
    at org.eclipse.ui.internal.Workbench.init(Workbench.java:1336)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2315)
    at org.eclipse.ui.internal.Workbench.access$5(Workbench.java:2206)
    at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:424)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.jface.internal.databinding.realmadapter.RealmAdapter.run(RealmAdapter.java:44)
    at org.eclipse.rap.ui.internal.RealmAdapterHook.runWithDefault(RealmAdapterHook.java:48)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:427)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:157)
    at org.eclipse.example.library.presentation.LibraryEntryPoint.createUI(LibraryEntryPoint.java:19)
    at org.eclipse.rwt.internal.lifecycle.EntryPointManager.createUI(EntryPointManager.java:92)
    at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:244)
    at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:113)
    at java.lang.Thread.run(Thread.java:619)
    at org.eclipse.rwt.internal.lifecycle.UIThread.run(UIThread.java:102)



Reproducible: Always

Steps to Reproduce:
1. generate editor for the library model from http://wiki.eclipse.org/EMF_Editor_goes_RAP
2. launch the RAP, in the launch configuration>Runtime Settings, sett Session timeout to 20s.
3. after RAP start, create a model, and add few element, so that the icon image for model elements can be seen, and save model. This is to make sure the ExtendedImageRegistry is called.
4. leave the RAP alone for 20s, so that the session timeout.
5. restart the session, (open the model if necessay), then a dialog popup and show NullPointerException (see attached screenshot)
Comment 1 chengdong Mising name CLA 2010-08-24 12:54:57 EDT
Created attachment 177344 [details]
library model used as a test case.

attached the test case.
Comment 2 Kenn Hussey CLA 2010-08-24 15:32:27 EDT
Created attachment 177360 [details]
proposed changes

Please confirm whether these changes address the issue.
Comment 3 chengdong Mising name CLA 2010-08-24 23:35:42 EDT
Created attachment 177383 [details]
propsed patch for ExtendedImageRegistry

This is a proposed change for ExtendedImageRegistry. Similar changes should apply to ExtendedFontRegistry and ExtendedColorRegistry.
Comment 4 chengdong Mising name CLA 2010-08-24 23:41:06 EDT
Ken:

The patch you supplied does not fix the problem. Because the INSTANCE is immutable, it did not change between 2 sessions, but the table==null.

I propose to change the INSTANCE to mutable, so that when display is disposed, set INSTANCE to null, and recreate INSTANCE if necessary. See the previous attachement for ExtendedImageRegistry. Similar should apply to Font and Color registry.
Comment 5 chengdong Mising name CLA 2010-08-24 23:50:37 EDT
One more thing: we really should dispose the images when the display is disposed.

Does anyone know what prevent us from doing that?
Comment 6 Kenn Hussey CLA 2010-08-25 08:28:03 EDT
Created attachment 177409 [details]
better patch

Silly me. This patch should address the problem and also ensure safe/correct access to the (session-based) image registry via the static INSTANCE field. Similar changes also made to the font and color registries.
Comment 7 chengdong Mising name CLA 2010-08-25 12:43:16 EDT
Tested previous patch. And confirmed the bug is fixed. Thanks Kenn!
Comment 8 Kenn Hussey CLA 2010-08-25 14:42:52 EDT
The changes have been committed to HEAD and R2_6_maintenance streams.