Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Barbin2016-01-22 09:31:26 +0000
committerFlorian Barbin2016-01-28 12:46:50 +0000
commitd4ce5d750def671d3cee2de9ca410a1dc271bc32 (patch)
treec8d7e38df335cf71881d094c7fde9f64db411d27
parent90f24477547fbb8c6920be3a9153ab5c3b45f8bb (diff)
downloadorg.eclipse.sirius-d4ce5d750def671d3cee2de9ca410a1dc271bc32.tar.gz
org.eclipse.sirius-d4ce5d750def671d3cee2de9ca410a1dc271bc32.tar.xz
org.eclipse.sirius-d4ce5d750def671d3cee2de9ca410a1dc271bc32.zip
[484544] Avoid NPE in the traceability marker navigation.
* If a semantic element didn't have a representation element, a NPE can occurs. * When trying to retrieve the REPRESENTATION_ELEMENT_ID, all current editors set a default value to null when retrieving it (if not found), and check that the value is not null. If REPRESENTATION_ELEMENT_ID is not set, it should not lead to an other NPE. Bug: 484544 Change-Id: I9d31afc4b3b277619701ca15723485f78896ebb9 Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/marker/TraceabilityMarkerNavigationProvider.java71
1 files changed, 40 insertions, 31 deletions
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/marker/TraceabilityMarkerNavigationProvider.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/marker/TraceabilityMarkerNavigationProvider.java
index 675332539a..9112ec76c8 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/marker/TraceabilityMarkerNavigationProvider.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/dialect/marker/TraceabilityMarkerNavigationProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011, 2015 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2010, 2016 THALES GLOBAL SERVICES and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -63,8 +63,7 @@ import com.google.common.collect.Sets;
* </p>
* *
* <ul>
- * <li>
- * If the opened representation is representing S1 in some way, the element
+ * <li>If the opened representation is representing S1 in some way, the element
* representing S1 should be revealed and selected</li>
* <li>If the opened representation is not representing S1, the code should look
* through the representations opened for this session and find one representing
@@ -190,9 +189,8 @@ public class TraceabilityMarkerNavigationProvider implements IGotoMarker {
* </p>
* *
* <ul>
- * <li>
- * If the opened representation is representing S1 in some way, the element
- * representing S1 should be revealed and selected</li>
+ * <li>If the opened representation is representing S1 in some way, the
+ * element representing S1 should be revealed and selected</li>
* <li>If the opened representation is not representing S1, the code should
* look through the representations opened for this session and find one
* representing S1. If one if found, it should call the goToMarker method on
@@ -334,7 +332,9 @@ public class TraceabilityMarkerNavigationProvider implements IGotoMarker {
}
}
- /* If the searched semantic element has been found in the given editor */
+ /*
+ * If the searched semantic element has been found in the given editor
+ */
if (foundEditor) {
editorToFocus = editor;
representationToFocus = editor.getRepresentation();
@@ -385,28 +385,37 @@ public class TraceabilityMarkerNavigationProvider implements IGotoMarker {
res = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformResourceString));
}
}
-
- IMarker shadowMarker = null;
- try {
- shadowMarker = res.createMarker(marker.getType());
- shadowMarker.setAttribute(TraceabilityMarkerNavigationProvider.TRACEABILITY_SEMANTIC_ELEMENT_URI_ATTRIBUTE, EcoreUtil.getURI(this.representationToFocus).toString());
- shadowMarker.setAttribute(TraceabilityMarkerNavigationProvider.REPRESENTATION_ELEMENT_ID, resource.getURIFragment(representationElementToSelect).toString());
- shadowMarker.setAttribute(TraceabilityMarkerNavigationProvider.REPRESENTATION_URI, EcoreUtil.getURI(this.representationToFocus).toString());
- shadowMarker.setAttribute(TraceabilityMarkerNavigationProvider.TRACEABILITY_INTERNAL_ATTRIBUTE, "active"); //$NON-NLS-1$
-
- // Step 2 : we sets the focus on the editor and call the goToMarker
- // method on it
- editorToFocus.setFocus();
- editorToFocus.gotoMarker(shadowMarker);
-
- } catch (CoreException e) {
- // Nothing to do, goToMarker will fail.
- } finally {
- if (shadowMarker != null) {
- try {
- shadowMarker.delete();
- } catch (CoreException e) {
- // Nothing to do, goToMarker will fail.
+ // If we can't retrieve the resource, there is nothing to do.
+ if (res != null) {
+ IMarker shadowMarker = null;
+ try {
+ shadowMarker = res.createMarker(marker.getType());
+ shadowMarker.setAttribute(TraceabilityMarkerNavigationProvider.TRACEABILITY_SEMANTIC_ELEMENT_URI_ATTRIBUTE, EcoreUtil.getURI(this.representationToFocus).toString());
+
+ // If there is no corresponding representation element we do not
+ // set
+ // the REPRESENTATION_ELEMENT_ID.
+ if (representationElementToSelect != null) {
+ shadowMarker.setAttribute(TraceabilityMarkerNavigationProvider.REPRESENTATION_ELEMENT_ID, resource.getURIFragment(representationElementToSelect).toString());
+ }
+ shadowMarker.setAttribute(TraceabilityMarkerNavigationProvider.REPRESENTATION_URI, EcoreUtil.getURI(this.representationToFocus).toString());
+ shadowMarker.setAttribute(TraceabilityMarkerNavigationProvider.TRACEABILITY_INTERNAL_ATTRIBUTE, "active"); //$NON-NLS-1$
+
+ // Step 2 : we sets the focus on the editor and call the
+ // goToMarker
+ // method on it
+ editorToFocus.setFocus();
+ editorToFocus.gotoMarker(shadowMarker);
+
+ } catch (CoreException e) {
+ // Nothing to do, goToMarker will fail.
+ } finally {
+ if (shadowMarker != null) {
+ try {
+ shadowMarker.delete();
+ } catch (CoreException e) {
+ // Nothing to do, goToMarker will fail.
+ }
}
}
}
@@ -578,8 +587,8 @@ public class TraceabilityMarkerNavigationProvider implements IGotoMarker {
* the content provider to evaluate the tree structure
*/
public RepresentationToOpenDialog(Shell parent, Session session, Set<DRepresentation> candidateRepresentations, EObject semanticElement) {
- super(parent, new SessionLabelProvider(ViewHelper.INSTANCE.createAdapterFactory()), new CandidateRepresentationContentProvider(ViewHelper.INSTANCE.createAdapterFactory(),
- candidateRepresentations, session));
+ super(parent, new SessionLabelProvider(ViewHelper.INSTANCE.createAdapterFactory()),
+ new CandidateRepresentationContentProvider(ViewHelper.INSTANCE.createAdapterFactory(), candidateRepresentations, session));
SessionLabelProvider labelProvider = new SessionLabelProvider(ViewHelper.INSTANCE.createAdapterFactory());
String objectName = labelProvider.getText(semanticElement);
setTitle(MessageFormat.format(Messages.TraceabilityMarkerNavigationProvider_dialogTitle, objectName));

Back to the top