diff options
author | Benoit Maggi | 2018-07-02 09:22:35 +0000 |
---|---|---|
committer | Benoit Maggi | 2018-07-02 13:30:54 +0000 |
commit | e9c6b1b23e75a5572c2083b1aa3e00c42daaea95 (patch) | |
tree | 01af9d23b826bbec9b358deb4ff63790c7b04f42 /plugins/infra | |
parent | 6a380916aed9be05f2a114cb98a0977b69d02742 (diff) | |
download | org.eclipse.papyrus-e9c6b1b23e75a5572c2083b1aa3e00c42daaea95.tar.gz org.eclipse.papyrus-e9c6b1b23e75a5572c2083b1aa3e00c42daaea95.tar.xz org.eclipse.papyrus-e9c6b1b23e75a5572c2083b1aa3e00c42daaea95.zip |
Bug 536581 - NullPointerException in PolicyChecker.getFor
- provide default policyChecker for call with null
- return null as diagramType when diagram is null
Change-Id: I31eac58d645f82e4c8ac93c67950aecf27f0927b
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Diffstat (limited to 'plugins/infra')
2 files changed, 25 insertions, 22 deletions
diff --git a/plugins/infra/gmfdiag/expansion/org.eclipse.papyrus.infra.gmfdiag.expansion/src/main/java/org/eclipse/papyrus/infra/gmfdiag/expansion/expansionmodel/providers/ExpandEditPartProvider.java b/plugins/infra/gmfdiag/expansion/org.eclipse.papyrus.infra.gmfdiag.expansion/src/main/java/org/eclipse/papyrus/infra/gmfdiag/expansion/expansionmodel/providers/ExpandEditPartProvider.java index 469f19af7ca..877d0972cb9 100644 --- a/plugins/infra/gmfdiag/expansion/org.eclipse.papyrus.infra.gmfdiag.expansion/src/main/java/org/eclipse/papyrus/infra/gmfdiag/expansion/expansionmodel/providers/ExpandEditPartProvider.java +++ b/plugins/infra/gmfdiag/expansion/org.eclipse.papyrus.infra.gmfdiag.expansion/src/main/java/org/eclipse/papyrus/infra/gmfdiag/expansion/expansionmodel/providers/ExpandEditPartProvider.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2015 CEA LIST. + * Copyright (c) 2015, 2018 CEA LIST. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,8 +8,8 @@ * * Contributors: * - * CEA LIST - Initial API and implementation - * + * CEA LIST - Initial API and implementation + * Benoit Maggi (CEA) - Bug 536581 *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.expansion.expansionmodel.providers; @@ -52,10 +52,10 @@ public class ExpandEditPartProvider extends AbstractEditPartProvider { // private static final boolean DEBUG_EXPANSION = "true".equalsIgnoreCase(Platform.getDebugOption( // "org.eclipse.papyrus.infra.gmfdiag.common/debug/expansion")); /** Map containing node view types supported by this provider */ - protected Map<String, Class<?>> nodeMap = new HashMap<String, Class<?>>(); + protected Map<String, Class<?>> nodeMap = new HashMap<>(); /** Map containing edge view types supported by this provider */ - protected Map<String, Class<?>> edgeMap = new HashMap<String, Class<?>>(); + protected Map<String, Class<?>> edgeMap = new HashMap<>(); private DiagramExpansionsRegistry diagramExpansionRegistry=null; @@ -67,14 +67,15 @@ public class ExpandEditPartProvider extends AbstractEditPartProvider { } protected String getDiagramType(View currentView) { - Diagram diagram=currentView.getDiagram(); String currentDiagramType=null; - ViewPrototype viewPrototype=org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils.getPrototype(diagram); - if(viewPrototype!=null){ - currentDiagramType=viewPrototype.getLabel(); - } - else{ - currentDiagramType=diagram.getType(); + Diagram diagram=currentView.getDiagram(); + if (diagram != null) { + ViewPrototype viewPrototype=org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils.getPrototype(diagram); + if(viewPrototype!=null){ + currentDiagramType=viewPrototype.getLabel(); + } else{ + currentDiagramType=diagram.getType(); + } } return currentDiagramType; } @@ -123,8 +124,7 @@ public class ExpandEditPartProvider extends AbstractEditPartProvider { if ((currentDiagramType == null) || (diagramExpansionRegistry.getUsage(currentDiagramType)==null)) { return null; } - - + String graphicalType = view.getType(); Activator.log.trace(Activator.EXPANSION_TRACE,this.getClass().getName()+" view appears with the type "+graphicalType);//$NON-NLS-1$ EObject eObject= diagramExpansionRegistry.mapChildreen.get(currentDiagramType).IDMap.get(graphicalType); @@ -178,7 +178,6 @@ public class ExpandEditPartProvider extends AbstractEditPartProvider { private IGraphicalEditPart createNewGraphicEditPart(Class editpartClass, Object[] constructorParams) { try { Constructor constructor = getCreationConstructor(editpartClass); - return (constructor == null)? null : (IGraphicalEditPart) constructor.newInstance(constructorParams); } catch (Throwable e) { diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java index 408e3c76ac8..6a64edc3e82 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013, 2017 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2013, 2017, 2018 CEA LIST, Christian W. Damus, and others. * * * All rights reserved. This program and the accompanying materials @@ -12,6 +12,7 @@ * Christian W. Damus (CEA) - bug 422257 * Christian W. Damus - bugs 463156, 493030 * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 519409 + * Benoit Maggi (CEA) - Bug 536581 *****************************************************************************/ package org.eclipse.papyrus.infra.viewpoints.policy; @@ -75,30 +76,33 @@ public class PolicyChecker { * @since 2.0 */ public static PolicyChecker getFor(EObject object) { - if (object.eResource() != null) + if (object!= null && object.eResource() != null) { return getFor(object.eResource()); - else + } else { return getFor(ArchitectureDomainManager.getInstance().getDefaultArchitectureContext()); + } } /** * @since 2.0 */ public static PolicyChecker getFor(Resource resource) { - if (resource.getResourceSet() != null) + if (resource != null && resource.getResourceSet() != null) { return getFor(resource.getResourceSet()); - else + } else { return getFor(ArchitectureDomainManager.getInstance().getDefaultArchitectureContext()); + } } /** * @since 2.0 */ public static PolicyChecker getFor(ResourceSet resourceSet) { - if (resourceSet instanceof ModelSet) + if (resourceSet instanceof ModelSet) { return getFor((ModelSet) resourceSet); - else + } else { return getFor(ArchitectureDomainManager.getInstance().getDefaultArchitectureContext()); + } } /** |