AnnotatedCollectionI ref = ctx;
while (ref != null)
{
- if (ref == this)
+ if (ref == this || ref.getContext() == ctx)
{
throw new IllegalArgumentException(
"Circular reference in SequenceGroup.context");
assertEquals(a.getHiddenSequences().getSize(), 1);
}
+ @Test(
+ groups = "Functional",
+ expectedExceptions = { IllegalArgumentException.class })
+ public void testSetDataset_selfReference()
+ {
+ SequenceI seq = new Sequence("a", "a");
+ AlignmentI alignment = new Alignment(new SequenceI[] { seq });
+ alignment.setDataset(alignment);
+ }
}
import jalview.schemes.NucleotideColourScheme;
+import junit.extensions.PA;
+
import org.testng.annotations.Test;
public class SequenceGroupTest
// expected
assertNull(sg3.getContext());
}
+
+ /*
+ * use PrivilegedAccessor to 'force' a SequenceGroup with
+ * a circular context reference
+ */
+ PA.setValue(sg2, "context", sg2);
+ try
+ {
+ sg3.setContext(sg2); // circular reference in sg2
+ fail("Expected exception");
+ } catch (IllegalArgumentException e)
+ {
+ // expected
+ assertNull(sg3.getContext());
+ }
}
@Test(groups = { "Functional" })