Buggy code:
} protected static final String PREF_KEY = "Coloc_2." ; protected enum RoiConfiguration { None , Img1 , Img2 , Mask , RoiManager ; } protected Coloc_2 . RoiConfiguration roiConfig = Coloc_2 . RoiConfiguration . Img1 ; protected ArrayList < Coloc_2 < T > . MaskInfo > masks = new ArrayList < Coloc_2 < T > . MaskInfo > ( ) ; protected static int index1 = 0 ; protected static int index2 = 1 ; protected static int indexMask = 0 ; protected static int indexRoi = 0 ; protected Image < T > img1 ; protected Image < T > img2 ; protected int img1Channel = 1 ; protected int img2Channel = 1 ; protected PearsonsCorrelation < T > pearsonsCorrelation ; protected LiHistogram2D < T > liHistogramCh1 ; protected LiHistogram2D < T > liHistogramCh2 ; protected LiICQ < T > liICQ ; protected MandersColocalization < T > mandersCorrelation ; protected Histogram2D < T > histogram2D ; protected CostesSignificanceTest < T > costesSignificance ; protected boolean displayImages ; protected boolean autoSavePdf ; public void run ( String arg0 ) { } public boolean showDialog ( ) { int [ ] windowList = WindowManager . getIDList ( ) ; if ( ( windowList == null ) || ( ( windowList . length ) < 2 ) ) { IJ . showMessage ( "At<seq2seq4repair_space>least<seq2seq4repair_space>2<seq2seq4repair_space>images<seq2seq4repair_space>must<seq2seq4repair_space>be<seq2seq4repair_space>open!" ) ; return false ; } final GenericDialog gd = new GenericDialog ( "Coloc<seq2seq4repair_space>2" ) ; String [ ] titles = new String [ windowList . length ] ; String [ ] roisAndMasks = new String [ ( windowList . length ) + 4 ] ; roisAndMasks [ 0 ] = "<None>" ; roisAndMasks [ 1 ] = "ROI(s)<seq2seq4repair_space>in<seq2seq4repair_space>channel<seq2seq4repair_space>1" ; roisAndMasks [ 2 ] = "ROI(s)<seq2seq4repair_space>in<seq2seq4repair_space>channel<seq2seq4repair_space>2" ; roisAndMasks [ 3 ] = "ROI<seq2seq4repair_space>Manager" ; for ( int i = 0 ; i < ( windowList . length ) ; i ++ ) { ImagePlus imp = WindowManager . getImage ( windowList [ i ] ) ; if ( imp != null ) { titles [ i ] = imp . getTitle ( ) ; roisAndMasks [ ( i + 4 ) ] = imp . getTitle ( ) ; } else { titles [ i ] = "" ; } } displayImages = Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "displayImages" ) , false ) ; autoSavePdf = Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "autoSavePdf" ) , true ) ; boolean displayShuffledCostes = Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "displayShuffledCostes" ) , false ) ; boolean useLiCh1 = Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "useLiCh1" ) , true ) ; boolean useLiCh2 = Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "useLiCh2" ) , true ) ; boolean useLiICQ = Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "useLiICQ" ) , true ) ; boolean useManders = Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "useManders" ) , true ) ; boolean useScatterplot = Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "useScatterplot" ) , true ) ; boolean useCostes = Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "useCostes" ) , true ) ; int psf = ( ( int ) ( Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "psf" ) , 3 ) ) ) ; int nrCostesRandomisations = ( ( int ) ( Prefs . get ( ( ( Coloc_2 . PREF_KEY ) + "nrCostesRandomisations" ) , 10 ) ) ) ; Coloc_2 . index1 = Coloc_2 . clip ( Coloc_2 . index1 , 0 , titles . length ) ; Coloc_2 . index2 = Coloc_2 . clip ( Coloc_2 . index2 , 0 , titles . length ) ; <START_BUG> Coloc_2 . indexMask = Coloc_2 . clip ( Coloc_2 . indexMask , 0 , roisAndMasks . length ) ; <END_BUG> gd . addChoice ( "Channel_1" , titles , titles [ Coloc_2 . index1 ] ) ; gd . addChoice ( "Channel_2" , titles , titles [ Coloc_2 . index2 ] ) ; gd . addChoice ( "ROI_or_mask" , roisAndMasks , roisAndMasks [ Coloc_2 . indexMask ] ) ; gd . addCheckbox ( "Show_\"Save_PDF\"_Dialog" , autoSavePdf ) ; gd . addCheckbox ( "Display_Images_in_Result" , displayImages ) ; gd . addCheckbox ( "Display_Shuffled_Images" , displayShuffledCostes ) ; final Checkbox shuffleCb = ( ( Checkbox ) ( gd . getCheckboxes ( ) . lastElement ( ) ) ) ; gd . addMessage ( "Algorithms:" ) ; gd . addCheckbox ( "Li_Histogram_Channel_1" , useLiCh1 ) ; gd . addCheckbox ( "Li_Histogram_Channel_2" , useLiCh2 ) ; gd . addCheckbox ( "Li_ICQ" , useLiICQ ) ; gd . addCheckbox ( "Manders'_Correlation" , useManders ) ; gd . addCheckbox ( "2D_Instensity_Histogram" , useScatterplot ) ; gd . addCheckbox ( "Costes'_Significance_Test" , useCostes ) ; final Checkbox costesCb = ( ( Checkbox ) ( gd . getCheckboxes ( ) . lastElement ( ) ) ) ; gd . addNumericField ( "PSF" , psf , 1 ) ; gd . addNumericField ( "Costes_randomisations" , nrCostesRandomisations , 0 ) ; shuffleCb . setEnabled ( useCostes ) ; costesCb . addItemListener ( new ItemListener ( ) { @ Override public void itemStateChanged ( ItemEvent e ) { shuffleCb . setEnabled ( costesCb . getState ( ) ) ; } } ) ; gd . showDialog ( ) ; if ( gd . wasCanceled ( ) ) return false ; ImagePlus imp1 = WindowManager . getImage ( ( ( gd . getNextChoiceIndex ( ) ) + 1 ) ) ; ImagePlus imp2 = WindowManager . getImage ( ( ( gd . getNextChoiceIndex ( ) ) + 1 ) ) ; Coloc_2 . indexMask = gd . getNextChoiceIndex ( ) ; if ( ( Coloc_2 . indexMask ) == 0 ) roiConfig = Coloc_2 . RoiConfiguration . None ;

Fix:
Coloc_2 . indexMask = Coloc_2 . clip ( Coloc_2 . indexMask , 0 , ( ( roisAndMasks . length ) - 1 ) ) ;