Program: 146474
Project: 146474
Buggy source:
/** 
 * Creates views for charts
 * @param inflater Inflater to be used for creating views
 */
private void refreshChartViews(LayoutInflater inflater){
  LinearLayout chartsContainer=(LinearLayout)mRootView.findViewById(R.id.ChartsContainer);
  chartsContainer.removeAllViews();
  mCharts=new HashMap<>();
  SharedPreferences sh=PreferenceManager.getDefaultSharedPreferences(getActivity());
  Set<String> hashSet=sh.getStringSet("String_Node_Str",new HashSet<String>());
  LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
  lp.gravity=Gravity.CENTER;
  TextView noCharts=new TextView(getActivity());
  noCharts.setLayoutParams(lp);
  noCharts.setGravity(Gravity.CENTER);
  noCharts.setText("String_Node_Str");
  noCharts.setTypeface(Typeface.DEFAULT_BOLD);
  if (hashSet.size() == 0) {
    chartsContainer.addView(noCharts);
  }
  String[] pairs=hashSet.toArray(new String[hashSet.size()]);
  Arrays.sort(pairs);
  for (  String x : pairs) {
    View element=inflater.inflate(R.layout.chart_item,chartsContainer,false);
    chartsContainer.addView(element);
    mCharts.put(x,element);
  }
  CompoundButton.OnCheckedChangeListener IndicatorListener=new CompoundButton.OnCheckedChangeListener(){
    @Override public void onCheckedChanged(    CompoundButton buttonView,    boolean isChecked){
      ViewGroup viewGroup;
      if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        viewGroup=(ViewGroup)buttonView.getParent().getParent().getParent();
      }
 else {
        viewGroup=(ViewGroup)buttonView.getParent();
      }
      StockChartView stockChartView=(StockChartView)viewGroup.findViewById(R.id.StockChartView);
      IndicatorManager iManager=stockChartView.getIndicatorManager();
      if (stockChartView.findSeriesByName("String_Node_Str") != null) {
        if (isChecked) {
switch (buttonView.getId()) {
case R.id.enableEMAIndicator:
            iManager.addEma(stockChartView.findSeriesByName("String_Node_Str"),0);
          break;
case R.id.enableMACDIndicator:
        iManager.addMacd(stockChartView.findSeriesByName("String_Node_Str"),0);
      break;
case R.id.enableRSIIndicator:
    iManager.addRsi(stockChartView.findSeriesByName("String_Node_Str"),0);
  break;
case R.id.enableSMAIndicator:
iManager.addSma(stockChartView.findSeriesByName("String_Node_Str"),0);
break;
default :
break;
}
stockChartView.recalcIndicators();
stockChartView.recalc();
stockChartView.invalidate();
}
 else {
List<AbstractIndicator> indicators=stockChartView.getIndicatorManager().getIndicators();
for (AbstractIndicator x : indicators) {
switch (buttonView.getId()) {
case R.id.enableEMAIndicator:
if (x instanceof EmaIndicator) {
stockChartView.getIndicatorManager().removeIndicator(x);
}
break;
case R.id.enableMACDIndicator:
if (x instanceof MacdIndicator) {
stockChartView.getIndicatorManager().removeIndicator(x);
}
break;
case R.id.enableRSIIndicator:
if (x instanceof RsiIndicator) {
stockChartView.getIndicatorManager().removeIndicator(x);
}
break;
case R.id.enableSMAIndicator:
if (x instanceof SmaIndicator) {
stockChartView.getIndicatorManager().removeIndicator(x);
}
break;
default :
break;
}
}
stockChartView.recalc();
stockChartView.invalidate();
}
}
 else {
SwitchCompat sw=(SwitchCompat)buttonView;
sw.setChecked(!isChecked);
}
}
}
;
for (String x : mCharts.keySet()) {
((SwitchCompat)mCharts.get(x).findViewById(R.id.enableEMAIndicator)).setOnCheckedChangeListener(IndicatorListener);
((SwitchCompat)mCharts.get(x).findViewById(R.id.enableRSIIndicator)).setOnCheckedChangeListener(IndicatorListener);
((SwitchCompat)mCharts.get(x).findViewById(R.id.enableSMAIndicator)).setOnCheckedChangeListener(IndicatorListener);
((SwitchCompat)mCharts.get(x).findViewById(R.id.enableMACDIndicator)).setOnCheckedChangeListener(IndicatorListener);
}
}

Fixed version (ground truth):
/** 
 * Creates views for charts
 * @param inflater Inflater to be used for creating views
 */
