Program: 180865
Project: 180865
Buggy source:
/** 
 * Called when voice data integrity check returns
 */
protected void onActivityResult(int requestCode,int resultCode,Intent data){
  if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
    if (data == null) {
      mEnableDemo=false;
      mVoicesMissing=false;
      updateWidgetState();
      return;
    }
    ArrayList<String> available=data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
    ArrayList<String> unavailable=data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
    if ((available == null) || (unavailable == null)) {
      mEnableDemo=false;
      mVoicesMissing=false;
      updateWidgetState();
      return;
    }
    if (available.size() > 0) {
      if (mTts == null) {
        mTts=new TextToSpeech(this,this);
      }
      ListPreference ttsLanguagePref=(ListPreference)findPreference("String_Node_Str");
      CharSequence[] entries=new CharSequence[available.size()];
      CharSequence[] entryValues=new CharSequence[available.size()];
      for (int i=0; i < available.size(); i++) {
        String[] langCountryVariant=available.get(i).split("String_Node_Str");
        Locale loc=null;
        if (langCountryVariant.length == 1) {
          loc=new Locale(langCountryVariant[0]);
        }
 else         if (langCountryVariant.length == 2) {
          loc=new Locale(langCountryVariant[0],langCountryVariant[1]);
        }
 else         if (langCountryVariant.length == 3) {
          loc=new Locale(langCountryVariant[0],langCountryVariant[1],langCountryVariant[2]);
        }
        if (loc != null) {
          entries[i]=loc.getDisplayName();
          entryValues[i]=available.get(i);
        }
      }
      ttsLanguagePref.setEntries(entries);
      ttsLanguagePref.setEntryValues(entryValues);
      mEnableDemo=true;
      int languageResult=mTts.setLanguage(new Locale(mDefaultLanguage,mDefaultCountry,mDefaultLocVariant));
      if (languageResult < TextToSpeech.LANG_AVAILABLE) {
        Locale currentLocale=Locale.getDefault();
        mDefaultLanguage=currentLocale.getISO3Language();
        mDefaultCountry=currentLocale.getISO3Country();
        mDefaultLocVariant=currentLocale.getVariant();
        languageResult=mTts.setLanguage(new Locale(mDefaultLanguage,mDefaultCountry,mDefaultLocVariant));
        if (languageResult < TextToSpeech.LANG_AVAILABLE) {
          parseLocaleInfo(ttsLanguagePref.getEntryValues()[0].toString());
          mTts.setLanguage(new Locale(mDefaultLanguage,mDefaultCountry,mDefaultLocVariant));
        }
        ContentResolver resolver=getContentResolver();
        Settings.Secure.putString(resolver,TTS_DEFAULT_LANG,mDefaultLanguage);
        Settings.Secure.putString(resolver,TTS_DEFAULT_COUNTRY,mDefaultCountry);
        Settings.Secure.putString(resolver,TTS_DEFAULT_VARIANT,mDefaultLocVariant);
      }
    }
 else {
      mEnableDemo=false;
    }
    if (unavailable.size() > 0) {
      mVoicesMissing=true;
    }
 else {
      mVoicesMissing=false;
    }
    updateWidgetState();
  }
 else   if (requestCode == GET_SAMPLE_TEXT) {
    if (resultCode == TextToSpeech.LANG_AVAILABLE) {
      String sample=getString(R.string.tts_demo);
      if ((data != null) && (data.getStringExtra("String_Node_Str") != null)) {
        sample=data.getStringExtra("String_Node_Str");
      }
      if (mTts != null) {
        mTts.speak(sample,TextToSpeech.QUEUE_FLUSH,null);
      }
    }
 else {
      Log.e(TAG,"String_Node_Str");
    }
  }
}

Fixed version (ground truth):
/** 
 * Called when voice data integrity check returns
 */
