nus-yam/ex-repair huggingface dataset:
Program: 184063
Project: 184063
Buggy source:
/** 
 * Format the given phone number using  {@link PhoneNumberUtils#formatNumber(android.text.Editable,int)}. This helper method uses   {@link #sEditable} and {@link #sFormattingType} toprevent allocations between multiple calls. <p> Because of the shared  {@link #sEditable} builder, <b>this method is notthread safe</b>, and should only be called from the GUI thread. <p> If the given String object is null or empty, return an empty String.
 */
private String formatPhoneNumber(String number){
  if (!TextUtils.isEmpty(number)) {
    return "String_Node_Str";
  }
  if (sFormattingType == FORMATTING_TYPE_INVALID) {
    sFormattingType=PhoneNumberUtils.getFormatTypeForLocale(Locale.getDefault());
  }
  sEditable.clear();
  sEditable.append(number);
  PhoneNumberUtils.formatNumber(sEditable,sFormattingType);
  return sEditable.toString();
}

Fixed version (ground truth):
/** 
 * Format the given phone number using  {@link PhoneNumberUtils#formatNumber(android.text.Editable,int)}. This helper method uses   {@link #sEditable} and {@link #sFormattingType} toprevent allocations between multiple calls. <p> Because of the shared  {@link #sEditable} builder, <b>this method is notthread safe</b>, and should only be called from the GUI thread. <p> If the given String object is null or empty, return an empty String.
 */
private String formatPhoneNumber(String number){
  if (TextUtils.isEmpty(number)) {
    return "String_Node_Str";
  }
  if (sFormattingType == FORMATTING_TYPE_INVALID) {
    sFormattingType=PhoneNumberUtils.getFormatTypeForLocale(Locale.getDefault());
  }
  sEditable.clear();
  sEditable.append(number);
  PhoneNumberUtils.formatNumber(sEditable,sFormattingType);
  return sEditable.toString();
}
Program: 184064
Project: 184064
Buggy source:
/** 
 * Parse a specific entry from the given   {@link Bundle} and insert into thegiven  {@link EntityDelta}. Silently skips the insert when missing value or no valid   {@link EditType} found.
 * @param typeExtra {@link Bundle} key that holds the incoming{@link EditType#rawValue} value.
 * @param valueExtra {@link Bundle} key that holds the incoming value.
 * @param valueColumn Column to write value into {@link ValuesDelta}.
 */
public static void parseExtras(EntityDelta state,DataKind kind,Bundle extras,String typeExtra,String valueExtra,String valueColumn){
  final CharSequence value=extras.getCharSequence(valueExtra);
  if (kind == null)   return;
  final boolean canInsert=EntityModifier.canInsert(state,kind);
  final boolean validValue=(value != null && TextUtils.isGraphic(value));
  if (!validValue || !canInsert)   return;
  final int typeValue=extras.getInt(typeExtra,BaseTypes.TYPE_CUSTOM);
  final EditType editType=EntityModifier.getBestValidType(state,kind,true,typeValue);
  final ValuesDelta child=EntityModifier.insertChild(state,kind,editType);
  child.put(valueColumn,value.toString());
  if (editType != null && editType.customColumn != null) {
    final CharSequence customType=extras.getCharSequence(typeExtra);
    child.put(editType.customColumn,customType.toString());
  }
}

Fixed version (ground truth):
/** 
 * Parse a specific entry from the given   {@link Bundle} and insert into thegiven  {@link EntityDelta}. Silently skips the insert when missing value or no valid   {@link EditType} found.
 * @param typeExtra {@link Bundle} key that holds the incoming{@link EditType#rawValue} value.
 * @param valueExtra {@link Bundle} key that holds the incoming value.
 * @param valueColumn Column to write value into {@link ValuesDelta}.
 */
public static void parseExtras(EntityDelta state,DataKind kind,Bundle extras,String typeExtra,String valueExtra,String valueColumn){
  final CharSequence value=extras.getCharSequence(valueExtra);
  if (kind == null)   return;
  final boolean canInsert=EntityModifier.canInsert(state,kind);
  final boolean validValue=(value != null && TextUtils.isGraphic(value));
  if (!validValue || !canInsert)   return;
  final int typeValue=extras.getInt(typeExtra,BaseTypes.TYPE_CUSTOM);
  final EditType editType=EntityModifier.getBestValidType(state,kind,true,typeValue);
  final ValuesDelta child=EntityModifier.insertChild(state,kind,editType);
  child.put(valueColumn,value.toString());
  if (editType != null && editType.customColumn != null) {
    final String customType=extras.getString(typeExtra);
    child.put(editType.customColumn,customType);
  }
}
Program: 184065
Project: 184065
Buggy source:
/** 
 * Find the best   {@link EditType} for a potential insert. The "best" is thefirst primary type that doesn't already exist. When all valid types exist, we pick the last valid option.
 */
public static EditType getBestValidType(EntityDelta state,DataKind kind,boolean includeSecondary,int exactValue){
  if (kind.typeColumn == null)   return null;
  final SparseIntArray typeCount=getTypeFrequencies(state,kind);
  final ArrayList<EditType> validTypes=getValidTypes(state,kind,null,includeSecondary,typeCount);
  if (validTypes.size() == 0)   return null;
  final EditType lastType=validTypes.get(validTypes.size() - 1);
  Iterator<EditType> iterator=validTypes.iterator();
  while (iterator.hasNext()) {
    final EditType type=iterator.next();
    final int count=typeCount.get(type.rawValue);
    if (count == exactValue) {
      return type;
    }
    if (count > 0) {
      iterator.remove();
    }
  }
  if (validTypes.size() > 0) {
    return validTypes.get(0);
  }
 else {
    return lastType;
  }
}

Fixed version (ground truth):
/** 
 * Find the best   {@link EditType} for a potential insert. The "best" is thefirst primary type that doesn't already exist. When all valid types exist, we pick the last valid option.
 */
public static EditType getBestValidType(EntityDelta state,DataKind kind,boolean includeSecondary,int exactValue){
  if (kind.typeColumn == null)   return null;
  final SparseIntArray typeCount=getTypeFrequencies(state,kind);
  final ArrayList<EditType> validTypes=getValidTypes(state,kind,null,includeSecondary,typeCount);
  if (validTypes.size() == 0)   return null;
  final EditType lastType=validTypes.get(validTypes.size() - 1);
  Iterator<EditType> iterator=validTypes.iterator();
  while (iterator.hasNext()) {
    final EditType type=iterator.next();
    final int count=typeCount.get(type.rawValue);
    if (exactValue == type.rawValue) {
      return type;
    }
    if (count > 0) {
      iterator.remove();
    }
  }
  if (validTypes.size() > 0) {
    return validTypes.get(0);
  }
 else {
    return lastType;
  }
}
Program: 184066
Project: 184066
Buggy source:
/** 
 * Find   {@link RawContacts#_ID} of the requested {@link EntityDelta}.
 */
