Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345870

Summary: AbstractFeatureProvider.link(PictogramElement pictogramElement, Object[] businessObjects) should check Business Object's eResource is not null
Product: [Modeling] Graphiti Reporter: M <cofiem>
Component: CoreAssignee: Tim Kaiser <tim.kaiser>
Status: CLOSED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: michael.wenz
Version: 0.8.0Flags: tim.kaiser: indigo+
Target Milestone: 0.8.0   
Hardware: All   
OS: All   
Whiteboard: Indigo RC1 theme_bugs
Attachments:
Description Flags
mylyn/context/zip none

Description M CLA 2011-05-16 00:51:24 EDT
Build Identifier: 20110319-2305

AbstractFeatureProvider.link(PictogramElement pictogramElement, Object[] businessObjects) should check that Business Object's .eResource() and .getResourceSet() are not null before using.

If something is null, throw a descriptive exception (message e.g.: The business object's resource/resourceset must be set before it is linked to the pictogram.)

Whenever I forget to set the resource, I spend a few minutes tracking down a generic NullPointerException, only to find that this is the issue.

Reproducible: Always

Steps to Reproduce:
1. In a AbstractCreateConnectionFeature in Graphiti using emf model
2. create a new emf business model object, do not link it to the resourceset
3. in create method override, call IFeatureProvider.addIfPossible
4. NullPointerException occurs:

!ENTRY org.eclipse.graphiti 4 0 2011-05-16 14:28:39.462
!MESSAGE CommandExec.executeCommand() java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException
at org.eclipse.graphiti.features.impl.AbstractFeatureProvider.link(AbstractFeatureProvider.java:639)
	at org.eclipse.graphiti.features.impl.AbstractFeature.link(AbstractFeature.java:205)
	at org.eclipse.graphiti.features.impl.AbstractFeature.link(AbstractFeature.java:193)
	at mypackage.AddConnectionFeature.add(AddConnectionFeature.java:43)
	at org.eclipse.graphiti.internal.command.AddFeatureCommandWithContext.execute(AddFeatureCommandWithContext.java:76)
	at org.eclipse.graphiti.internal.command.GFPreparableCommand.doExecute(GFPreparableCommand.java:37)
	at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
	at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandStackImpl.execute(GFWorkspaceCommandStackImpl.java:52)
	at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
	at org.eclipse.graphiti.ui.internal.editor.GFWorkspaceCommandStackImpl.execute(GFWorkspaceCommandStackImpl.java:39)
	at org.eclipse.graphiti.internal.command.CommandExec.executeCommand(CommandExec.java:74)
	at org.eclipse.graphiti.features.impl.AbstractFeatureProvider.addIfPossible(AbstractFeatureProvider.java:338)
	at mypackage.CreateConnectionFeature.create(CreateConnectionFeature.java:86)
Comment 1 Tim Kaiser CLA 2011-05-17 08:09:53 EDT
Created attachment 195842 [details]
mylyn/context/zip
Comment 2 Tim Kaiser CLA 2011-05-17 08:13:58 EDT
eclipse runtime assertions added, runtime exception with descriptive message will be thrown
Comment 3 Michael Wenz CLA 2011-06-24 08:45:04 EDT
Part of Graphiti Indigo 0.8.0