Program: 13473
Project: 13473
Buggy source:
protected void updateUI(){
  if (!isAdded()) {
    return;
  }
  if (mVisitsData == null) {
    setupNoResultsUI(false);
    return;
  }
  final VisitModel[] dataToShowOnGraph=getDataToShowOnGraph(mVisitsData);
  if (dataToShowOnGraph == null || dataToShowOnGraph.length == 0) {
    setupNoResultsUI(false);
    return;
  }
  mNoActivtyThisPeriodContainer.setVisibility(View.GONE);
  OverviewLabel selectedStatsType=mOverviewItems[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];
}
final boolean[] weekendDays;
if (getTimeframe() == StatsTimeframe.DAY) {
weekendDays=new boolean[dataToShowOnGraph.length];
}
 else {
weekendDays=null;
}
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 (weekendDays != null) {
SimpleDateFormat from=new SimpleDateFormat(StatsConstants.STATS_INPUT_DATE_FORMAT);
try {
Date date=from.parse(currentItemStatsDate);
Calendar c=Calendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTimeInMillis(date.getTime());
weekendDays[i]=c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY;
}
 catch (ParseException e) {
weekendDays[i]=false;
AppLog.e(AppLog.T.STATS,e);
}
}
}
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().outerColor=getResources().getColor(R.color.grey_lighten_30_translucent_50);
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);
mGraphView.setWeekendDays(weekendDays);
if (mPrevNumberOfBarsGraph != -1 && mPrevNumberOfBarsGraph != dataToShowOnGraph.length) {
mSelectedBarGraphBarIndex=-1;
mPrevNumberOfBarsGraph=dataToShowOnGraph.length;
onBarTapped(getDefaultBarIndex(dataToShowOnGraph));
mGraphView.highlightBar(getDefaultBarIndex(dataToShowOnGraph));
return;
}
mPrevNumberOfBarsGraph=dataToShowOnGraph.length;
int barSelectedOnGraph;
if (mSelectedBarGraphBarIndex == -1) {
barSelectedOnGraph=getDefaultBarIndex(dataToShowOnGraph);
}
 else if (mSelectedBarGraphBarIndex < dataToShowOnGraph.length) {
barSelectedOnGraph=mSelectedBarGraphBarIndex;
}
 else {
barSelectedOnGraph=getDefaultBarIndex(dataToShowOnGraph);
mSelectedBarGraphBarIndex=barSelectedOnGraph;
}
updateUIBelowTheGraph(barSelectedOnGraph);
mGraphView.highlightBar(barSelectedOnGraph);
}

Fixed version (ground truth):
protected void updateUI(){
  if (!isAdded()) {
    return;
  }
  if (mVisitsData == null) {
    setupNoResultsUI(false);
    return;
  }
  final VisitModel[] dataToShowOnGraph=getDataToShowOnGraph(mVisitsData);
  if (dataToShowOnGraph == null || dataToShowOnGraph.length == 0) {
    setupNoResultsUI(false);
    return;
  }
  mNoActivtyThisPeriodContainer.setVisibility(View.GONE);
  OverviewLabel selectedStatsType=mOverviewItems[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];
}
final boolean[] weekendDays;
if (getTimeframe() == StatsTimeframe.DAY) {
weekendDays=new boolean[dataToShowOnGraph.length];
}
 else {
weekendDays=null;
}
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 (weekendDays != null) {
SimpleDateFormat from=new SimpleDateFormat(StatsConstants.STATS_INPUT_DATE_FORMAT,Locale.ROOT);
try {
Date date=from.parse(currentItemStatsDate);
Calendar c=Calendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTimeInMillis(date.getTime());
weekendDays[i]=c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY;
}
 catch (ParseException e) {
weekendDays[i]=false;
AppLog.e(AppLog.T.STATS,e);
}
}
}
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().outerColor=getResources().getColor(R.color.grey_lighten_30_translucent_50);
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);
mGraphView.setWeekendDays(weekendDays);
if (mPrevNumberOfBarsGraph != -1 && mPrevNumberOfBarsGraph != dataToShowOnGraph.length) {
mSelectedBarGraphBarIndex=-1;
mPrevNumberOfBarsGraph=dataToShowOnGraph.length;
onBarTapped(getDefaultBarIndex(dataToShowOnGraph));
mGraphView.highlightBar(getDefaultBarIndex(dataToShowOnGraph));
return;
}
mPrevNumberOfBarsGraph=dataToShowOnGraph.length;
int barSelectedOnGraph;
if (mSelectedBarGraphBarIndex == -1) {
barSelectedOnGraph=getDefaultBarIndex(dataToShowOnGraph);
}
 else if (mSelectedBarGraphBarIndex < dataToShowOnGraph.length) {
barSelectedOnGraph=mSelectedBarGraphBarIndex;
}
 else {
barSelectedOnGraph=getDefaultBarIndex(dataToShowOnGraph);
mSelectedBarGraphBarIndex=barSelectedOnGraph;
}
updateUIBelowTheGraph(barSelectedOnGraph);
mGraphView.highlightBar(barSelectedOnGraph);
}