public long getRawContactId(int index){
  if (index >= 0 && index < this.size()) {
    final EntityDelta delta=this.get(index);
    return delta.getValues().getAsLong(RawContacts._ID);
  }
 else {
    return 0;
  }
}

Fixed version (ground truth):
/** 
 * Find   {@link RawContacts#_ID} of the requested {@link EntityDelta}.
 */
public long getRawContactId(int index){
  if (index >= 0 && index < this.size()) {
    final EntityDelta delta=this.get(index);
    final ValuesDelta values=delta.getValues();
    if (values.isVisible()) {
      return values.getAsLong(RawContacts._ID);
    }
  }
  return 0;
}
Program: 184067
Project: 184067
Buggy source:
/** 
 * Find index of given   {@link RawContacts#_ID} when present.
 */
public int indexOfRawContactId(long rawContactId){
  final int size=this.size();
  for (int i=0; i < size; i++) {
    final long currentId=getRawContactId(i);
    if (currentId == rawContactId) {
      return i;
    }
  }
  return -1;
}

Fixed version (ground truth):
/** 
 * Find index of given   {@link RawContacts#_ID} when present.
 */
public int indexOfRawContactId(Long rawContactId){
  final int size=this.size();
  for (int i=0; i < size; i++) {
    final long currentId=getRawContactId(i);
    if (currentId == rawContactId) {
      return i;
    }
  }
  return -1;
}
Program: 184068
Project: 184068
Buggy source:
@Override protected void onRestoreInstanceState(Bundle savedInstanceState){
  mState=savedInstanceState.<EntitySet>getParcelable(KEY_EDIT_STATE);
  bindTabs();
  bindHeader();
  if (hasValidState()) {
    final long selectedId=savedInstanceState.getLong(KEY_SELECTED_RAW_CONTACT);
    setSelectedRawContactId(selectedId);
  }
  super.onRestoreInstanceState(savedInstanceState);
}

Fixed version (ground truth):
@Override protected void onRestoreInstanceState(Bundle savedInstanceState){
  mState=savedInstanceState.<EntitySet>getParcelable(KEY_EDIT_STATE);
  bindTabs();
  bindHeader();
  if (hasValidState()) {
    final Long selectedId=savedInstanceState.getLong(KEY_SELECTED_RAW_CONTACT);
    setSelectedRawContactId(selectedId);
  }
  super.onRestoreInstanceState(savedInstanceState);
}
Program: 184069
Project: 184069
Buggy source:
/** 
 * {@inheritDoc} 
 */
public void onTabSelectionChanged(int tabIndex,boolean clicked){
  if (!hasValidState())   return;
  if (tabIndex < 0 || tabIndex >= mState.size())   return;
  final EntityDelta entity=mState.get(tabIndex);
  final String accountType=entity.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
  final Sources sources=Sources.getInstance(this);
  final ContactsSource source=sources.getInflatedSource(accountType,ContactsSource.LEVEL_CONSTRAINTS);
  mEditor.setState(entity,source);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public void onTabSelectionChanged(int tabIndex,boolean clicked){
  if (!hasValidState())   return;
  final EntityDelta entity=this.getSelectedEntityDelta();
  final String accountType=entity.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
  final Sources sources=Sources.getInstance(this);
  final ContactsSource source=sources.getInflatedSource(accountType,ContactsSource.LEVEL_CONSTRAINTS);
  mEditor.setState(entity,source);
}
Program: 184070
Project: 184070
Buggy source:
/** 
 * {@inheritDoc} 
 */
public void onPhotoLongClick(View view){
  if (!hasValidState())   return;
  this.createPhotoDialog().show();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public void onPhotoLongClick(View view){
  if (!hasValidState())   return;
  showAndManageDialog(createPhotoDialog());
}
Program: 184071
Project: 184071
Buggy source:
/** 
 * Set the selected tab based on the given   {@link RawContacts#_ID}.
 */
protected void setSelectedRawContactId(long rawContactId){
  final int index=mState.indexOfRawContactId(rawContactId);
  mTabWidget.setCurrentTab(index);
}

Fixed version (ground truth):
/** 
 * Set the selected tab based on the given   {@link RawContacts#_ID}.
 */
protected void setSelectedRawContactId(Long rawContactId){
  int tabIndex=0;
  final int size=mTabRawContacts.size();
  for (int i=0; i < size; i++) {
    if (mTabRawContacts.valueAt(i) == rawContactId) {
      tabIndex=i;
      break;
    }
  }
  mTabWidget.setCurrentTab(tabIndex);
  this.onTabSelectionChanged(tabIndex,false);
}
Program: 184072
Project: 184072
Buggy source:
@Override protected void onPostExecute(EditContactActivity target,AlertDialog.Builder result){
  result.create().show();
}

Fixed version (ground truth):
@Override protected void onPostExecute(EditContactActivity target,AlertDialog.Builder result){
  target.showAndManageDialog(result.create());
}
Program: 184073
Project: 184073
Buggy source:
private Dialog createDeleteDialog(){
  final AlertDialog.Builder builder=new AlertDialog.Builder(this);
  builder.setTitle(R.string.deleteConfirmation_title);
  builder.setIcon(android.R.drawable.ic_dialog_alert);
  builder.setMessage(R.string.deleteConfirmation);
  builder.setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int which){
      final int index=mTabWidget.getCurrentTab();
      final EntityDelta delta=mState.get(index);
      delta.markDeleted();
      bindTabs();
      bindHeader();
    }
  }
);
  builder.setNegativeButton(android.R.string.cancel,null);
  builder.setCancelable(false);
  return builder.create();
}