private void refreshChartViews(LayoutInflater inflater){
  LinearLayout chartsContainer=(LinearLayout)mRootView.findViewById(R.id.ChartsContainer);
  chartsContainer.removeAllViews();
  mCharts=new HashMap<>();
  SharedPreferences sh=PreferenceManager.getDefaultSharedPreferences(getActivity());
  Set<String> hashSet=sh.getStringSet("String_Node_Str",new HashSet<String>());
  LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
  lp.gravity=Gravity.CENTER;
  TextView noCharts=new TextView(getActivity());
  noCharts.setLayoutParams(lp);
  noCharts.setGravity(Gravity.CENTER);
  noCharts.setText("String_Node_Str");
  noCharts.setTypeface(Typeface.DEFAULT_BOLD);
  if (hashSet.size() == 0) {
    chartsContainer.addView(noCharts);
  }
  String[] pairs=hashSet.toArray(new String[hashSet.size()]);
  Arrays.sort(pairs);
  for (  String x : pairs) {
    View element=inflater.inflate(R.layout.chart_item,chartsContainer,false);
    chartsContainer.addView(element);
    mCharts.put(x,element);
  }
  CompoundButton.OnCheckedChangeListener indicatorChangeStateListener=new CompoundButton.OnCheckedChangeListener(){
    @Override public void onCheckedChanged(    CompoundButton buttonView,    boolean isChecked){
      ViewGroup viewGroup;
      if (getResources().getConfiguration().screenWidthDp >= 350) {
        viewGroup=(ViewGroup)buttonView.getParent().getParent().getParent();
      }
 else {
        viewGroup=(ViewGroup)buttonView.getParent();
      }
      StockChartView stockChartView=(StockChartView)viewGroup.findViewById(R.id.stockChartView);
      IndicatorManager iManager=stockChartView.getIndicatorManager();
      if (stockChartView.findSeriesByName("String_Node_Str") != null) {
        if (isChecked) {
switch (buttonView.getId()) {
case R.id.enableEMAIndicator:
            iManager.addEma(stockChartView.findSeriesByName("String_Node_Str"),0);
          break;
case R.id.enableMACDIndicator:
        iManager.addMacd(stockChartView.findSeriesByName("String_Node_Str"),0);
      break;
case R.id.enableRSIIndicator:
    iManager.addRsi(stockChartView.findSeriesByName("String_Node_Str"),0);
  break;
case R.id.enableSMAIndicator:
iManager.addSma(stockChartView.findSeriesByName("String_Node_Str"),0);
break;
default :
break;
}
stockChartView.recalcIndicators();
stockChartView.recalc();
stockChartView.invalidate();
}
 else {
Iterator<AbstractIndicator> iterator=stockChartView.getIndicatorManager().getIndicators().iterator();
while (iterator.hasNext()) {
AbstractIndicator x=iterator.next();
switch (buttonView.getId()) {
case R.id.enableEMAIndicator:
if (x instanceof EmaIndicator) {
iterator.remove();
stockChartView.getIndicatorManager().removeIndicator(x);
}
break;
case R.id.enableMACDIndicator:
if (x instanceof MacdIndicator) {
iterator.remove();
stockChartView.getIndicatorManager().removeIndicator(x);
}
break;
case R.id.enableRSIIndicator:
if (x instanceof RsiIndicator) {
iterator.remove();
stockChartView.getIndicatorManager().removeIndicator(x);
}
break;
case R.id.enableSMAIndicator:
if (x instanceof SmaIndicator) {
iterator.remove();
stockChartView.getIndicatorManager().removeIndicator(x);
}
break;
default :
break;
}
}
stockChartView.recalc();
stockChartView.invalidate();
}
}
 else {
SwitchCompat sw=(SwitchCompat)buttonView;
sw.setChecked(!isChecked);
}
}
}
;
for (String x : mCharts.keySet()) {
((SwitchCompat)mCharts.get(x).findViewById(R.id.enableEMAIndicator)).setOnCheckedChangeListener(indicatorChangeStateListener);
((SwitchCompat)mCharts.get(x).findViewById(R.id.enableRSIIndicator)).setOnCheckedChangeListener(indicatorChangeStateListener);
((SwitchCompat)mCharts.get(x).findViewById(R.id.enableSMAIndicator)).setOnCheckedChangeListener(indicatorChangeStateListener);
((SwitchCompat)mCharts.get(x).findViewById(R.id.enableMACDIndicator)).setOnCheckedChangeListener(indicatorChangeStateListener);
}
}