From: gmungoc Date: Wed, 22 Jun 2016 13:56:32 +0000 (+0100) Subject: JAL-1982 defensive checks for null annotations array X-Git-Tag: Release_2_10_0~159^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=dea079f732d46e67066405edece02f673f9c0f0c;p=jalview.git JAL-1982 defensive checks for null annotations array --- diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 081f446..33a54e8 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -1332,15 +1332,19 @@ public class AlignmentUtils Collection types, List forSequences, boolean anyType, boolean doShow) { - for (AlignmentAnnotation aa : al.getAlignmentAnnotation()) + AlignmentAnnotation[] anns = al.getAlignmentAnnotation(); + if (anns != null) { - if (anyType || types.contains(aa.label)) + for (AlignmentAnnotation aa : anns) { - if ((aa.sequenceRef != null) - && (forSequences == null || forSequences - .contains(aa.sequenceRef))) + if (anyType || types.contains(aa.label)) { - aa.visible = doShow; + if ((aa.sequenceRef != null) + && (forSequences == null || forSequences + .contains(aa.sequenceRef))) + { + aa.visible = doShow; + } } } } diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 8b3aa98..d738882 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -1760,6 +1760,10 @@ public class AnnotationFile */ public String printCSVAnnotations(AlignmentAnnotation[] annotations) { + if (annotations == null) + { + return ""; + } StringBuffer sp = new StringBuffer(); for (int i = 0; i < annotations.length; i++) { diff --git a/src/jalview/io/JSONFile.java b/src/jalview/io/JSONFile.java index 36980f8..3cda444 100644 --- a/src/jalview/io/JSONFile.java +++ b/src/jalview/io/JSONFile.java @@ -744,11 +744,14 @@ public class JSONFile extends AlignFile implements ComplexAlignFile fr = avpanel.cloneFeatureRenderer(); // Add non auto calculated annotation to AlignFile - for (AlignmentAnnotation annot : annots) + if (annots != null) { - if (annot != null && !annot.autoCalculated) + for (AlignmentAnnotation annot : annots) { - annotations.add(annot); + if (annot != null && !annot.autoCalculated) + { + annotations.add(annot); + } } } globalColourScheme = ColourSchemeProperty.getColourName(viewport diff --git a/src/jalview/schemes/RNAHelicesColour.java b/src/jalview/schemes/RNAHelicesColour.java index d17f510..9729a83 100644 --- a/src/jalview/schemes/RNAHelicesColour.java +++ b/src/jalview/schemes/RNAHelicesColour.java @@ -91,6 +91,10 @@ public class RNAHelicesColour extends ResidueColourScheme // This loop will find the first rna structure annotation by which to colour // the sequences. AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation(); + if (annotations == null) + { + return; + } for (int i = 0; i < annotations.length; i++) { diff --git a/src/jalview/schemes/RNAHelicesColourChooser.java b/src/jalview/schemes/RNAHelicesColourChooser.java index 1a13bbe..b1b3c5a 100644 --- a/src/jalview/schemes/RNAHelicesColourChooser.java +++ b/src/jalview/schemes/RNAHelicesColourChooser.java @@ -22,6 +22,7 @@ package jalview.schemes; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; +import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceGroup; import java.awt.event.ActionEvent; @@ -77,16 +78,20 @@ public class RNAHelicesColourChooser adjusting = true; Vector list = new Vector(); int index = 1; - for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++) + AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation(); + if (anns != null) { - String label = av.getAlignment().getAlignmentAnnotation()[i].label; - if (!list.contains(label)) + for (int i = 0; i < anns.length; i++) { - list.addElement(label); - } - else - { - list.addElement(label + "_" + (index++)); + String label = anns[i].label; + if (!list.contains(label)) + { + list.addElement(label); + } + else + { + list.addElement(label + "_" + (index++)); + } } } diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 0f6d66b..91ee3c1 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -1420,11 +1420,15 @@ public abstract class AlignmentViewport implements AlignViewportI, protected void setSequenceAnnotationsVisible(SequenceI sequenceI, boolean visible) { - for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation()) + AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation(); + if (anns != null) { - if (ann.sequenceRef == sequenceI) + for (AlignmentAnnotation ann : anns) { - ann.visible = visible; + if (ann.sequenceRef == sequenceI) + { + ann.visible = visible; + } } } } diff --git a/src/jalview/workers/StrucConsensusThread.java b/src/jalview/workers/StrucConsensusThread.java index 3483dac..4249112 100644 --- a/src/jalview/workers/StrucConsensusThread.java +++ b/src/jalview/workers/StrucConsensusThread.java @@ -94,12 +94,15 @@ public class StrucConsensusThread extends AlignCalcWorker .getAlignmentAnnotation(); AlignmentAnnotation rnaStruc = null; // select rna struct to use for calculation - for (int i = 0; i < aa.length; i++) + if (aa != null) { - if (aa[i].visible && aa[i].isRNA() && aa[i].isValidStruc()) + for (int i = 0; i < aa.length; i++) { - rnaStruc = aa[i]; - break; + if (aa[i].visible && aa[i].isRNA() && aa[i].isValidStruc()) + { + rnaStruc = aa[i]; + break; + } } } // check to see if its valid