JAL-2490 test coverage of empty and null feature group in Jalview format
[jalview.git] / src / jalview / io / FeaturesFile.java
index afc00ee..a3cab6b 100755 (executable)
@@ -542,12 +542,15 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
             .toArray(new String[visible.keySet().size()]);
 
     /*
-     * sort groups alphabetically, and ensure that null group is output last
+     * sort groups alphabetically, and ensure that features with a
+     * null or empty group are output after those in named groups
      */
     List<String> sortedGroups = new ArrayList<String>(visibleFeatureGroups);
     sortedGroups.remove(null);
+    sortedGroups.remove("");
     Collections.sort(sortedGroups);
     sortedGroups.add(null);
+    sortedGroups.add("");
 
     boolean foundSome = false;
 
@@ -570,7 +573,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
 
     for (String group : sortedGroups)
     {
-      if (group != null)
+      boolean isNamedGroup = (group != null && !"".equals(group));
+      if (isNamedGroup)
       {
         out.append(newline);
         out.append("STARTGROUP").append(TAB);
@@ -598,7 +602,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
         }
       }
 
-      if (group != null)
+      if (isNamedGroup)
       {
         out.append("ENDGROUP").append(TAB);
         out.append(group);