Fixed version (ground truth):
private Dialog createDeleteDialog(){
  final AlertDialog.Builder builder=new AlertDialog.Builder(this);
  builder.setTitle(R.string.deleteConfirmation_title);
  builder.setIcon(android.R.drawable.ic_dialog_alert);
  builder.setMessage(R.string.deleteConfirmation);
  builder.setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int which){
      final EntityDelta delta=getSelectedEntityDelta();
      delta.markDeleted();
      bindTabs();
      bindHeader();
    }
  }
);
  builder.setNegativeButton(android.R.string.cancel,null);
  builder.setCancelable(false);
  return builder.create();
}
Program: 184074
Project: 184074
Buggy source:
@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  final Context context=this;
  final LayoutInflater inflater=this.getLayoutInflater();
  final Intent intent=getIntent();
  final String action=intent.getAction();
  final Bundle extras=intent.getExtras();
  setContentView(R.layout.act_edit);
  mHeader=(ContactHeaderWidget)this.findViewById(R.id.contact_header_widget);
  mHeader.setContactHeaderListener(this);
  mHeader.showStar(true);
  mTabWidget=(ScrollingTabWidget)this.findViewById(R.id.tab_widget);
  mTabWidget.setTabSelectionListener(this);
  mEditor=(ContactEditorView)this.findViewById(android.R.id.tabcontent);
  mEditor.getPhotoEditor().setEditorListener(this);
  findViewById(R.id.btn_done).setOnClickListener(this);
  findViewById(R.id.btn_discard).setOnClickListener(this);
  if (Intent.ACTION_EDIT.equals(action) && icicle == null) {
    new QueryEntitiesTask(this).execute(intent);
  }
 else   if (Intent.ACTION_INSERT.equals(action) && icicle == null) {
    doAddAction();
  }
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  final Context context=this;
  final LayoutInflater inflater=this.getLayoutInflater();
  final Intent intent=getIntent();
  final String action=intent.getAction();
  final Bundle extras=intent.getExtras();
  setContentView(R.layout.act_edit);
  mHeader=(ContactHeaderWidget)this.findViewById(R.id.contact_header_widget);
  mHeader.setContactHeaderListener(this);
  mHeader.showStar(true);
  mTabWidget=(ScrollingTabWidget)this.findViewById(R.id.tab_widget);
  mTabWidget.setTabSelectionListener(this);
  mEditor=(ContactEditorView)this.findViewById(android.R.id.tabcontent);
  mEditor.getPhotoEditor().setEditorListener(this);
  findViewById(R.id.btn_done).setOnClickListener(this);
  findViewById(R.id.btn_discard).setOnClickListener(this);
  final boolean hasIncomingState=icicle != null && icicle.containsKey(KEY_EDIT_STATE);
  if (Intent.ACTION_EDIT.equals(action) && !hasIncomingState) {
    new QueryEntitiesTask(this).execute(intent);
  }
 else   if (Intent.ACTION_INSERT.equals(action) && !hasIncomingState) {
    doAddAction();
  }
}
Program: 184075
Project: 184075
Buggy source:
/** 
 * Rebuild tabs to match our underlying   {@link #mState} object, usuallycalled once we've parsed  {@link Entity} data or have inserted a new{@link RawContacts}.
 */
protected void bindTabs(){
  if (!hasValidState())   return;
  final Sources sources=Sources.getInstance(this);
  int selectedTab=0;
  mTabWidget.removeAllTabs();
  for (  EntityDelta entity : mState) {
    ValuesDelta values=entity.getValues();
    final String accountType=values.getAsString(RawContacts.ACCOUNT_TYPE);
    final Long rawContactId=values.getAsLong(RawContacts._ID);
    final ContactsSource source=sources.getInflatedSource(accountType,ContactsSource.LEVEL_CONSTRAINTS);
    final View tabView=ContactsUtils.createTabIndicatorView(mTabWidget.getTabParent(),source);
    mTabWidget.addTab(tabView);
  }
  if (mState.size() > 0) {
    mTabWidget.setCurrentTab(selectedTab);
    this.onTabSelectionChanged(selectedTab,false);
  }
  mEditor.setVisibility(View.VISIBLE);
}

Fixed version (ground truth):
/** 
 * Rebuild tabs to match our underlying   {@link #mState} object, usuallycalled once we've parsed  {@link Entity} data or have inserted a new{@link RawContacts}.
 */
protected void bindTabs(){
  if (!hasValidState())   return;
  final Sources sources=Sources.getInstance(this);
  final Long selectedRawContactId=this.getSelectedRawContactId();
  mTabWidget.removeAllTabs();
  mTabRawContacts.clear();
  for (  EntityDelta entity : mState) {
    final ValuesDelta values=entity.getValues();
    if (!values.isVisible())     continue;
    final String accountType=values.getAsString(RawContacts.ACCOUNT_TYPE);
    final Long rawContactId=values.getAsLong(RawContacts._ID);
    final ContactsSource source=sources.getInflatedSource(accountType,ContactsSource.LEVEL_CONSTRAINTS);
    final int tabIndex=mTabWidget.getTabCount();
    final View tabView=ContactsUtils.createTabIndicatorView(mTabWidget.getTabParent(),source);
    mTabWidget.addTab(tabView);
    mTabRawContacts.put(tabIndex,rawContactId);
  }
  final boolean hasActiveTabs=mTabWidget.getTabCount() > 0;
  if (hasActiveTabs) {
    this.setSelectedRawContactId(selectedRawContactId);
  }
 else {
    this.doSaveAction();
  }
  mEditor.setVisibility(View.VISIBLE);
}
Program: 184076
Project: 184076
Buggy source:
/** 
 * Delete the entire contact currently being edited, which usually asks for user confirmation before continuing.
 */
private boolean doDeleteAction(){
  if (!hasValidState())   return false;
  this.createDeleteDialog().show();
  return true;
}

Fixed version (ground truth):
/** 
 * Delete the entire contact currently being edited, which usually asks for user confirmation before continuing.
 */
private boolean doDeleteAction(){
  if (!hasValidState())   return false;
  showAndManageDialog(createDeleteDialog());
  return true;
}
Program: 184077
Project: 184077
Buggy source:
/** 
 * Return the   {@link RawContacts#_ID} of the currently selected tab.
 */
protected long getSelectedRawContactId(){
  final int index=mTabWidget.getCurrentTab();
  return mState.getRawContactId(index);
}

Fixed version (ground truth):
/** 
 * Return the   {@link RawContacts#_ID} of the currently selected tab.
 */
protected Long getSelectedRawContactId(){
  final int tabIndex=mTabWidget.getCurrentTab();
  return this.mTabRawContacts.get(tabIndex);
}
Program: 184078
Project: 184078
Buggy source:
/** 
 * {@inheritDoc} 
 */
