Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] NPE in CDOResourceImpl.basicSetResource(occurs in my CDO TED when exiting my RCP application)
[CDO] NPE in CDOResourceImpl.basicSetResource [message #1121603] Mon, 30 September 2013 20:05 Go to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 153
Registered: September 2011
Senior Member
Hi all,

I try to build a simple modeler example based an Graphiti with CDO as backend storage.
To achieve this, I followed some topics and the Dawn example.
I now have a CDO transactional editing domain (TED) which works fine until I quit my RCP application.

I then get a NullPointerException in CDOResourceImpl.basicSetResource because of CDOUtil.getViewSet(oldResourceSet) returning null in CDO code.

Adding a "dummy" adapter as follow solves the problem but I don't know why it happens.

@SuppressWarnings("restriction")
public class CDOTransactionalEditingDomainImpl extends TransactionalEditingDomainImpl {

	public static String CDO_TED_ID = "myappsmodeler.CDOEditingDomain";
	
	public CDOTransactionalEditingDomainImpl(AdapterFactory adapterFactory, TransactionalCommandStack stack, ResourceSet resourceSet) {
		super(adapterFactory, stack, resourceSet);
	}

	@Override
	protected TransactionChangeRecorder createChangeRecorder(ResourceSet rset)
	{
		return new TransactionChangeRecorder(this, rset) {
			  @Override
			  public void notifyChanged(Notification notification)
			  {
			    if (!(notification.getOldValue() instanceof ResourceSet && notification.getNewValue() == null && notification
			        .getEventType() == Notification.SET))
			    {
			      if (!(notification instanceof CDODeltaNotification))
			      {
			        super.notifyChanged(notification);
			      }
			    }
			  }			
		};
	}
	
	public static class CDOFactoryImpl extends FactoryImpl {
		@Override
		public synchronized TransactionalEditingDomain createEditingDomain() {

			final ResourceSet resourceSet = new ResourceSetImpl();
			
			resourceSet.eAdapters().add(new InternalCDOViewSet() {
				
				// Dummy adapter used when exiting the modeler to avoid a NPE in CDOResourceImpl.basicSetResource
				// because of CDOUtil.getViewSet(oldResourceSet) returning null...
				@Override
				public CDOView[] getViews() { return null; }

				@Override
				public CDOResourceFactory getResourceFactory() { return null; }

				@Override
				public org.eclipse.emf.ecore.EPackage.Registry getPackageRegistry() { return null; }

				@Override
				public ResourceSet getResourceSet() { return null; }

				@Override
				public EList<Adapter> eAdapters() { return null; }

				@Override
				public boolean eDeliver() { return false; }

				@Override
				public void eSetDeliver(boolean deliver) {}

				@Override
				public void eNotify(Notification notification) {}

				@Override
				public void notifyChanged(Notification notification) {}

				@Override
				public Notifier getTarget() { return null; }

				@Override
				public void setTarget(Notifier newTarget) {}

				@Override
				public boolean isAdapterForType(Object type) { return false; }

				@Override
				public void add(InternalCDOView view) {}

				@Override
				public void remove(InternalCDOView view) {}

				@Override
				public InternalCDOView resolveView(String repositoryUUID) { return null; }

				@Override
				public <V> V executeWithoutNotificationHandling(Callable<V> callable) { return null; }
			});

			final IWorkspaceCommandStack workspaceCommandStack = new GFWorkspaceCommandStackImpl(new DefaultOperationHistory());
			TransactionalEditingDomain result = new CDOTransactionalEditingDomainImpl(
				new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE),
				workspaceCommandStack, resourceSet);
			
			mapResourceSet(result);
			
			return result;
		}
	}
}


Could somebody tell me what's wrong ?

Kind regards,

Laurent
Re: [CDO] NPE in CDOResourceImpl.basicSetResource [message #1121982 is a reply to message #1121603] Tue, 01 October 2013 05:47 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5523
Registered: July 2009
Senior Member
Hi Laurent,

Some aspects of your problem are unclear to me:

1) Are you actually using Dawn or have you just been inspired by Dawn example code?
2) What's the stack trace of your NPE and what version of CDO are you using?
3) CDOTransactionalEditingDomainImpl and CDOFactoryImpl (the one below) are your own code?

