Program: 14339
Project: 14339
Buggy source:
private void updateUI(){
  if (!isAdded()) {
    return;
  }
  if (mVisitsData == null) {
    setupNoResultsUI(false);
    return;
  }
  if (mVisitsData instanceof VolleyError || mVisitsData instanceof StatsError) {
    setupNoResultsUI(false);
    return;
  }
  final VisitModel[] dataToShowOnGraph=getDataToShowOnGraph((VisitsModel)mVisitsData);
  if (dataToShowOnGraph == null || dataToShowOnGraph.length == 0) {
    setupNoResultsUI(false);
    return;
  }
  mNoActivtyThisPeriodContainer.setVisibility(View.GONE);
  OverviewLabel selectedStatsType=overviewItems[mSelectedOverviewItemIndex];
  mLegendContainer.setVisibility(View.VISIBLE);
  mLegendLabel.setText(StringUtils.capitalize(selectedStatsType.getLabel().toLowerCase()));
switch (selectedStatsType) {
case VIEWS:
    mVisitorsCheckboxContainer.setVisibility(View.VISIBLE);
  mVisitorsCheckbox.setEnabled(true);
mVisitorsCheckbox.setChecked(mIsCheckboxChecked);
break;
default :
mVisitorsCheckboxContainer.setVisibility(View.GONE);
break;
}
final String[] horLabels=new String[dataToShowOnGraph.length];
mStatsDate=new String[dataToShowOnGraph.length];
GraphView.GraphViewData[] mainSeriesItems=new GraphView.GraphViewData[dataToShowOnGraph.length];
GraphView.GraphViewData[] secondarySeriesItems=null;
if (mIsCheckboxChecked && selectedStatsType == OverviewLabel.VIEWS) {
secondarySeriesItems=new GraphView.GraphViewData[dataToShowOnGraph.length];
}
for (int i=0; i < dataToShowOnGraph.length; i++) {
int currentItemValue=0;
switch (selectedStatsType) {
case VIEWS:
currentItemValue=dataToShowOnGraph[i].getViews();
break;
case VISITORS:
currentItemValue=dataToShowOnGraph[i].getVisitors();
break;
case LIKES:
currentItemValue=dataToShowOnGraph[i].getLikes();
break;
case COMMENTS:
currentItemValue=dataToShowOnGraph[i].getComments();
break;
}
mainSeriesItems[i]=new GraphView.GraphViewData(i,currentItemValue);
if (mIsCheckboxChecked && secondarySeriesItems != null) {
secondarySeriesItems[i]=new GraphView.GraphViewData(i,dataToShowOnGraph[i].getVisitors());
}
String currentItemStatsDate=dataToShowOnGraph[i].getPeriod();
horLabels[i]=getDateLabelForBarInGraph(currentItemStatsDate);
mStatsDate[i]=currentItemStatsDate;
}
if (mGraphContainer.getChildCount() >= 1 && mGraphContainer.getChildAt(0) instanceof GraphView) {
mGraphView=(StatsBarGraph)mGraphContainer.getChildAt(0);
}
 else {
mGraphContainer.removeAllViews();
mGraphView=new StatsBarGraph(getActivity());
mGraphContainer.addView(mGraphView);
}
mGraphView.removeAllSeries();
GraphViewSeries mainSeriesOnScreen=new GraphViewSeries(mainSeriesItems);
mainSeriesOnScreen.getStyle().color=getResources().getColor(R.color.stats_bar_graph_main_series);
mainSeriesOnScreen.getStyle().highlightColor=getResources().getColor(R.color.stats_bar_graph_main_series_highlight);
mainSeriesOnScreen.getStyle().outerhighlightColor=getResources().getColor(R.color.stats_bar_graph_outer_highlight);
mainSeriesOnScreen.getStyle().padding=DisplayUtils.dpToPx(getActivity(),5);
mGraphView.addSeries(mainSeriesOnScreen);
if (mIsCheckboxChecked && secondarySeriesItems != null && selectedStatsType == OverviewLabel.VIEWS) {
GraphViewSeries secondarySeries=new GraphViewSeries(secondarySeriesItems);
secondarySeries.getStyle().padding=DisplayUtils.dpToPx(getActivity(),10);
secondarySeries.getStyle().color=getResources().getColor(R.color.stats_bar_graph_secondary_series);
secondarySeries.getStyle().highlightColor=getResources().getColor(R.color.orange_fire);
mGraphView.addSeries(secondarySeries);
}
switch (selectedStatsType) {
case VISITORS:
double maxYValue=getMaxYValueForVisitorsAndView(dataToShowOnGraph);
mGraphView.setManualYAxisBounds(maxYValue,0d);
break;
default :
mGraphView.setManualYAxis(false);
break;
}
mGraphView.getGraphViewStyle().setNumHorizontalLabels(dataToShowOnGraph.length);
mGraphView.getGraphViewStyle().setMaxColumnWidth(DisplayUtils.dpToPx(getActivity(),StatsConstants.STATS_GRAPH_BAR_MAX_COLUMN_WIDTH_DP));
mGraphView.setHorizontalLabels(horLabels);
mGraphView.setGestureListener(this);
boolean resultsAvailable=false;
for (int i=0; i < dataToShowOnGraph.length; i++) {
if (dataToShowOnGraph[i].getViews() != 0 || dataToShowOnGraph[i].getVisitors() != 0 || dataToShowOnGraph[i].getLikes() != 0 || dataToShowOnGraph[i].getComments() != 0) {
resultsAvailable=true;
break;
}
}
mNoActivtyThisPeriodContainer.setVisibility(resultsAvailable ? View.GONE : View.VISIBLE);
mGraphView.setClickable(resultsAvailable);
if (mPrevNumberOfBarsGraph != -1 && mPrevNumberOfBarsGraph != dataToShowOnGraph.length) {
mSelectedBarGraphBarIndex=-1;
mPrevNumberOfBarsGraph=dataToShowOnGraph.length;
onBarTapped(dataToShowOnGraph.length - 1);
mGraphView.highlightBar(dataToShowOnGraph.length - 1);
return;
}
mPrevNumberOfBarsGraph=dataToShowOnGraph.length;
int barSelectedOnGraph;
if (mSelectedBarGraphBarIndex == -1) {
barSelectedOnGraph=dataToShowOnGraph.length - 1;
}
 else if (mSelectedBarGraphBarIndex < dataToShowOnGraph.length) {
barSelectedOnGraph=mSelectedBarGraphBarIndex;
}
 else {
barSelectedOnGraph=dataToShowOnGraph.length - 1;
mSelectedBarGraphBarIndex=barSelectedOnGraph;
}
updateUIBelowTheGraph(barSelectedOnGraph);
mGraphView.highlightBar(barSelectedOnGraph);
}

