From 143f4631badc09685fdbdaa33839f2e438ea7a22 Mon Sep 17 00:00:00 2001
From: Dominique Marcadet <Dominique.Marcadet@centralesupelec.fr>
Date: Thu, 30 May 2019 10:44:20 +0200
Subject: [PATCH] avoid NPE when referred object is in ServiceNS

---
 .../iec61850/nsd/impl/DataAttributeImpl.java  | 32 +++++++++++++++----
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.nsd/src/fr/centralesupelec/edf/riseclipse/iec61850/nsd/impl/DataAttributeImpl.java b/fr.centralesupelec.edf.riseclipse.iec61850.nsd/src/fr/centralesupelec/edf/riseclipse/iec61850/nsd/impl/DataAttributeImpl.java
index 4120efe..adc0fc7 100644
--- a/fr.centralesupelec.edf.riseclipse.iec61850.nsd/src/fr/centralesupelec/edf/riseclipse/iec61850/nsd/impl/DataAttributeImpl.java
+++ b/fr.centralesupelec.edf.riseclipse.iec61850.nsd/src/fr/centralesupelec/edf/riseclipse/iec61850/nsd/impl/DataAttributeImpl.java
@@ -3589,11 +3589,17 @@ public class DataAttributeImpl extends DocumentedClassImpl implements DataAttrib
             }
             else {
                 setRefersToFunctionalConstraint( foundFC );
+                String foundWhere = "(???";
+                if( getRefersToFunctionalConstraint().getParentFunctionalConstraints().getParentNS() !=  null ) {
+                    foundWhere = "NS (id:" + getRefersToFunctionalConstraint().getParentFunctionalConstraints().getParentNS().getId();
+                }
+                else if( getRefersToFunctionalConstraint().getParentFunctionalConstraints().getParentServiceNS() != null ) {
+                    foundWhere = "ServiceNS (id:" + getRefersToFunctionalConstraint().getParentFunctionalConstraints().getParentServiceNS().getId();
+                }
                 console.info( "[NSD links] FunctionalConstraint (abbreviation: " + getFc()
                         + ") refers by DataAttribute (name: "
-                        + getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
-                        + getRefersToFunctionalConstraint().getParentFunctionalConstraints().getParentNS().getId()
-                        + ")" );
+                        + getName() + ") in NS (id:" + ns.getId() + ") found in "
+                        + foundWhere + ")" );
             }
         }
 
@@ -3605,10 +3611,17 @@ public class DataAttributeImpl extends DocumentedClassImpl implements DataAttrib
             }
             else {
                 setRefersToPresenceCondition( foundPC );
+                String foundWhere = "(???";
+                if( getRefersToPresenceCondition().getParentPresenceConditions().getParentNS() !=  null ) {
+                    foundWhere = "NS (id:" + getRefersToPresenceCondition().getParentPresenceConditions().getParentNS().getId();
+                }
+                else if( getRefersToPresenceCondition().getParentPresenceConditions().getParentServiceNS() != null ) {
+                    foundWhere = "ServiceNS (id:" + getRefersToPresenceCondition().getParentPresenceConditions().getParentServiceNS().getId();
+                }
                 console.info( "[NSD links] PresenceCondition (name: " + getPresCond()
                         + ") refers by DataAttribute (name: "
                         + getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
-                        + getRefersToPresenceCondition().getParentPresenceConditions().getParentNS().getId() + ")" );
+                        + foundWhere + ")" );
             }
         }
 
@@ -3673,12 +3686,17 @@ public class DataAttributeImpl extends DocumentedClassImpl implements DataAttrib
                     }
                     else {
                         setRefersToConstructedAttribute( foundCA );
+                        String foundWhere = "(???";
+                        if( getRefersToConstructedAttribute().getParentConstructedAttributes() !=  null ) {
+                            foundWhere = "NS (id:" + getRefersToConstructedAttribute().getParentConstructedAttributes().getParentNS().getId();
+                        }
+                        else if( getRefersToConstructedAttribute().getParentServiceTypeRealizations() != null ) {
+                            foundWhere = "ServiceNS (id:" + getRefersToConstructedAttribute().getParentServiceTypeRealizations().getParentServiceNS().getId();
+                        }
                         console.info( "[NSD links] ConstructedAttribute (name: " + getType()
                                 + ") refers as type by DataAttribute (name: "
                                 + getName() + ") in NS (id:" + ns.getId() + ") found in NS (id:"
-                                + getRefersToConstructedAttribute().getParentConstructedAttributes().getParentNS()
-                                        .getId()
-                                + ")" );
+                                + foundWhere + ")" );
                     }
                     break;
                 case DefinedAttributeTypeKind.ENUMERATED_VALUE:
-- 
GitLab