Perhaps you can write a simple test case to demo your problem. Here are examples that use TransactionalEditingDomains:

Bugzilla_362270_Test.java - org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla (3 matches)
Bugzilla_362270c_Test.java - org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla (3 matches)
Bugzilla_417483_Test.java - org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla (7 matches)

If your test reveals a problem in CDO please submit a bugzilla and attach the test case and resulting stack traces to
it. Then I might be able to CC/assign some people who are more experienced with TransactionalEditingDomains.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Am 30.09.2013 22:05, schrieb Laurent Le Moux:
> Hi all,
>
> I try to build a simple modeler example based an Graphiti with CDO as backend storage.
> To achieve this, I followed some topics and the Dawn example.
> I now have a CDO transactional editing domain (TED) which works fine until I quit my RCP application.
>
> I then get a NullPointerException in CDOResourceImpl.basicSetResource because of CDOUtil.getViewSet(oldResourceSet)
> returning null in CDO code.
>
> Adding a "dummy" adapter as follow solves the problem but I don't know why it happens.
>
>
> @SuppressWarnings("restriction")
> public class CDOTransactionalEditingDomainImpl extends TransactionalEditingDomainImpl {
>
> public static String CDO_TED_ID = "myappsmodeler.CDOEditingDomain";
>
> public CDOTransactionalEditingDomainImpl(AdapterFactory adapterFactory, TransactionalCommandStack stack,
> ResourceSet resourceSet) {
> super(adapterFactory, stack, resourceSet);
> }
>
> @Override
> protected TransactionChangeRecorder createChangeRecorder(ResourceSet rset)
> {
> return new TransactionChangeRecorder(this, rset) {
> @Override
> public void notifyChanged(Notification notification)
> {
> if (!(notification.getOldValue() instanceof ResourceSet && notification.getNewValue() == null &&
> notification
> .getEventType() == Notification.SET))
> {
> if (!(notification instanceof CDODeltaNotification))
> {
> super.notifyChanged(notification);
> }
> }
> }
> };
> }
>
> public static class CDOFactoryImpl extends FactoryImpl {
> @Override
> public synchronized TransactionalEditingDomain createEditingDomain() {
>
> final ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.eAdapters().add(new InternalCDOViewSet() {
>
> // Dummy adapter used when exiting the modeler to avoid a NPE in CDOResourceImpl.basicSetResource
> // because of CDOUtil.getViewSet(oldResourceSet) returning null...
> @Override
> public CDOView[] getViews() { return null; }
>
> @Override
> public CDOResourceFactory getResourceFactory() { return null; }
>
> @Override
> public org.eclipse.emf.ecore.EPackage.Registry getPackageRegistry() { return null; }
>
> @Override
> public ResourceSet getResourceSet() { return null; }
>
> @Override
> public EList<Adapter> eAdapters() { return null; }
>
> @Override
> public boolean eDeliver() { return false; }
>
> @Override
> public void eSetDeliver(boolean deliver) {}
>
> @Override
> public void eNotify(Notification notification) {}
>
> @Override
> public void notifyChanged(Notification notification) {}
>
> @Override
> public Notifier getTarget() { return null; }
>
> @Override
> public void setTarget(Notifier newTarget) {}
>
> @Override
> public boolean isAdapterForType(Object type) { return false; }
>
> @Override
> public void add(InternalCDOView view) {}
>
> @Override
> public void remove(InternalCDOView view) {}
>
> @Override
> public InternalCDOView resolveView(String repositoryUUID) { return null; }
>
> @Override
> public <V> V executeWithoutNotificationHandling(Callable<V> callable) { return null; }
> });
>
> final IWorkspaceCommandStack workspaceCommandStack = new GFWorkspaceCommandStackImpl(new
> DefaultOperationHistory());
> TransactionalEditingDomain result = new CDOTransactionalEditingDomainImpl(
> new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE),
> workspaceCommandStack, resourceSet);
>
> mapResourceSet(result);
>
> return result;
> }
> }
> }
>
>
> Could somebody tell me what's wrong ?
>
> Kind regards,
>
> Laurent
Re: [CDO] NPE in CDOResourceImpl.basicSetResource [message #1122048 is a reply to message #1121982] Tue, 01 October 2013 07:19 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 153
Registered: September 2011
Senior Member
Hello Eike,

Thanks for your quick answer.
My code is inspired by Dawn code and a few things I read in the forum.
I'm using CDO 4.2.0 and here's the stack trace :
!ENTRY org.eclipse.net4j.util 0 0 2013-10-01 09:11:58.408
!MESSAGE Problem while deactivating Transaction 1 [MAIN]
!STACK 0
java.lang.NullPointerException
	at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.basicSetResourceSet(CDOResourceImpl.java:1488)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$ResourcesEList.inverseRemove(ResourceSetImpl.java:604)
	at org.eclipse.emf.common.notify.impl.NotifyingListImpl.removeAll(NotifyingListImpl.java:945)
	at org.eclipse.emf.internal.cdo.view.CDOViewSetImpl.remove(CDOViewSetImpl.java:184)
	at org.eclipse.emf.internal.cdo.view.CDOViewImpl.doBeforeDeactivate(CDOViewImpl.java:1179)
	at org.eclipse.net4j.util.lifecycle.Lifecycle.internalDeactivate(Lifecycle.java:121)
	at org.eclipse.net4j.util.lifecycle.Lifecycle.deactivate(Lifecycle.java:167)
	at org.eclipse.net4j.util.lifecycle.LifecycleUtil.deactivate(LifecycleUtil.java:221)
	at org.eclipse.net4j.util.lifecycle.LifecycleUtil.deactivate(LifecycleUtil.java:211)
	at org.eclipse.net4j.util.lifecycle.LifecycleUtil.deactivate(LifecycleUtil.java:237)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.close(AbstractCDOView.java:1526)
	at myappsmodeler.ApplicationWorkbenchAdvisor.postShutdown(ApplicationWorkbenchAdvisor.java:84)
	at org.eclipse.ui.internal.Workbench.shutdown(Workbench.java:2884)
	at org.eclipse.ui.internal.Workbench.busyClose(Workbench.java:1108)
	at org.eclipse.ui.internal.Workbench.access$19(Workbench.java:1024)
	at org.eclipse.ui.internal.Workbench$19.run(Workbench.java:1327)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.Workbench.close(Workbench.java:1325)
	at org.eclipse.ui.internal.Workbench.close(Workbench.java:1298)
	at org.eclipse.ui.internal.WorkbenchWindow.busyClose(WorkbenchWindow.java:1227)
	at org.eclipse.ui.internal.WorkbenchWindow.access$14(WorkbenchWindow.java:1198)
	at org.eclipse.ui.internal.WorkbenchWindow$10.run(WorkbenchWindow.java:1261)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.WorkbenchWindow.close(WorkbenchWindow.java:1259)
	at org.eclipse.ui.internal.WorkbenchWindow.close(WorkbenchWindow.java:1271)
	at myappsmodeler.handlers.QuitHandler.execute(QuitHandler.java:14)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:224)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:167)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:213)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:285)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:504)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:555)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:376)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$0(KeyBindingDispatcher.java:322)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:84)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1056)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1081)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1108)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1104)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1525)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4723)
	at org.eclipse.swt.widgets.Tree.WM_CHAR(Tree.java:6009)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4611)
	at org.eclipse.swt.widgets.Tree.windowProc(Tree.java:6005)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4990)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2549)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:610)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
	at myappsmodeler.Application.start(Application.java:20)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1426)