public void onDisplayNameLongClick(View view){
  if (!hasValidState())   return;
  this.createNameDialog().show();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public void onDisplayNameLongClick(View view){
  if (!hasValidState())   return;
  showAndManageDialog(createNameDialog());
}
Program: 184079
Project: 184079
Buggy source:
/** 
 * Saves or creates the contact based on the mode, and if successful finishes the activity.
 */
private boolean doSaveAction(){
  if (!hasValidState())   return false;
  final int selectedTab=mTabWidget.getCurrentTab();
  final long rawContactId=mState.getRawContactId(selectedTab);
  if (rawContactId != -1) {
    final Intent intent=new Intent();
    intent.putExtra(ViewContactActivity.RAW_CONTACT_ID_EXTRA,rawContactId);
    setResult(RESULT_OK,intent);
  }
  try {
    final PersistTask task=new PersistTask(this);
    task.execute(mState);
    task.get(TIMEOUT_PERSIST,TimeUnit.MILLISECONDS);
  }
 catch (  InterruptedException e) {
  }
catch (  TimeoutException e) {
  }
catch (  ExecutionException e) {
  }
  this.finish();
  return true;
}

Fixed version (ground truth):
/** 
 * Saves or creates the contact based on the mode, and if successful finishes the activity.
 */
private boolean doSaveAction(){
  if (!hasValidState())   return false;
  final Long rawContactId=this.getSelectedRawContactId();
  if (rawContactId != null) {
    final Intent intent=new Intent();
    intent.putExtra(ViewContactActivity.RAW_CONTACT_ID_EXTRA,(long)rawContactId);
    setResult(RESULT_OK,intent);
  }
  try {
    final PersistTask task=new PersistTask(this);
    task.execute(mState);
    task.get(TIMEOUT_PERSIST,TimeUnit.MILLISECONDS);
  }
 catch (  InterruptedException e) {
  }
catch (  TimeoutException e) {
  }
catch (  ExecutionException e) {
  }
  this.finish();
  return true;
}
Program: 184080
Project: 184080
Buggy source:
/** 
 * Parse a specific entry from the given   {@link Bundle} and insert into thegiven  {@link EntityDelta}. Silently skips the insert when missing value or no valid   {@link EditType} found.
 * @param typeExtra {@link Bundle} key that holds the incoming{@link EditType#rawValue} value.
 * @param valueExtra {@link Bundle} key that holds the incoming value.
 * @param valueColumn Column to write value into {@link ValuesDelta}.
 */
public static void parseExtras(EntityDelta state,DataKind kind,Bundle extras,String typeExtra,String valueExtra,String valueColumn){
  final CharSequence value=extras.getCharSequence(valueExtra);
  if (kind == null)   return;
  final boolean canInsert=EntityModifier.canInsert(state,kind);
  final boolean validValue=(value != null && TextUtils.isGraphic(value));
  if (!validValue || !canInsert)   return;
  final int typeValue=extras.getInt(typeExtra,BaseTypes.TYPE_CUSTOM);
  final EditType editType=EntityModifier.getBestValidType(state,kind,true,typeValue);
  final ValuesDelta child=EntityModifier.insertChild(state,kind,editType);
  child.put(valueColumn,value.toString());
  if (editType != null && editType.customColumn != null) {
    final CharSequence customType=extras.getCharSequence(typeExtra);
    child.put(editType.customColumn,customType.toString());
  }
}

Fixed version (ground truth):
/** 
 * Parse a specific entry from the given   {@link Bundle} and insert into thegiven  {@link EntityDelta}. Silently skips the insert when missing value or no valid   {@link EditType} found.
 * @param typeExtra {@link Bundle} key that holds the incoming{@link EditType#rawValue} value.
 * @param valueExtra {@link Bundle} key that holds the incoming value.
 * @param valueColumn Column to write value into {@link ValuesDelta}.
 */
public static void parseExtras(EntityDelta state,DataKind kind,Bundle extras,String typeExtra,String valueExtra,String valueColumn){
  final CharSequence value=extras.getCharSequence(valueExtra);
  if (kind == null)   return;
  final boolean canInsert=EntityModifier.canInsert(state,kind);
  final boolean validValue=(value != null && TextUtils.isGraphic(value));
  if (!validValue || !canInsert)   return;
  final int typeValue=extras.getInt(typeExtra,BaseTypes.TYPE_CUSTOM);
  final EditType editType=EntityModifier.getBestValidType(state,kind,true,typeValue);
  final ValuesDelta child=EntityModifier.insertChild(state,kind,editType);
  child.put(valueColumn,value.toString());
  if (editType != null && editType.customColumn != null) {
    final String customType=extras.getString(typeExtra);
    child.put(editType.customColumn,customType);
  }
}
Program: 184081
Project: 184081
Buggy source:
/** 
 * Find the best   {@link EditType} for a potential insert. The "best" is thefirst primary type that doesn't already exist. When all valid types exist, we pick the last valid option.
 */
public static EditType getBestValidType(EntityDelta state,DataKind kind,boolean includeSecondary,int exactValue){
  if (kind.typeColumn == null)   return null;
  final SparseIntArray typeCount=getTypeFrequencies(state,kind);
  final ArrayList<EditType> validTypes=getValidTypes(state,kind,null,includeSecondary,typeCount);
  if (validTypes.size() == 0)   return null;
  final EditType lastType=validTypes.get(validTypes.size() - 1);
  Iterator<EditType> iterator=validTypes.iterator();
  while (iterator.hasNext()) {
    final EditType type=iterator.next();
    final int count=typeCount.get(type.rawValue);
    if (count == exactValue) {
      return type;
    }
    if (count > 0) {
      iterator.remove();
    }
  }
  if (validTypes.size() > 0) {
    return validTypes.get(0);
  }
 else {
    return lastType;
  }
}

Fixed version (ground truth):
/** 
 * Find the best   {@link EditType} for a potential insert. The "best" is thefirst primary type that doesn't already exist. When all valid types exist, we pick the last valid option.
 */
public static EditType getBestValidType(EntityDelta state,DataKind kind,boolean includeSecondary,int exactValue){
  if (kind.typeColumn == null)   return null;
  final SparseIntArray typeCount=getTypeFrequencies(state,kind);
  final ArrayList<EditType> validTypes=getValidTypes(state,kind,null,includeSecondary,typeCount);
  if (validTypes.size() == 0)   return null;
  final EditType lastType=validTypes.get(validTypes.size() - 1);
  Iterator<EditType> iterator=validTypes.iterator();
  while (iterator.hasNext()) {
    final EditType type=iterator.next();
    final int count=typeCount.get(type.rawValue);
    if (exactValue == type.rawValue) {
      return type;
    }
    if (count > 0) {
      iterator.remove();
    }
  }
  if (validTypes.size() > 0) {
    return validTypes.get(0);
  }
 else {
    return lastType;
  }
}
Program: 184082
Project: 184082
Buggy source:
/** 
 * Find   {@link RawContacts#_ID} of the requested {@link EntityDelta}.
 */
public long getRawContactId(int index){
  if (index >= 0 && index < this.size()) {
    final EntityDelta delta=this.get(index);
    return delta.getValues().getAsLong(RawContacts._ID);
  }
 else {
    return 0;
  }
}

Fixed version (ground truth):
/** 
 * Find   {@link RawContacts#_ID} of the requested {@link EntityDelta}.
 */
public long getRawContactId(int index){
  if (index >= 0 && index < this.size()) {
    final EntityDelta delta=this.get(index);
    final ValuesDelta values=delta.getValues();
    if (values.isVisible()) {
      return values.getAsLong(RawContacts._ID);
    }
  }
  return 0;
}
Program: 184083
Project: 184083
Buggy source:
/** 
 * Find index of given   {@link RawContacts#_ID} when present.
 */
public int indexOfRawContactId(long rawContactId){
  final int size=this.size();
  for (int i=0; i < size; i++) {
    final long currentId=getRawContactId(i);
    if (currentId == rawContactId) {
      return i;
    }
  }
  return -1;
}

Fixed version (ground truth):
/** 
 * Find index of given   {@link RawContacts#_ID} when present.
 */
public int indexOfRawContactId(Long rawContactId){
  final int size=this.size();
  for (int i=0; i < size; i++) {
    final long currentId=getRawContactId(i);
    if (currentId == rawContactId) {
      return i;
    }
  }
  return -1;
}
Program: 184084
Project: 184084
Buggy source:
@Override protected void onRestoreInstanceState(Bundle savedInstanceState){
  mState=savedInstanceState.<EntitySet>getParcelable(KEY_EDIT_STATE);
  bindTabs();
  bindHeader();
  if (hasValidState()) {
    final long selectedId=savedInstanceState.getLong(KEY_SELECTED_RAW_CONTACT);
    setSelectedRawContactId(selectedId);
  }
  super.onRestoreInstanceState(savedInstanceState);
}

Fixed version (ground truth):
@Override protected void onRestoreInstanceState(Bundle savedInstanceState){
  mState=savedInstanceState.<EntitySet>getParcelable(KEY_EDIT_STATE);
  bindTabs();
  bindHeader();
  if (hasValidState()) {
    final Long selectedId=savedInstanceState.getLong(KEY_SELECTED_RAW_CONTACT);
    setSelectedRawContactId(selectedId);
  }
  super.onRestoreInstanceState(savedInstanceState);
}
Program: 184085
Project: 184085
Buggy source:
/** 
 * {@inheritDoc} 
 */
public void onTabSelectionChanged(int tabIndex,boolean clicked){
  if (!hasValidState())   return;
  if (tabIndex < 0 || tabIndex >= mState.size())   return;
  final EntityDelta entity=mState.get(tabIndex);
  final String accountType=entity.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
  final Sources sources=Sources.getInstance(this);
  final ContactsSource source=sources.getInflatedSource(accountType,ContactsSource.LEVEL_CONSTRAINTS);
  mEditor.setState(entity,source);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public void onTabSelectionChanged(int tabIndex,boolean clicked){
  if (!hasValidState())   return;
  final EntityDelta entity=this.getSelectedEntityDelta();
  final String accountType=entity.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
  final Sources sources=Sources.getInstance(this);
  final ContactsSource source=sources.getInflatedSource(accountType,ContactsSource.LEVEL_CONSTRAINTS);
  mEditor.setState(entity,source);
}
Program: 184086
Project: 184086
Buggy source:
/** 
 * {@inheritDoc} 
 */
public void onPhotoLongClick(View view){
  if (!hasValidState())   return;
  this.createPhotoDialog().show();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public void onPhotoLongClick(View view){
  if (!hasValidState())   return;
  showAndManageDialog(createPhotoDialog());
}
Program: 184087
Project: 184087
Buggy source:
/** 
 * Set the selected tab based on the given   {@link RawContacts#_ID}.
 */
protected void setSelectedRawContactId(long rawContactId){
  final int index=mState.indexOfRawContactId(rawContactId);
  mTabWidget.setCurrentTab(index);
}

Fixed version (ground truth):
/** 
 * Set the selected tab based on the given   {@link RawContacts#_ID}.
 */
protected void setSelectedRawContactId(Long rawContactId){
  int tabIndex=0;
  final int size=mTabRawContacts.size();
  for (int i=0; i < size; i++) {
    if (mTabRawContacts.valueAt(i) == rawContactId) {
      tabIndex=i;
      break;
    }
  }
  mTabWidget.setCurrentTab(tabIndex);
  this.onTabSelectionChanged(tabIndex,false);
}
Program: 184088
Project: 184088
Buggy source:
@Override protected void onPostExecute(EditContactActivity target,AlertDialog.Builder result){
  result.create().show();
}

Fixed version (ground truth):
@Override protected void onPostExecute(EditContactActivity target,AlertDialog.Builder result){
  target.showAndManageDialog(result.create());
}
Program: 184089
Project: 184089
Buggy source:
private Dialog createDeleteDialog(){
  final AlertDialog.Builder builder=new AlertDialog.Builder(this);
  builder.setTitle(R.string.deleteConfirmation_title);
  builder.setIcon(android.R.drawable.ic_dialog_alert);
  builder.setMessage(R.string.deleteConfirmation);
  builder.setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int which){
      final int index=mTabWidget.getCurrentTab();
      final EntityDelta delta=mState.get(index);
      delta.markDeleted();
      bindTabs();
      bindHeader();
    }
  }
);
  builder.setNegativeButton(android.R.string.cancel,null);
  builder.setCancelable(false);
  return builder.create();
}

