Skip to main content



      Home
Home » Eclipse Projects » Sirius » NPE when creating DRepresentation(NPE when creating DRepresentation)
NPE when creating DRepresentation [message #1741479] Thu, 25 August 2016 09:36 Go to next message
Eclipse UserFriend
Hello,

I am currently developing an eclipse plugin whose purpose is to open a Sirius representation of a DSL file. If there is no aird file, or no existing representation of if, then it does what is needed to generate the diagram (creating the session, aird, representation, select viewpoint,...).
I have no problem with loading an existing representation, but I am struggling with creating a new one. Here is my code:
Collection<RepresentationDescription> descs = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), model);
for (RepresentationDescription desc : descs) {
	if (DialectManager.INSTANCE.canCreate(model, desc)) {
		rep = DialectManager.INSTANCE.createRepresentation(ifile.getParent().getFullPath().toString(), model, desc, session, new NullProgressMonitor());
		DialectUIManager.INSTANCE.openEditor(session, rep, new NullProgressMonitor());
		session.save(new NullProgressMonitor());
	}
}

The NPE is at the line
rep = DialectManager.INSTANCE.createRepresentation(ifile.getParent().getFullPath().toString(), model, desc, session, new NullProgressMonitor());

And the stack trace is:
java.lang.NullPointerException
	at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.getAllInitialyActiveLayers(DDiagramSynchronizer.java:301)
	at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.activateInitialLayers(DDiagramSynchronizer.java:283)
	at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.initDiagram(DDiagramSynchronizer.java:237)
	at org.eclipse.sirius.diagram.business.internal.sync.DDiagramSynchronizer.initDiagram(DDiagramSynchronizer.java:57)
	at org.eclipse.sirius.diagram.business.internal.dialect.DiagramDialectServices.createRepresentation(DiagramDialectServices.java:166)
	at org.eclipse.sirius.diagram.business.internal.dialect.DiagramDialectServices.createRepresentation(DiagramDialectServices.java:179)
	at org.eclipse.sirius.business.internal.dialect.DialectManagerImpl.createRepresentation(DialectManagerImpl.java:173)
	at org.eclipse.sirius.business.api.dialect.command.CreateRepresentationCommand.doExecute(CreateRepresentationCommand.java:117)
	at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
	at org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFCommandOperation.java:119)
	at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:516)
	at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:208)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)

I cannot debug directly the program since I an using Sirius as a plugin, so I took a look at the sources, but I found no reason to get this error. I think it might come from desc, but the only null parameter that does not seem normal is the "init" one: do someone know what it correspond to?
And if anyone have an idea concerning this error, I would appreciate some help Smile

Thank you,

Vincent

[Updated on: Fri, 26 August 2016 04:36] by Moderator

Re: NPE when creating DRepresentation [message #1741501 is a reply to message #1741479] Thu, 25 August 2016 10:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi Vincent,

Could you precise with which version of Sirius you see the NPE ?

Note that you can debug the Sirius code to identify the NPE cause, I see two options:

. if your have installed the sdk or the source plugins: just go the the eclipse preferences > Plug-in Development enable "Include all plug-ins from target in Java search". Then you can use CTRL/CMD+SHIFT+T to find the class and put your breakpoints.

. otherwise, just add the org.eclipse.sirius.diagram to one of your plugin project, and then form the corresponding item in the Plug-in Dependencies (displayed as children of the project in the Package Explorer view), you can use the "Import from Repository" wizard to import the source in your workspace. Please use the "import the indicated version" choice.

Regards

--
Maxime - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius


Re: NPE when creating DRepresentation [message #1741599 is a reply to message #1741501] Fri, 26 August 2016 04:45 Go to previous message
Eclipse UserFriend
Hi Maxime,

Thank you for taking the time to answer.
What I did is importing org.eclipse.sirius.diagram from Repository, but I have a problem with one of the import of DiagramDialectSelect:
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;

It makes it impossible to debug... I looked for this class, but I havent found it: is there anything I can do to get it? Or am I missing something?


EDIT: I finally got it to work! I looked at the sources again and realized that the session could be null too. So I tried to do
SessionManager.INSTANCE.getSession(resource)
with the resource I was using: the value was null. Then I tried with
Resource res = session.getSemanticResources().iterator().next();
as the parameter, and it now works perfectly.

Thank you for your help,
Keep up the good work on Sirius,

Vincent

[Updated on: Fri, 26 August 2016 05:10] by Moderator

Previous Topic:Properties tab refresh problem
Next Topic:Open diagram programmatically with custom input (no file)
Goto Forum:
  


Current Time: Mon Mar 17 07:54:18 EDT 2025

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

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

Back to the top