And yes, CDOTransactionalEditingDomainImpl and CDOFactoryImpl are my own code.

I'll have a look to your examples and see if I can write a simple test to reproduce my problem.
Re: [CDO] NPE in CDOResourceImpl.basicSetResource [message #1122120 is a reply to message #1122048] Tue, 01 October 2013 08:46 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5523
Registered: July 2009
Senior Member
Am 01.10.2013 09:19, schrieb Laurent Le Moux:
> Hello Eike,
>
> Thanks for your quick answer.
> My code is inspired by Dawn code and a few things I read in the forum.
> I'm using CDO 4.2.0 and here's the stack trace :
>
> !ENTRY org.eclipse.net4j.util 0 0 2013-10-01 09:11:58.408
> !MESSAGE Problem while deactivating Transaction 1 [MAIN]
> !STACK 0
> java.lang.NullPointerException
> at org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl.basicSetResourceSet(CDOResourceImpl.java:1488)
The line number does no longer match the code. Can you update to 4.2 SR1, which we've published yesterday?

http://www.eclipse.org/cdo/downloads/

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: [CDO] NPE in CDOResourceImpl.basicSetResource [message #1122160 is a reply to message #1122120] Tue, 01 October 2013 09:30 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 153
Registered: September 2011
Senior Member
Eike,

Here's a simple test reproducing the error.
After starting the example, simply quit. It should trigger the exception.

ApplicationWorkbenchAdvisor#preStartup opens a transaction, creates a resource and adds it to the TED.

ApplicationWorkbenchAdvisor#postShutdown closes the transaction which leads to the exception.
Re: [CDO] NPE in CDOResourceImpl.basicSetResource [message #1122194 is a reply to message #1122160] Tue, 01 October 2013 10:13 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5523
Registered: July 2009
Senior Member
Hi Laurent,

The cause of the problem is in your preStartup() method:

transaction = session.openTransaction();

// Access the resource once it's under CDO TED control
TransactionalEditingDomain editingDomain =
TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(CDOTransactionalEditingDomainImpl.CDO_TED_ID);
res = transaction.getOrCreateResource("TestCDOTED");
editingDomain.getResourceSet().getResources().add(res);

Which should be:

// Access the resource once it's under CDO TED control
TransactionalEditingDomain editingDomain =
TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain(CDOTransactionalEditingDomainImpl.CDO_TED_ID);

transaction = session.openTransaction(editingDomain.getResourceSet());
res = transaction.getOrCreateResource("TestCDOTED");

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Am 01.10.2013 11:30, schrieb Laurent Le Moux:
> Eike,
>
> Here's a simple test reproducing the error.
> After starting the example, simply quit. It should trigger the exception.
>
> ApplicationWorkbenchAdvisor#preStartup opens a transaction, creates a resource and adds it to the TED.
>
> ApplicationWorkbenchAdvisor#postShutdown closes the transaction which leads to the exception.
Re: [CDO] NPE in CDOResourceImpl.basicSetResource [message #1122345 is a reply to message #1122194] Tue, 01 October 2013 13:19 Go to previous message
Laurent Le Moux is currently offline Laurent Le Moux
Messages: 153
Registered: September 2011
Senior Member
Hi Eike,

It indeed solves my problem...but I'm now facing another issue :
java.lang.IllegalStateException: Different object was registered for OID681
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.registerObject(AbstractCDOView.java:1324)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:923)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.getObject(CDOTransactionImpl.java:1150)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.convertIDToObject(AbstractCDOView.java:1255)
	at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertIDToObject(CDOStoreImpl.java:691)
	at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.convertToEMF(CDOStoreImpl.java:659)
	at org.eclipse.emf.internal.cdo.view.CDOStoreImpl.get(CDOStoreImpl.java:191)
	at org.eclipse.emf.ecore.impl.EStoreEObjectImpl$BasicEStoreEList.delegateGet(EStoreEObjectImpl.java:241)
	at org.eclipse.emf.common.util.DelegatingEList.get(DelegatingEList.java:230)
	at org.eclipse.emf.ecore.util.DelegatingEcoreEList.toArray(DelegatingEcoreEList.java:335)


This seems to be a known problem :
http://www.eclipse.org/forums/index.php/t/369768/
https://bugs.eclipse.org/bugs/show_bug.cgi?id=399956

Unless you can suggest me a better solution, I'll stick to my "workaround" until the bug is adressed in 4.3.

Cheers,

Laurent
Previous Topic:[Teneo] DB Keywords not always escapes
Next Topic:EMF generating compile errors with enums
Goto Forum:
  


Current Time: Thu Sep 18 09:49:06 GMT 2014

Powered by FUDForum. Page generated in 0.01898 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software