Fixed version (ground truth):
private Dialog createDeleteDialog(){
  final AlertDialog.Builder builder=new AlertDialog.Builder(this);
  builder.setTitle(R.string.deleteConfirmation_title);
  builder.setIcon(android.R.drawable.ic_dialog_alert);
  builder.setMessage(R.string.deleteConfirmation);
  builder.setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int which){
      final EntityDelta delta=getSelectedEntityDelta();
      delta.markDeleted();
      bindTabs();
      bindHeader();
    }
  }
);
  builder.setNegativeButton(android.R.string.cancel,null);
  builder.setCancelable(false);
  return builder.create();
}
Program: 184090
Project: 184090
Buggy source:
@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  final Context context=this;
  final LayoutInflater inflater=this.getLayoutInflater();
  final Intent intent=getIntent();
  final String action=intent.getAction();
  final Bundle extras=intent.getExtras();
  setContentView(R.layout.act_edit);
  mHeader=(ContactHeaderWidget)this.findViewById(R.id.contact_header_widget);
  mHeader.setContactHeaderListener(this);
  mHeader.showStar(true);
  mTabWidget=(ScrollingTabWidget)this.findViewById(R.id.tab_widget);
  mTabWidget.setTabSelectionListener(this);
  mEditor=(ContactEditorView)this.findViewById(android.R.id.tabcontent);
  mEditor.getPhotoEditor().setEditorListener(this);
  findViewById(R.id.btn_done).setOnClickListener(this);
  findViewById(R.id.btn_discard).setOnClickListener(this);
  if (Intent.ACTION_EDIT.equals(action) && icicle == null) {
    new QueryEntitiesTask(this).execute(intent);
  }
 else   if (Intent.ACTION_INSERT.equals(action) && icicle == null) {
    doAddAction();
  }
}

