JAL-1136 sometimes there are no parameters associated with a CalcId key
[jalview.git] / src / jalview / gui / Jalview2XML.java
index ea5d5a7..ee67b55 100644 (file)
@@ -1236,12 +1236,18 @@ public class Jalview2XML
         }
       }
     }
-    if (calcIdSet.size()>0)
+    if (calcIdSet.size() > 0)
     {
-      for (String calcId:calcIdSet)
+      for (String calcId : calcIdSet)
       {
-        if (calcId.trim().length()>0) {
-          view.addCalcIdParam(createCalcIdParam(calcId, av));
+        if (calcId.trim().length() > 0)
+        {
+          CalcIdParam cidp = createCalcIdParam(calcId, av);
+          // Some calcIds have no parameters.
+          if (cidp != null)
+          {
+            view.addCalcIdParam(cidp);
+          }
         }
       }
     }
@@ -2306,24 +2312,20 @@ public class Jalview2XML
           jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),
                   an[i].getDescription(), anot);
         }
-        if (autoForView)
+        // register new annotation
+        if (an[i].getId() != null)
+        {
+          annotationIds.put(an[i].getId(), jaa);
+          jaa.annotationId = an[i].getId();
+        }
+        // recover sequence association
+        if (an[i].getSequenceRef() != null)
         {
-          // register new annotation
-          if (an[i].getId() != null)
+          if (al.findName(an[i].getSequenceRef()) != null)
           {
-            annotationIds.put(an[i].getId(), jaa);
-            jaa.annotationId = an[i].getId();
-          }
-          // recover sequence association
-          if (an[i].getSequenceRef() != null)
-          {
-            if (al.findName(an[i].getSequenceRef()) != null)
-            {
-              jaa.createSequenceMapping(
-                      al.findName(an[i].getSequenceRef()), 1, true);
-              al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(
-                      jaa);
-            }
+            jaa.createSequenceMapping(al.findName(an[i].getSequenceRef()),
+                    1, true);
+            al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa);
           }
         }
         // and make a note of any group association
@@ -3367,13 +3369,20 @@ public class Jalview2XML
                 );
       }
     }
-    if (view.getCalcIdParam()!=null)
+    if (view.getCalcIdParam() != null)
     {
-      for (CalcIdParam calcIdParam:view.getCalcIdParam())
+      for (CalcIdParam calcIdParam : view.getCalcIdParam())
       {
-        if (recoverCalcIdParam(calcIdParam, af.viewport)) {
-        } else {
-          warn("Couldn't recover parameters for "+calcIdParam.getCalcId());
+        if (calcIdParam != null)
+        {
+          if (recoverCalcIdParam(calcIdParam, af.viewport))
+          {
+          }
+          else
+          {
+            warn("Couldn't recover parameters for "
+                    + calcIdParam.getCalcId());
+          }
         }
       }
     }