protected void onActivityResult(int requestCode,int resultCode,Intent data){
  if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
    if (data == null) {
      mEnableDemo=false;
      mVoicesMissing=false;
      updateWidgetState();
      return;
    }
    ArrayList<String> available=data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
    ArrayList<String> unavailable=data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
    if ((available == null) || (unavailable == null)) {
      mEnableDemo=false;
      mVoicesMissing=false;
      updateWidgetState();
      return;
    }
    if (available.size() > 0) {
      if (mTts == null) {
        mTts=new TextToSpeech(this,this);
      }
      ListPreference ttsLanguagePref=(ListPreference)findPreference("String_Node_Str");
      CharSequence[] entries=new CharSequence[available.size()];
      CharSequence[] entryValues=new CharSequence[available.size()];
      int selectedLanguageIndex=-1;
      String selectedLanguagePref=mDefaultLanguage;
      if (mDefaultCountry.length() > 0) {
        selectedLanguagePref=selectedLanguagePref + LOCALE_DELIMITER + mDefaultCountry;
      }
      if (mDefaultLocVariant.length() > 0) {
        selectedLanguagePref=selectedLanguagePref + LOCALE_DELIMITER + mDefaultLocVariant;
      }
      for (int i=0; i < available.size(); i++) {
        String[] langCountryVariant=available.get(i).split("String_Node_Str");
        Locale loc=null;
        if (langCountryVariant.length == 1) {
          loc=new Locale(langCountryVariant[0]);
        }
 else         if (langCountryVariant.length == 2) {
          loc=new Locale(langCountryVariant[0],langCountryVariant[1]);
        }
 else         if (langCountryVariant.length == 3) {
          loc=new Locale(langCountryVariant[0],langCountryVariant[1],langCountryVariant[2]);
        }
        if (loc != null) {
          entries[i]=loc.getDisplayName();
          entryValues[i]=available.get(i);
          if (entryValues[i].equals(selectedLanguagePref)) {
            selectedLanguageIndex=i;
          }
        }
      }
      ttsLanguagePref.setEntries(entries);
      ttsLanguagePref.setEntryValues(entryValues);
      if (selectedLanguageIndex > -1) {
        ttsLanguagePref.setValueIndex(selectedLanguageIndex);
      }
      mEnableDemo=true;
      int languageResult=mTts.setLanguage(new Locale(mDefaultLanguage,mDefaultCountry,mDefaultLocVariant));
      if (languageResult < TextToSpeech.LANG_AVAILABLE) {
        Locale currentLocale=Locale.getDefault();
        mDefaultLanguage=currentLocale.getISO3Language();
        mDefaultCountry=currentLocale.getISO3Country();
        mDefaultLocVariant=currentLocale.getVariant();
        languageResult=mTts.setLanguage(new Locale(mDefaultLanguage,mDefaultCountry,mDefaultLocVariant));
        if (languageResult < TextToSpeech.LANG_AVAILABLE) {
          parseLocaleInfo(ttsLanguagePref.getEntryValues()[0].toString());
          mTts.setLanguage(new Locale(mDefaultLanguage,mDefaultCountry,mDefaultLocVariant));
        }
        ContentResolver resolver=getContentResolver();
        Settings.Secure.putString(resolver,TTS_DEFAULT_LANG,mDefaultLanguage);
        Settings.Secure.putString(resolver,TTS_DEFAULT_COUNTRY,mDefaultCountry);
        Settings.Secure.putString(resolver,TTS_DEFAULT_VARIANT,mDefaultLocVariant);
      }
    }
 else {
      mEnableDemo=false;
    }
    if (unavailable.size() > 0) {
      mVoicesMissing=true;
    }
 else {
      mVoicesMissing=false;
    }
    updateWidgetState();
  }
 else   if (requestCode == GET_SAMPLE_TEXT) {
    if (resultCode == TextToSpeech.LANG_AVAILABLE) {
      String sample=getString(R.string.tts_demo);
      if ((data != null) && (data.getStringExtra("String_Node_Str") != null)) {
        sample=data.getStringExtra("String_Node_Str");
      }
      if (mTts != null) {
        mTts.speak(sample,TextToSpeech.QUEUE_FLUSH,null);
      }
    }
 else {
      Log.e(TAG,"String_Node_Str");
    }
  }
}