Fixed version (ground truth):
@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  final Context context=this;
  final LayoutInflater inflater=this.getLayoutInflater();
  final Intent intent=getIntent();
  final String action=intent.getAction();
  final Bundle extras=intent.getExtras();
  setContentView(R.layout.act_edit);
  mHeader=(ContactHeaderWidget)this.findViewById(R.id.contact_header_widget);
  mHeader.setContactHeaderListener(this);
  mHeader.showStar(true);
  mTabWidget=(ScrollingTabWidget)this.findViewById(R.id.tab_widget);
  mTabWidget.setTabSelectionListener(this);
  mEditor=(ContactEditorView)this.findViewById(android.R.id.tabcontent);
  mEditor.getPhotoEditor().setEditorListener(this);
  findViewById(R.id.btn_done).setOnClickListener(this);
  findViewById(R.id.btn_discard).setOnClickListener(this);
  final boolean hasIncomingState=icicle != null && icicle.containsKey(KEY_EDIT_STATE);
  if (Intent.ACTION_EDIT.equals(action) && !hasIncomingState) {
    new QueryEntitiesTask(this).execute(intent);
  }
 else   if (Intent.ACTION_INSERT.equals(action) && !hasIncomingState) {
    doAddAction();
  }
}
Program: 184091
Project: 184091
Buggy source:
/** 
 * Rebuild tabs to match our underlying   {@link #mState} object, usuallycalled once we've parsed  {@link Entity} data or have inserted a new{@link RawContacts}.
 */
protected void bindTabs(){
  if (!hasValidState())   return;
  final Sources sources=Sources.getInstance(this);
  int selectedTab=0;
  mTabWidget.removeAllTabs();
  for (  EntityDelta entity : mState) {
    ValuesDelta values=entity.getValues();
    final String accountType=values.getAsString(RawContacts.ACCOUNT_TYPE);
    final Long rawContactId=values.getAsLong(RawContacts._ID);
    final ContactsSource source=sources.getInflatedSource(accountType,ContactsSource.LEVEL_CONSTRAINTS);
    final View tabView=ContactsUtils.createTabIndicatorView(mTabWidget.getTabParent(),source);
    mTabWidget.addTab(tabView);
  }
  if (mState.size() > 0) {
    mTabWidget.setCurrentTab(selectedTab);
    this.onTabSelectionChanged(selectedTab,false);
  }
  mEditor.setVisibility(View.VISIBLE);
}

Fixed version (ground truth):
/** 
 * Rebuild tabs to match our underlying   {@link #mState} object, usuallycalled once we've parsed  {@link Entity} data or have inserted a new{@link RawContacts}.
 */
protected void bindTabs(){
  if (!hasValidState())   return;
  final Sources sources=Sources.getInstance(this);
  final Long selectedRawContactId=this.getSelectedRawContactId();
  mTabWidget.removeAllTabs();
  mTabRawContacts.clear();
  for (  EntityDelta entity : mState) {
    final ValuesDelta values=entity.getValues();
    if (!values.isVisible())     continue;
    final String accountType=values.getAsString(RawContacts.ACCOUNT_TYPE);
    final Long rawContactId=values.getAsLong(RawContacts._ID);
    final ContactsSource source=sources.getInflatedSource(accountType,ContactsSource.LEVEL_CONSTRAINTS);
    final int tabIndex=mTabWidget.getTabCount();
    final View tabView=ContactsUtils.createTabIndicatorView(mTabWidget.getTabParent(),source);
    mTabWidget.addTab(tabView);
    mTabRawContacts.put(tabIndex,rawContactId);
  }
  final boolean hasActiveTabs=mTabWidget.getTabCount() > 0;
  if (hasActiveTabs) {
    this.setSelectedRawContactId(selectedRawContactId);
  }
 else {
    this.doSaveAction();
  }
  mEditor.setVisibility(View.VISIBLE);
}
Program: 184092
Project: 184092
Buggy source:
/** 
 * Delete the entire contact currently being edited, which usually asks for user confirmation before continuing.
 */
private boolean doDeleteAction(){
  if (!hasValidState())   return false;
  this.createDeleteDialog().show();
  return true;
}

Fixed version (ground truth):
/** 
 * Delete the entire contact currently being edited, which usually asks for user confirmation before continuing.
 */
private boolean doDeleteAction(){
  if (!hasValidState())   return false;
  showAndManageDialog(createDeleteDialog());
  return true;
}
Program: 184093
Project: 184093
Buggy source:
/** 
 * Return the   {@link RawContacts#_ID} of the currently selected tab.
 */
protected long getSelectedRawContactId(){
  final int index=mTabWidget.getCurrentTab();
  return mState.getRawContactId(index);
}

Fixed version (ground truth):
/** 
 * Return the   {@link RawContacts#_ID} of the currently selected tab.
 */
protected Long getSelectedRawContactId(){
  final int tabIndex=mTabWidget.getCurrentTab();
  return this.mTabRawContacts.get(tabIndex);
}
Program: 184094
Project: 184094
Buggy source:
/** 
 * {@inheritDoc} 
 */
