[CDO] NPE in CDOResourceImpl.basicSetResource [message #1121603] |
Mon, 30 September 2013 20:05 |
Laurent Le Moux Messages: 184 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 |
|
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
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
|
|
Re: [CDO] NPE in CDOResourceImpl.basicSetResource [message #1122194 is a reply to message #1122160] |
Tue, 01 October 2013 10:13 |
|
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.
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
Powered by
FUDForum. Page generated in 0.03838 seconds