JAL-4245 Return null from getRootDataset if no dataset
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 26 Jul 2023 12:03:14 +0000 (14:03 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 26 Jul 2023 12:03:14 +0000 (14:03 +0200)
src/jalview/datamodel/SequenceI.java

index d8a5462..11aa4e6 100755 (executable)
@@ -396,11 +396,16 @@ public interface SequenceI extends ASequenceI
   public SequenceI getDatasetSequence();
 
   /**
-   * Returns the top grandparent in the dataset sequences hierarchy.
+   * Returns the top grandparent in the dataset sequences hierarchy
+   * or null if there is no dataset associated with this sequence.
    */
   public default SequenceI getRootDatasetSequence()
   {
-    var sequence = this;
+    if (getDatasetSequence() == null)
+    {
+      return null;
+    }
+    var sequence = getDatasetSequence();
     while (sequence.getDatasetSequence() != null)
     {
       sequence = sequence.getDatasetSequence();