public void onDisplayNameLongClick(View view){
  if (!hasValidState())   return;
  this.createNameDialog().show();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public void onDisplayNameLongClick(View view){
  if (!hasValidState())   return;
  showAndManageDialog(createNameDialog());
}
Program: 184095
Project: 184095
Buggy source:
/** 
 * Saves or creates the contact based on the mode, and if successful finishes the activity.
 */
private boolean doSaveAction(){
  if (!hasValidState())   return false;
  final int selectedTab=mTabWidget.getCurrentTab();
  final long rawContactId=mState.getRawContactId(selectedTab);
  if (rawContactId != -1) {
    final Intent intent=new Intent();
    intent.putExtra(ViewContactActivity.RAW_CONTACT_ID_EXTRA,rawContactId);
    setResult(RESULT_OK,intent);
  }
  try {
    final PersistTask task=new PersistTask(this);
    task.execute(mState);
    task.get(TIMEOUT_PERSIST,TimeUnit.MILLISECONDS);
  }
 catch (  InterruptedException e) {
  }
catch (  TimeoutException e) {
  }
catch (  ExecutionException e) {
  }
  this.finish();
  return true;
}

Fixed version (ground truth):
/** 
 * Saves or creates the contact based on the mode, and if successful finishes the activity.
 */
private boolean doSaveAction(){
  if (!hasValidState())   return false;
  final Long rawContactId=this.getSelectedRawContactId();
  if (rawContactId != null) {
    final Intent intent=new Intent();
    intent.putExtra(ViewContactActivity.RAW_CONTACT_ID_EXTRA,(long)rawContactId);
    setResult(RESULT_OK,intent);
  }
  try {
    final PersistTask task=new PersistTask(this);
    task.execute(mState);
    task.get(TIMEOUT_PERSIST,TimeUnit.MILLISECONDS);
  }
 catch (  InterruptedException e) {
  }
catch (  TimeoutException e) {
  }
catch (  ExecutionException e) {
  }
  this.finish();
  return true;
}
Program: 184097
Project: 184097
Buggy source:
@Override public void handleMessage(Message message){
  if (ContactsListActivity.this.isFinishing()) {
    return;
  }
switch (message.what) {
case FETCH_IMAGE_MSG:
    ImageView imageView=(ImageView)message.obj;
  long photoId=(Long)imageView.getTag();
Bitmap photo=null;
try {
photo=ContactsUtils.loadContactPhoto(mContext,photoId,null);
if (photo != null) {
  mBitmapCache.put(photoId,new SoftReference<Bitmap>(photo));
  imageView.setImageBitmap(photo);
}
}
 catch (OutOfMemoryError e) {
}
mItemsMissingImages.remove(imageView);
break;
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message message){
  if (ContactsListActivity.this.isFinishing()) {
    return;
  }
switch (message.what) {
case FETCH_IMAGE_MSG:
{
      ImageView imageView=(ImageView)message.obj;
      long photoId=(Long)imageView.getTag();
      if (photoId == 0) {
        break;
      }
      Bitmap photo=null;
      try {
        photo=ContactsUtils.loadContactPhoto(mContext,photoId,null);
      }
 catch (      OutOfMemoryError e) {
      }
      if (photo == null) {
        break;
      }
      mBitmapCache.put(photoId,new SoftReference<Bitmap>(photo));
synchronized (imageView) {
        long currentPhotoId=(Long)imageView.getTag();
        if (currentPhotoId == photoId) {
          imageView.setImageBitmap(photo);
          mItemsMissingImages.remove(imageView);
        }
      }
      break;
    }
}
}
Program: 184098
Project: 184098
Buggy source:
public void onScrollStateChanged(AbsListView view,int scrollState){
  mScrollState=scrollState;
  if (scrollState != OnScrollListener.SCROLL_STATE_IDLE) {
    clearImageFetching();
  }
 else   if (mDisplayPhotos) {
    processMissingImageItems(view);
  }
}

Fixed version (ground truth):
public void onScrollStateChanged(AbsListView view,int scrollState){
  mScrollState=scrollState;
  if (scrollState == OnScrollListener.SCROLL_STATE_FLING) {
    clearImageFetching();
  }
 else   if (mDisplayPhotos) {
    processMissingImageItems(view);
  }
}
Program: 184100
Project: 184100
Buggy source:
@Override public void handleMessage(Message message){
  if (ContactsListActivity.this.isFinishing()) {
    return;
  }
switch (message.what) {
case FETCH_IMAGE_MSG:
    ImageView imageView=(ImageView)message.obj;
  long photoId=(Long)imageView.getTag();
Bitmap photo=null;
try {
photo=ContactsUtils.loadContactPhoto(mContext,photoId,null);
if (photo != null) {
  mBitmapCache.put(photoId,new SoftReference<Bitmap>(photo));
  imageView.setImageBitmap(photo);
}
}
 catch (OutOfMemoryError e) {
}
mItemsMissingImages.remove(imageView);
break;
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message message){
  if (ContactsListActivity.this.isFinishing()) {
    return;
  }
switch (message.what) {
case FETCH_IMAGE_MSG:
{
      ImageView imageView=(ImageView)message.obj;
      long photoId=(Long)imageView.getTag();
      if (photoId == 0) {
        break;
      }
      Bitmap photo=null;
      try {
        photo=ContactsUtils.loadContactPhoto(mContext,photoId,null);
      }
 catch (      OutOfMemoryError e) {
      }
      if (photo == null) {
        break;
      }
      mBitmapCache.put(photoId,new SoftReference<Bitmap>(photo));
synchronized (imageView) {
        long currentPhotoId=(Long)imageView.getTag();
        if (currentPhotoId == photoId) {
          imageView.setImageBitmap(photo);
          mItemsMissingImages.remove(imageView);
        }
      }
      break;
    }
}
}
Program: 184101
Project: 184101
Buggy source:
public void onScrollStateChanged(AbsListView view,int scrollState){
  mScrollState=scrollState;
  if (scrollState != OnScrollListener.SCROLL_STATE_IDLE) {
    clearImageFetching();
  }
 else   if (mDisplayPhotos) {
    processMissingImageItems(view);
  }
}

Fixed version (ground truth):
public void onScrollStateChanged(AbsListView view,int scrollState){
  mScrollState=scrollState;
  if (scrollState == OnScrollListener.SCROLL_STATE_FLING) {
    clearImageFetching();
  }
 else   if (mDisplayPhotos) {
    processMissingImageItems(view);
  }
}
Program: 184103
Project: 184103
Buggy source:
@Override public void handleMessage(Message message){
  if (ContactsListActivity.this.isFinishing()) {
    return;
  }
switch (message.what) {
case FETCH_IMAGE_MSG:
    ImageView imageView=(ImageView)message.obj;
  long photoId=(Long)imageView.getTag();
Bitmap photo=null;
try {
photo=ContactsUtils.loadContactPhoto(mContext,photoId,null);
if (photo != null) {
  mBitmapCache.put(photoId,new SoftReference<Bitmap>(photo));
  imageView.setImageBitmap(photo);
}
}
 catch (OutOfMemoryError e) {
}
mItemsMissingImages.remove(imageView);
break;
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message message){
  if (ContactsListActivity.this.isFinishing()) {
    return;
  }
switch (message.what) {
case FETCH_IMAGE_MSG:
{
      ImageView imageView=(ImageView)message.obj;
      long photoId=(Long)imageView.getTag();
      if (photoId == 0) {
        break;
      }
      Bitmap photo=null;
      try {
        photo=ContactsUtils.loadContactPhoto(mContext,photoId,null);
      }
 catch (      OutOfMemoryError e) {
      }
      if (photo == null) {
        break;
      }
      mBitmapCache.put(photoId,new SoftReference<Bitmap>(photo));
synchronized (imageView) {
        long currentPhotoId=(Long)imageView.getTag();
        if (currentPhotoId == photoId) {
          imageView.setImageBitmap(photo);
          mItemsMissingImages.remove(imageView);
        }
      }
      break;
    }
}
}
Program: 184104
Project: 184104
Buggy source:
public void onScrollStateChanged(AbsListView view,int scrollState){
  mScrollState=scrollState;
  if (scrollState != OnScrollListener.SCROLL_STATE_IDLE) {
    clearImageFetching();
  }
 else   if (mDisplayPhotos) {
    processMissingImageItems(view);
  }
}

Fixed version (ground truth):
public void onScrollStateChanged(AbsListView view,int scrollState){
  mScrollState=scrollState;
  if (scrollState == OnScrollListener.SCROLL_STATE_FLING) {
    clearImageFetching();
  }
 else   if (mDisplayPhotos) {
    processMissingImageItems(view);
  }
}
Program: 184105
Project: 184105
Buggy source:
@Override protected void onResume(){
  super.onResume();
  boolean runQuery=true;
  Activity parent=getParent();
  if (mMode == MODE_DEFAULT) {
    setDefaultMode();
  }
  if (parent != null && parent instanceof DialtactsActivity) {
    String filterText=((DialtactsActivity)parent).getAndClearFilterText();
    if (filterText != null && filterText.length() > 0) {
      getListView().setFilterText(filterText);
      runQuery=false;
    }
 else     if (mJustCreated) {
      getListView().clearTextFilter();
    }
  }
  if (mJustCreated && runQuery) {
    startQuery();
  }
  mJustCreated=false;
}

Fixed version (ground truth):
@Override protected void onResume(){
  super.onResume();
  mScrollState=OnScrollListener.SCROLL_STATE_IDLE;
  boolean runQuery=true;
  Activity parent=getParent();
  if (mMode == MODE_DEFAULT) {
    setDefaultMode();
  }
  if (parent != null && parent instanceof DialtactsActivity) {
    String filterText=((DialtactsActivity)parent).getAndClearFilterText();
    if (filterText != null && filterText.length() > 0) {
      getListView().setFilterText(filterText);
      runQuery=false;
    }
 else     if (mJustCreated) {
      getListView().clearTextFilter();
    }
  }
  if (mJustCreated && runQuery) {
    startQuery();
  }
  mJustCreated=false;
}
Program: 184106
Project: 184106
Buggy source:
@Override protected void onPause(){
  super.onPause();
  TelephonyManager telephonyManager=(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
  telephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_NONE);
synchronized (mToneGeneratorLock) {
    if (mToneGenerator != null) {
      mToneStopper.removeMessages(STOP_TONE);
      mToneGenerator.release();
      mToneGenerator=null;
    }
  }
}

Fixed version (ground truth):
@Override protected void onPause(){
  super.onPause();
  TelephonyManager telephonyManager=(TelephonyManager)getSystemService(TELEPHONY_SERVICE);
  telephonyManager.listen(mPhoneStateListener,PhoneStateListener.LISTEN_NONE);
synchronized (mToneGeneratorLock) {
    if (mToneGenerator != null) {
      mToneGenerator.release();
      mToneGenerator=null;
    }
  }
}
Program: 184107
Project: 184107
Buggy source:
/** 
 * Plays the specified tone for TONE_LENGTH_MS milliseconds. The tone is played locally, using the audio stream for phone calls. Tones are played only if the "Audible touch tones" user preference is checked, and are NOT played if the device is in silent mode.
 * @param tone a tone code from {@link ToneGenerator}
 */
void playTone(int tone){
  if (!mDTMFToneEnabled) {
    return;
  }
  AudioManager audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  int ringerMode=audioManager.getRingerMode();
  if ((ringerMode == AudioManager.RINGER_MODE_SILENT) || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
    return;
  }
synchronized (mToneGeneratorLock) {
    if (mToneGenerator == null) {
      Log.w(TAG,"String_Node_Str" + tone);
      return;
    }
    mToneStopper.removeMessages(STOP_TONE);
    mToneGenerator.startTone(tone);
    mToneStopper.sendEmptyMessageDelayed(STOP_TONE,TONE_LENGTH_MS);
  }
}

Fixed version (ground truth):
/** 
 * Plays the specified tone for TONE_LENGTH_MS milliseconds. The tone is played locally, using the audio stream for phone calls. Tones are played only if the "Audible touch tones" user preference is checked, and are NOT played if the device is in silent mode.
 * @param tone a tone code from {@link ToneGenerator}
 */
void playTone(int tone){
  if (!mDTMFToneEnabled) {
    return;
  }
  AudioManager audioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
  int ringerMode=audioManager.getRingerMode();
  if ((ringerMode == AudioManager.RINGER_MODE_SILENT) || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
    return;
  }
synchronized (mToneGeneratorLock) {
    if (mToneGenerator == null) {
      Log.w(TAG,"String_Node_Str" + tone);
      return;
    }
    mToneGenerator.startTone(tone,TONE_LENGTH_MS);
  }
}