Fixed version (ground truth):
private void updateUI(){
  if (!isAdded()) {
    return;
  }
  if (mVisitsData == null) {
    setupNoResultsUI(false);
    return;
  }
  if (mVisitsData instanceof VolleyError || mVisitsData instanceof StatsError) {
    setupNoResultsUI(false);
    return;
  }
  final VisitModel[] dataToShowOnGraph=getDataToShowOnGraph((VisitsModel)mVisitsData);
  if (dataToShowOnGraph == null || dataToShowOnGraph.length == 0) {
    setupNoResultsUI(false);
    return;
  }
  mNoActivtyThisPeriodContainer.setVisibility(View.GONE);
  OverviewLabel selectedStatsType=overviewItems[mSelectedOverviewItemIndex];
  mLegendContainer.setVisibility(View.VISIBLE);
  mLegendLabel.setText(StringUtils.capitalize(selectedStatsType.getLabel().toLowerCase()));
switch (selectedStatsType) {
case VIEWS:
    mVisitorsCheckboxContainer.setVisibility(View.VISIBLE);
  mVisitorsCheckbox.setEnabled(true);
mVisitorsCheckbox.setChecked(mIsCheckboxChecked);
break;
default :
mVisitorsCheckboxContainer.setVisibility(View.GONE);
break;
}
final String[] horLabels=new String[dataToShowOnGraph.length];
mStatsDate=new String[dataToShowOnGraph.length];
GraphView.GraphViewData[] mainSeriesItems=new GraphView.GraphViewData[dataToShowOnGraph.length];
GraphView.GraphViewData[] secondarySeriesItems=null;
if (mIsCheckboxChecked && selectedStatsType == OverviewLabel.VIEWS) {
secondarySeriesItems=new GraphView.GraphViewData[dataToShowOnGraph.length];
}
boolean atLeastOneResultIsAvailable=false;
for (int i=0; i < dataToShowOnGraph.length; i++) {
int currentItemValue=0;
switch (selectedStatsType) {
case VIEWS:
currentItemValue=dataToShowOnGraph[i].getViews();
break;
case VISITORS:
currentItemValue=dataToShowOnGraph[i].getVisitors();
break;
case LIKES:
currentItemValue=dataToShowOnGraph[i].getLikes();
break;
case COMMENTS:
currentItemValue=dataToShowOnGraph[i].getComments();
break;
}
mainSeriesItems[i]=new GraphView.GraphViewData(i,currentItemValue);
if (currentItemValue > 0) {
atLeastOneResultIsAvailable=true;
}
if (mIsCheckboxChecked && secondarySeriesItems != null) {
secondarySeriesItems[i]=new GraphView.GraphViewData(i,dataToShowOnGraph[i].getVisitors());
}
String currentItemStatsDate=dataToShowOnGraph[i].getPeriod();
horLabels[i]=getDateLabelForBarInGraph(currentItemStatsDate);
mStatsDate[i]=currentItemStatsDate;
}
if (mGraphContainer.getChildCount() >= 1 && mGraphContainer.getChildAt(0) instanceof GraphView) {
mGraphView=(StatsBarGraph)mGraphContainer.getChildAt(0);
}
 else {
mGraphContainer.removeAllViews();
mGraphView=new StatsBarGraph(getActivity());
mGraphContainer.addView(mGraphView);
}
mGraphView.removeAllSeries();
GraphViewSeries mainSeriesOnScreen=new GraphViewSeries(mainSeriesItems);
mainSeriesOnScreen.getStyle().color=getResources().getColor(R.color.stats_bar_graph_main_series);
mainSeriesOnScreen.getStyle().highlightColor=getResources().getColor(R.color.stats_bar_graph_main_series_highlight);
mainSeriesOnScreen.getStyle().outerhighlightColor=getResources().getColor(R.color.stats_bar_graph_outer_highlight);
mainSeriesOnScreen.getStyle().padding=DisplayUtils.dpToPx(getActivity(),5);
mGraphView.addSeries(mainSeriesOnScreen);
if (mIsCheckboxChecked && secondarySeriesItems != null && selectedStatsType == OverviewLabel.VIEWS) {
GraphViewSeries secondarySeries=new GraphViewSeries(secondarySeriesItems);
secondarySeries.getStyle().padding=DisplayUtils.dpToPx(getActivity(),10);
secondarySeries.getStyle().color=getResources().getColor(R.color.stats_bar_graph_secondary_series);
secondarySeries.getStyle().highlightColor=getResources().getColor(R.color.orange_fire);
mGraphView.addSeries(secondarySeries);
}
switch (selectedStatsType) {
case VISITORS:
double maxYValue=getMaxYValueForVisitorsAndView(dataToShowOnGraph);
mGraphView.setManualYAxisBounds(maxYValue,0d);
break;
default :
mGraphView.setManualYAxis(false);
break;
}
mGraphView.getGraphViewStyle().setNumHorizontalLabels(dataToShowOnGraph.length);
mGraphView.getGraphViewStyle().setMaxColumnWidth(DisplayUtils.dpToPx(getActivity(),StatsConstants.STATS_GRAPH_BAR_MAX_COLUMN_WIDTH_DP));
mGraphView.setHorizontalLabels(horLabels);
mGraphView.setGestureListener(this);
mNoActivtyThisPeriodContainer.setVisibility(atLeastOneResultIsAvailable ? View.GONE : View.VISIBLE);
mGraphView.setClickable(atLeastOneResultIsAvailable);
if (mPrevNumberOfBarsGraph != -1 && mPrevNumberOfBarsGraph != dataToShowOnGraph.length) {
mSelectedBarGraphBarIndex=-1;
mPrevNumberOfBarsGraph=dataToShowOnGraph.length;
onBarTapped(dataToShowOnGraph.length - 1);
mGraphView.highlightBar(dataToShowOnGraph.length - 1);
return;
}
mPrevNumberOfBarsGraph=dataToShowOnGraph.length;
int barSelectedOnGraph;
if (mSelectedBarGraphBarIndex == -1) {
barSelectedOnGraph=dataToShowOnGraph.length - 1;
}
 else if (mSelectedBarGraphBarIndex < dataToShowOnGraph.length) {
barSelectedOnGraph=mSelectedBarGraphBarIndex;
}
 else {
barSelectedOnGraph=dataToShowOnGraph.length - 1;
mSelectedBarGraphBarIndex=barSelectedOnGraph;
}
updateUIBelowTheGraph(barSelectedOnGraph);
mGraphView.highlightBar(barSelectedOnGraph);
}