|
|
Re: NullPointerException when I create session using aird file [message #1847493 is a reply to message #1847476] |
Fri, 29 October 2021 03:02   |
Ts Bao Messages: 7 Registered: August 2021 |
Junior Member |
|
|
hi,Glenn Plouhinec. Appreciate your reply.
I printed my airduri, and the result was platform:/resource/LibraryMS/RequirementsModel/library.aird
I tried the code you provided
public void createSession(final URI sessionResourceURI) {
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
SessionCreationOperation sessionCreationOperation = new DefaultLocalSessionCreationOperation(sessionResourceURI, new NullProgressMonitor());
59 sessionCreationOperation.execute();
session = sessionCreationOperation.getCreatedSession();
// open UI session part
final IEditingSession editingSession = SessionUIManager.INSTANCE.getOrCreateUISession(session);
editingSession.open();
}
};
try {
operation.run(new NullProgressMonitor());
} catch (InvocationTargetException e) {
throw new RuntimeException("Impossible to create the session.", e.getCause());
} catch (InterruptedException e) {
throw new RuntimeException("Impossible to create the session.", e);
}
}
but I encountered almost the same problem.
Caused by: java.lang.NullPointerException
at org.eclipse.sirius.common.tools.api.resource.ResourceSetFactory.createFactory(ResourceSetFactory.java:77)
at org.eclipse.sirius.business.internal.session.SessionFactoryImpl.prepareEditingDomain(SessionFactoryImpl.java:113)
at org.eclipse.sirius.business.internal.session.SessionFactoryImpl.createSession(SessionFactoryImpl.java:82)
at org.eclipse.sirius.business.api.session.DefaultLocalSessionCreationOperation.execute(DefaultLocalSessionCreationOperation.java:71)
at utils.GenreateImages$1.execute(GenreateImages.java:59)
the code of org.eclipse.sirius.business.internal.session.SessionFactoryImpl.createSession is
public Session createSession(final URI sessionResourceURI, IProgressMonitor monitor) throws CoreException {
82 final TransactionalEditingDomain ted = prepareEditingDomain(sessionResourceURI);
boolean alreadyExistingResource = ted.getResourceSet().getURIConverter().exists(sessionResourceURI, null);
Session session = null;
if (alreadyExistingResource) {
session = loadSessionModelResource(sessionResourceURI, ted, monitor);
} else {
session = createSessionResource(sessionResourceURI, ted, true, monitor);
}
return session;
}
the code of at org.eclipse.sirius.business.internal.session.SessionFactoryImpl.prepareEditingDomain is
protected final TransactionalEditingDomain prepareEditingDomain(final URI sessionResourceURI) {
113 ResourceSet set = ResourceSetFactory.createFactory().createResourceSet(sessionResourceURI);
final TransactionalEditingDomain transactionalEditingDomain = EditingDomainFactoryService.INSTANCE.getEditingDomainFactory().createEditingDomain(set);
// Configure the resource set, its is done here and not before the
// editing domain creation which could provide its own resource set.
set = transactionalEditingDomain.getResourceSet();
set.getLoadOptions().put(DescriptionResourceImpl.OPTION_USE_URI_FRAGMENT_AS_ID, true);
configureDomain(transactionalEditingDomain, sessionResourceURI);
return transactionalEditingDomain;
}
I still don't know where I made a mistake. How should I correct it?
Regards
|
|
|
Re: NullPointerException when I create session using aird file [message #1847496 is a reply to message #1847493] |
Fri, 29 October 2021 07:40   |
|
Hi,
The line where the NPE occurs according to the stack trace (ResourceSetFactory.java:77) is:
} catch (final ClassCastException e) {
DslCommonPlugin.getDefault().error(MessageFormat.format(Messages.ResourceSetFactory_creationError, configElement.getAttribute(CLASS_ATTRIBUTE)), e);
}
It's very strange something can be null here, unless maybe we are very early during the platform startup and some things are not yet completely initialized.
Whatever the cause of the NPE is here, this line is only executed at all if a ClassCastException has been thrown earlier, which can only happen at
ResourceSetFactory contributed = (ResourceSetFactory) configElement.createExecutableExtension(CLASS_ATTRIBUTE);
I don't know if it makes sense in your context, but from the information we have it looks like:
- you (on someone/something in your execution context) registered a custom ResourceSetFactory using the org.eclipse.sirius.common.resourceSetFactory extension point, but the class provided is not a subclass of org.eclipse.sirius.common.tools.api.resource.ResourceSetFactory.
- for some reason, the error handling code which is supposed to report this error fails itself with an NPE.
Really the best way to debug this is for you to put a breakpoint on ResourceSetFactory.java:77, trigger the bug and then:
- inspect the ClassCastException to see what it the root issue;
- find out which part of the line in question is null and triggers the NPE, and report that here so we can understand (and fix) it.
Regards,
Pierre-Charles David
Pierre-Charles David - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Powered by
FUDForum. Page generated in 0.02080 seconds