Bug 506997 - [Navigation] BadStateException in Model Explorer context menu
Summary: [Navigation] BadStateException in Model Explorer context menu
Status: NEW
Alias: None
Product: Papyrus
Classification: Modeling
Component: Others (show other bugs)
Version: 2.0.2   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-03 14:54 EDT by Christian Damus CLA
Modified: 2017-03-02 13:07 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Damus CLA 2016-11-03 14:54:35 EDT
Papyrus Neon.2 build 201610290302
Papyrus Oxygen build 201611020128

This may be related to bug 494298, but the exception is different, so I don't know.

The dynamic navigation menu in the Model Explorer context menu attempts to access the ViewerSearchService in a ServicesRegistry that is not yet started, which raises an exception, in the case that the Papyrus editor has not had any embedded diagram editors open.

Steps to reproduce:

1.  Create a new model.  **Do not** create any diagram in this model.
2.  In the Model Explorer, right-click on the root (only) model element and
    expand the 'Navigate' sub-menu.
3.  Observe the exception below, in the log.
4.  Repeat steps 2 and 3 a few times; the exception occurs every time.
5.  Now create and open a diagram.
6.  Invoke the Model Explorer navigation context menu again.  No exception.
7.  Close the diagram.
8.  Invoke the Model Explorer navigation context menu again.  No exception.
9.  Close the whole Papyrus editor and open it again.  Make sure that the diagram
    is not opened.
10. Invoke the Model Explorer navigation context menu again.  See the exception.

-------- 8< --------

!ENTRY org.eclipse.papyrus.infra.gmfdiag.navigation 4 0 2016-11-03 14:39:10.260
!MESSAGE Unexpected Error
!STACK 0
org.eclipse.papyrus.infra.core.services.BadStateException: Registry should be started before. (Service= 'org.eclipse.papyrus.infra.services.viewersearch.impl.ViewerSearchService', state= registered)
	at org.eclipse.papyrus.infra.core.services.ServicesRegistry.getService(ServicesRegistry.java:406)
	at org.eclipse.papyrus.infra.core.utils.AbstractServiceUtils.getService(AbstractServiceUtils.java:117)
	at org.eclipse.papyrus.infra.gmfdiag.navigation.ui.DynamicNavigate.getViewsToSelect(DynamicNavigate.java:120)
	at org.eclipse.papyrus.infra.gmfdiag.navigation.ui.ModelExplorerDynamicNavigate.fill(ModelExplorerDynamicNavigate.java:50)
	at org.eclipse.ui.internal.menus.DynamicMenuContributionItem.fill(DynamicMenuContributionItem.java:147)
	at org.eclipse.jface.action.MenuManager.doItemFill(MenuManager.java:728)
	at org.eclipse.jface.action.MenuManager.update(MenuManager.java:810)
	at org.eclipse.jface.action.MenuManager.handleAboutToShow(MenuManager.java:472)
	at org.eclipse.jface.action.MenuManager.access$1(MenuManager.java:465)
	at org.eclipse.jface.action.MenuManager$2.menuShown(MenuManager.java:497)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:256)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4248)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1501)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1505)
	at org.eclipse.swt.widgets.Menu.menuWillOpen(Menu.java:805)
	at ...
Comment 1 Johan Van Noten CLA 2017-01-04 08:08:24 EST
Environment: Today's Neon.2, Papyrus Nightly, SysML Nightly

We observe the same issue when accessing the ServiceRegistry from a custom validation that accesses the ServiceRegistry for a validation that checks whether an element is shown on any diagram at all. This validation is also launched from the Model Explorer context menu, but I can't confirm that it wouldn't occur if we triggered it differently.

For us, this causes the following top of the stacktrace.
We didn't see this occurring in our pre-Neon.2 environment.

org.eclipse.papyrus.infra.core.services.BadStateException: Registry should be started before. (Service= 'org.eclipse.papyrus.infra.services.viewersearch.impl.ViewerSearchService', state= registered)
	at org.eclipse.papyrus.infra.core.services.ServicesRegistry.getService(ServicesRegistry.java:406)
	at org.eclipse.papyrus.infra.core.utils.AbstractServiceUtils.getService(AbstractServiceUtils.java:117)
	at be.flandersmake.mbse.fmsyseng.support.architecturevalidation.DiagramData.getViewsToSelect(DiagramData.java:190)
	at be.flandersmake.mbse.fmsyseng.support.architecturevalidation.DiagramData.occursInDiagrams(DiagramData.java:150)
	at be.flandersmake.mbse.fmsyseng.support.architecturevalidation.AVR_CP_PartsVisibleOnMin1Diagram.validate(AVR_CP_PartsVisibleOnMin1Diagram.java:62)

In addition to our specific scenario, we can also confirm the issue as described by Christian (so, without our customization).
Comment 2 Johan Van Noten CLA 2017-01-06 08:54:03 EST
I consider this issue to be high-priority.
It disables an important new Neon feature: navigation to diagrams.

* Right-click on any model element in the Model explorer
* Select navigate 
* --> Exception occurs
* Only navigation to occurrences in the Model Explorer remain, no diagram navigation possible anymore.

Additionally, this issue disables a significant amount of our validations since we can't programmatically search elements in the diagrams anymore. Is there an intermediary workaround to programatically start the ServiceRegistry?
Comment 3 Benoit Maggi CLA 2017-01-10 10:33:01 EST
@Johan:
You may try ServiceUtils.getInstance().getServiceRegistry(null).startRegistry() 
(there are other methods that check what is started or not)


but honestly I don't know what is expected by this kind of code:

public <S> S getService(Class<S> key) throws ServiceException {
	String realKey = key.getName();
	ServiceStartupEntry service = namedServices.get(realKey);
	if (service == null) {
		// throw an exception.
		// If added, say it.
		service = addedServices.get(realKey);
if (service != null) {
    throw new BadStateException("Registry should be started before.", service.getState(), service.getDescriptor());
} else {
    throw new ServiceNotFoundException("No service registered under '" + key + "'");
		}
}
return (S) service.getServiceInstance();
}
Comment 4 Johan Van Noten CLA 2017-01-10 10:42:25 EST
@Benoit: I agree with your statement... code/mechanism was very intransparent to me as well. Who knows (or should know) its background?

Anyway, your suggested workaround seems to avoid the issue, but I don't know what I'm doing and whether this is legal/expected/safe/... :-)

Thanks for the workaround.
Comment 5 Johan Van Noten CLA 2017-01-10 10:47:49 EST
By the way: the workaround of course only applies to my customized validations (since there I have to opportunity to start the ServiceRegistry).

All "normal Neon.2 users" are still stuck with a defective "Navigate to diagram" functionality.
Comment 6 Benoit Maggi CLA 2017-01-10 11:06:19 EST
@Johan: glad you make it works.

I don't have any background on this part, it probably need a little refactor but we need  to be careful since it's the center of all services.

And yes the navigation is still defective in Neon.2
I add Shuai that may have a idea on the navigation problem.
Comment 7 Johan Van Noten CLA 2017-03-02 13:07:44 EST
Guys, can this be raised to major and platform independent? 
We can't allow a feature as essential as "Navigate to diagram" to remain disabled in Neon and Oxygen!