nus-yam/ex-repair huggingface dataset:
Program: 161577
Project: 161577
Buggy source:
@Override public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds){
  widgetIDs=appWidgetIds;
  final int N=appWidgetIds.length;
  this.appWidgetManager=appWidgetManager;
  for (int i=0; i < N; i++) {
    Intent intent=new Intent(context,MVVWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appWidgetIds[i]);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    rv=new RemoteViews(context.getPackageName(),R.layout.mvv_widget);
    Calendar c=Calendar.getInstance();
    String headerMVVWidget="String_Node_Str" + c.get(Calendar.DAY_OF_MONTH) + "String_Node_Str"+ c.get(Calendar.MONTH)+ "String_Node_Str"+ c.get(Calendar.YEAR);
    rv.setTextViewText(R.id.mvv_widget_header,headerMVVWidget);
    rv.setRemoteAdapter(appWidgetIds[i],R.id.mvv_widget_item,intent);
    rv.setEmptyView(R.id.empty_view,R.id.empty_view);
    rv.setOnClickPendingIntent(R.id.mvv_refresh,getPendingSelfIntent(context,SYNC_CLICKED));
    appWidgetManager.updateAppWidget(appWidgetIds[i],rv);
  }
  super.onUpdate(context,appWidgetManager,appWidgetIds);
}

Fixed version (ground truth):
@Override public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds){
  widgetIDs=appWidgetIds;
  final int N=appWidgetIds.length;
  this.appWidgetManager=appWidgetManager;
  for (int i=0; i < N; i++) {
    Intent intent=new Intent(context,MVVWidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appWidgetIds[i]);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    rv=new RemoteViews(context.getPackageName(),R.layout.mvv_widget);
    Calendar c=Calendar.getInstance();
    String headerMVVWidget="String_Node_Str" + c.get(Calendar.DAY_OF_MONTH) + "String_Node_Str"+ c.get(Calendar.MONTH)+ "String_Node_Str"+ c.get(Calendar.YEAR);
    rv.setTextViewText(R.id.mvv_widget_header,headerMVVWidget);
    rv.setRemoteAdapter(appWidgetIds[i],R.id.mvv_widget_item,intent);
    rv.setEmptyView(R.id.empty_view,R.id.empty_view);
    rv.setOnClickPendingIntent(R.id.mvv_refresh,getPendingSelfIntent(context,Const.SYNC_CLICKED));
    appWidgetManager.updateAppWidget(appWidgetIds[i],rv);
  }
  super.onUpdate(context,appWidgetManager,appWidgetIds);
}
Program: 161578
Project: 161578
Buggy source:
@Override public void onCreate(){
  recentsManager=new RecentsManager(applicationContext,RecentsManager.STATIONS);
  callRecentVisitedStation();
  appWidgetManager=AppWidgetManager.getInstance(applicationContext);
  mostRecentStationName=null;
}

Fixed version (ground truth):
@Override public void onCreate(){
  recentsManager=new RecentsManager(applicationContext,RecentsManager.STATIONS);
  callRecentVisitedStation();
  appWidgetManager=AppWidgetManager.getInstance(applicationContext);
}
Program: 161579
Project: 161579
Buggy source:
@Override public RemoteViews getViewAt(int position){
  RemoteViews rv=new RemoteViews(applicationContext.getPackageName(),R.layout.mvv_widget_item);
  MVVDeparture currentSearch=(MVVDeparture)mvvList.get(position);
  if (currentSearch != null) {
    int icon_id=getImageResource(currentSearch);
    String number=currentSearch.getLine();
    String station=currentSearch.getDirection();
    String minutes=String.valueOf(currentSearch.getMin() + "String_Node_Str");
    rv.setImageViewResource(R.id.mvv_icon,icon_id);
    rv.setTextViewText(R.id.line_number,number);
    String stationString=(mostRecentStationName == null ? station : mostRecentStationName + "String_Node_Str" + station);
    rv.setTextViewText(R.id.station,stationString);
    rv.setTextViewText(R.id.minutes,minutes);
    return rv;
  }
  return null;
}

Fixed version (ground truth):
@Override public RemoteViews getViewAt(int position){
  RemoteViews rv=new RemoteViews(applicationContext.getPackageName(),R.layout.mvv_widget_item);
  MVVDeparture currentSearch=(MVVDeparture)mvvList.get(position);
  SharedPreferences sharedPreferences=applicationContext.getSharedPreferences(applicationContext.getString(R.string.mvv_shared_pref_key),Context.MODE_PRIVATE);
  String mostRecentStationName=sharedPreferences.getString(applicationContext.getString(R.string.most_recent_station),null);
  Utils.log("String_Node_Str" + mostRecentStationName);
  if (currentSearch != null) {
    int icon_id=getImageResource(currentSearch);
    String number=currentSearch.getLine();
    String station=currentSearch.getDirection();
    String minutes=String.valueOf(currentSearch.getMin() + "String_Node_Str");
    rv.setImageViewResource(R.id.mvv_icon,icon_id);
    rv.setTextViewText(R.id.line_number,number);
    String stationString=(mostRecentStationName == null ? station : mostRecentStationName + "String_Node_Str" + station);
    rv.setTextViewText(R.id.station,stationString);
    rv.setTextViewText(R.id.minutes,minutes);
    return rv;
  }
  return null;
}
Program: 161580
Project: 161580
Buggy source:
@Override public void showSuggestionList(MVVObject sug){
  try {
    mvvList=sug.getResultList();
    final MVVSuggestion sugestion=(MVVSuggestion)mvvList.get(0);
    final MVVDelegate delegate=this;
    new Thread(new Runnable(){
      @Override public void run(){
        (new MVVJsoupParser(delegate)).execute(sugestion.getName());
      }
    }
).run();
    mvvList=null;
  }
 catch (  Exception e) {
    Utils.log(e);
    Utils.showToast(applicationContext,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void showSuggestionList(MVVObject sug){
  try {
    mvvList=sug.getResultList();
    final MVVSuggestion sugestion=(MVVSuggestion)mvvList.get(0);
    final MVVDelegate delegate=this;
    new Thread(new Runnable(){
      @Override public void run(){
        (new MVVJsoupParser(delegate)).execute(sugestion.getName());
      }
    }
).run();
    mvvList=null;
  }
 catch (  Exception e) {
    Utils.log(e);
    Utils.showToast(applicationContext,applicationContext.getString(R.string.something_is_wrong));
  }
}
Program: 161581
Project: 161581
Buggy source:
public boolean callRecentVisitedStation(){
  boolean isValid=true;
  try {
    String query=getFirstRecentStation();
    if (query != null)     (new MVVJsoupParser(this)).execute(new String[]{query});
  }
 catch (  Exception e) {
    Utils.showToast(applicationContext,"String_Node_Str");
    e.printStackTrace();
    isValid=false;
    return isValid;
  }
  return isValid;
}

Fixed version (ground truth):
public boolean callRecentVisitedStation(){
  SharedPreferences sharedPreferences=applicationContext.getSharedPreferences(applicationContext.getString(R.string.mvv_shared_pref_key),Context.MODE_PRIVATE);
  String queryString=sharedPreferences.getString(applicationContext.getString(R.string.most_recent_station),null);
  boolean isValid=true;
  Utils.log("String_Node_Str" + queryString);
  try {
    if (queryString != null)     (new MVVJsoupParser(this)).execute(new String[]{queryString});
 else {
      Utils.showToast(applicationContext,applicationContext.getString(R.string.no_recent_found));
    }
  }
 catch (  Exception e) {
    Utils.showToast(applicationContext,applicationContext.getString(R.string.something_is_wrong));
    e.printStackTrace();
    isValid=false;
    return isValid;
  }
  return isValid;
}
Program: 161582
Project: 161582
Buggy source:
@Override public void showError(MVVObject object){
  Utils.log("String_Node_Str" + object.getMessage());
  Utils.showToast(applicationContext,"String_Node_Str");
}

Fixed version (ground truth):
@Override public void showError(MVVObject object){
  Utils.log("String_Node_Str" + object.getMessage());
  Utils.showToast(applicationContext,applicationContext.getString(R.string.something_is_wrong));
}
Program: 161583
Project: 161583
Buggy source:
@Override public void showDepartureList(MVVObject dep){
  try {
    mvvList=dep.getResultList();
    int widgetID=intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,-1);
    appWidgetManager.notifyAppWidgetViewDataChanged(widgetID,R.id.mvv_widget_item);
  }
 catch (  Exception e) {
    Utils.log(e);
    Utils.showToast(applicationContext,"String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public void showDepartureList(MVVObject dep){
  try {
    mvvList=dep.getResultList();
    int widgetID=intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,-1);
    appWidgetManager.notifyAppWidgetViewDataChanged(widgetID,R.id.mvv_widget_item);
  }
 catch (  Exception e) {
    Utils.log(e);
    Utils.showToast(applicationContext,applicationContext.getString(R.string.something_is_wrong));
  }
}
Program: 161585
Project: 161585
Buggy source:
private void sendMessage(String text){
  if (mEditedItem == null) {
    final ChatMessage message=new ChatMessage(text,currentChatMember);
    chatHistoryAdapter.add(message);
    chatManager.addToUnsent(message);
  }
 else {
    mEditedItem.setText(etMessage.getText().toString());
    chatManager.addToUnsent(mEditedItem);
    mEditedItem.setStatus(ChatMessage.STATUS_SENDING);
    chatManager.replaceMessage(mEditedItem);
    chatHistoryAdapter.notifyDataSetChanged();
  }
  startService(new Intent(this,SendMessageService.class));
}

Fixed version (ground truth):
private void sendMessage(String text){
  if (mEditedItem == null) {
    final ChatMessage message=new ChatMessage(text,currentChatMember);
    chatHistoryAdapter.add(message);
    chatManager.addToUnsent(message);
  }
 else {
    mEditedItem.setText(etMessage.getText().toString());
    chatManager.addToUnsent(mEditedItem);
    mEditedItem.setStatus(ChatMessage.STATUS_SENDING);
    chatManager.replaceMessage(mEditedItem);
    chatHistoryAdapter.notifyDataSetChanged();
    mEditedItem=null;
  }
  startService(new Intent(this,SendMessageService.class));
}
Program: 161586
Project: 161586
Buggy source:
@Override public boolean onActionItemClicked(ActionMode mode,MenuItem item){
  ChatMessage msg=chatHistoryAdapter.mCheckedItem;
switch (item.getItemId()) {
case R.id.action_edit:
    if (msg.getStatus() == ChatMessage.STATUS_SENDING) {
      chatManager.removeFromUnsent(msg);
      chatHistoryAdapter.removeUnsent(msg);
    }
 else {
      mEditedItem=msg;
    }
  InputMethodManager imm=(InputMethodManager)ChatActivity.this.getSystemService(Service.INPUT_METHOD_SERVICE);
imm.showSoftInput(etMessage,0);
etMessage.setText(msg.getText());
int position=msg.getText().length();
etMessage.setSelection(position);
mode.finish();
return true;
case R.id.action_info:
showInfo(msg);
mode.finish();
return true;
default :
return false;
}
}

Fixed version (ground truth):
@Override public boolean onActionItemClicked(ActionMode mode,MenuItem item){
  ChatMessage msg=chatHistoryAdapter.mCheckedItem;
switch (item.getItemId()) {
case R.id.action_edit:
    if (msg.getStatus() == ChatMessage.STATUS_SENDING) {
      chatManager.removeFromUnsent(msg);
      chatHistoryAdapter.removeUnsent(msg);
    }
 else {
      chatHistoryAdapter.mEditedItem=msg;
    }
  InputMethodManager imm=(InputMethodManager)ChatActivity.this.getSystemService(Service.INPUT_METHOD_SERVICE);
imm.showSoftInput(etMessage,0);
etMessage.setText(msg.getText());
int position=msg.getText().length();
etMessage.setSelection(position);
mode.finish();
return true;
case R.id.action_info:
showInfo(msg);
mode.finish();
return true;
default :
return false;
}
}
Program: 161587
Project: 161587
Buggy source:
private void sendMessage(String text){
  if (mEditedItem == null) {
    final ChatMessage message=new ChatMessage(text,currentChatMember);
    chatHistoryAdapter.add(message);
    chatManager.addToUnsent(message);
  }
 else {
    mEditedItem.setText(etMessage.getText().toString());
    chatManager.addToUnsent(mEditedItem);
    mEditedItem.setStatus(ChatMessage.STATUS_SENDING);
    chatManager.replaceMessage(mEditedItem);
    chatHistoryAdapter.changeCursor(chatManager.getAll());
    mEditedItem=null;
  }
  startService(new Intent(this,SendMessageService.class));
}

Fixed version (ground truth):
private void sendMessage(String text){
  if (chatHistoryAdapter.mEditedItem == null) {
    final ChatMessage message=new ChatMessage(text,currentChatMember);
    chatHistoryAdapter.add(message);
    chatManager.addToUnsent(message);
  }
 else {
    chatHistoryAdapter.mEditedItem.setText(etMessage.getText().toString());
    chatManager.addToUnsent(chatHistoryAdapter.mEditedItem);
    chatHistoryAdapter.mEditedItem.setStatus(ChatMessage.STATUS_SENDING);
    chatManager.replaceMessage(chatHistoryAdapter.mEditedItem);
    chatHistoryAdapter.mEditedItem=null;
    chatHistoryAdapter.changeCursor(chatManager.getAll());
  }
  startService(new Intent(this,SendMessageService.class));
}
Program: 161588
Project: 161588
Buggy source:
@Override public void onReceive(Context context,Intent intent){
  Bundle extras=intent.getExtras();
  String chatRoomString=extras.getString("String_Node_Str");
  String memberString=extras.getString("String_Node_Str");
  Utils.log("String_Node_Str" + chatRoomString + "String_Node_Str"+ memberString);
  if (chatRoomString.equals("String_Node_Str" + currentChatRoom.getId()) && chatHistoryAdapter != null) {
    if (memberString.equals("String_Node_Str" + currentChatMember.getId())) {
      chatHistoryAdapter.setUnsentMessages(chatManager.getAllUnsent());
    }
 else {
      AudioManager am=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
      if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
        MediaPlayer mediaPlayer=MediaPlayer.create(ChatActivity.this,R.raw.message);
        mediaPlayer.start();
      }
 else       if (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
        Vibrator v=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(500);
      }
    }
    chatHistoryAdapter.changeCursor(chatManager.getAll());
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
  Bundle extras=intent.getExtras();
  String chatRoomString=extras.getString("String_Node_Str");
  String memberString=extras.getString("String_Node_Str");
  int messageId=-1;
  if (extras.containsKey("String_Node_Str"))   messageId=Integer.parseInt(extras.getString("String_Node_Str"));
  Utils.log("String_Node_Str" + chatRoomString + "String_Node_Str"+ memberString);
  if (chatRoomString.equals("String_Node_Str" + currentChatRoom.getId()) && chatHistoryAdapter != null) {
    if (memberString.equals("String_Node_Str" + currentChatMember.getId())) {
      chatHistoryAdapter.setUnsentMessages(chatManager.getAllUnsent());
    }
 else     if (messageId == -1) {
      AudioManager am=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
      if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
        MediaPlayer mediaPlayer=MediaPlayer.create(ChatActivity.this,R.raw.message);
        mediaPlayer.start();
      }
 else       if (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
        Vibrator v=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(500);
      }
    }
    chatHistoryAdapter.changeCursor(chatManager.getAll());
  }
}
Program: 161589
Project: 161589
Buggy source:
/** 
 * Prompt the user to type in a name for the new chat room
 */
private void newChatRoom(){
  final EditText input=new EditText(this);
  new AlertDialog.Builder(this).setTitle("String_Node_Str").setMessage("String_Node_Str").setView(input).setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int whichButton){
      String value=input.getText().toString();
      String randId=Integer.toHexString((int)(Math.random() * 4096));
      createOrJoinChatRoom(randId + "String_Node_Str" + value);
    }
  }
).setNegativeButton(android.R.string.cancel,null).show();
}

Fixed version (ground truth):
/** 
 * Prompt the user to type in a name for the new chat room
 */
private void newChatRoom(){
  final EditText input=new EditText(this);
  new AlertDialog.Builder(this).setTitle(R.string.new_chat_room).setMessage(R.string.new_chat_room_desc).setView(input).setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int whichButton){
      String value=input.getText().toString();
      String randId=Integer.toHexString((int)(Math.random() * 4096));
      createOrJoinChatRoom(randId + "String_Node_Str" + value);
    }
  }
).setNegativeButton(android.R.string.cancel,null).show();
}
Program: 161590
Project: 161590
Buggy source:
@SuppressWarnings("String_Node_Str") public void setCafeteriaId(Activity mainActivity,int cafeteriaId){
  mCafeteriaId=cafeteriaId;
  CafeteriaMenuManager cmm=new CafeteriaMenuManager(mainActivity);
  cursorCafeteriaDates=cmm.getDatesFromDb();
  mainActivity.startManagingCursor(cursorCafeteriaDates);
  for (int position=0; position < getCount(); position++) {
    cursorCafeteriaDates.moveToPosition(position);
    dates.add(cursorCafeteriaDates.getString(cursorCafeteriaDates.getColumnIndex(Const.ID_COLUMN)));
  }
  CafeteriaMenuManager.lastInserted=0;
  this.notifyDataSetChanged();
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public void setCafeteriaId(Activity mainActivity,int cafeteriaId){
  mCafeteriaId=cafeteriaId;
  CafeteriaMenuManager cmm=new CafeteriaMenuManager(mainActivity);
  cursorCafeteriaDates=cmm.getDatesFromDb();
  mainActivity.startManagingCursor(cursorCafeteriaDates);
  for (int position=0; position < getCount(); position++) {
    cursorCafeteriaDates.moveToPosition(position);
    dates.add(cursorCafeteriaDates.getString(cursorCafeteriaDates.getColumnIndex(Const.ID_COLUMN)));
  }
  this.notifyDataSetChanged();
}
Program: 161591
Project: 161591
Buggy source:
private void bindViewChatMessage(View view,ChatMessage chatMessage){
  ViewHolder holder=(ViewHolder)view.getTag();
  holder.tvUser.setText(chatMessage.getMember().getDisplayName());
  holder.tvMessage.setText(chatMessage.getText());
  holder.tvTimestamp.setText(chatMessage.getTimestampString(mContext));
  if (holder.ivSent != null) {
    boolean sending=chatMessage.getStatus() == ChatMessage.STATUS_SENDING;
    holder.ivSent.setVisibility(sending ? View.GONE : View.VISIBLE);
    holder.pbSending.setVisibility(sending ? View.VISIBLE : View.GONE);
  }
  if (chatMessage.getMember().getLrzId().equals("String_Node_Str")) {
    holder.tvUser.setText("String_Node_Str");
    holder.tvTimestamp.setText("String_Node_Str");
  }
  if (mCheckedItem != null && mCheckedItem.getId() == chatMessage.getId() && mCheckedItem.getStatus() == chatMessage.getStatus()) {
    holder.layout.setBackgroundResource(R.drawable.bg_message_outgoing_selected);
  }
 else   if (holder.ivSent != null) {
    holder.layout.setBackgroundResource(R.drawable.bg_message_outgoing);
  }
}

Fixed version (ground truth):
private void bindViewChatMessage(View view,ChatMessage chatMessage){
  ViewHolder holder=(ViewHolder)view.getTag();
  holder.tvUser.setText(chatMessage.getMember().getDisplayName());
  holder.tvMessage.setText(chatMessage.getText());
  holder.tvTimestamp.setText(chatMessage.getTimestampString(mContext));
  if (holder.ivSent != null) {
    boolean sending=chatMessage.getStatus() == ChatMessage.STATUS_SENDING;
    holder.ivSent.setVisibility(sending ? View.GONE : View.VISIBLE);
    holder.pbSending.setVisibility(sending ? View.VISIBLE : View.GONE);
  }
  if (chatMessage.getMember().getLrzId().equals("String_Node_Str")) {
    holder.tvUser.setText("String_Node_Str");
    holder.tvTimestamp.setText("String_Node_Str");
  }
  if ((mCheckedItem != null && mCheckedItem.getId() == chatMessage.getId() && mCheckedItem.getStatus() == chatMessage.getStatus()) || (mEditedItem != null && mEditedItem.getId() == chatMessage.getId() && mEditedItem.getStatus() == chatMessage.getStatus())) {
    holder.layout.setBackgroundResource(R.drawable.bg_message_outgoing_selected);
  }
 else   if (holder.ivSent != null) {
    holder.layout.setBackgroundResource(R.drawable.bg_message_outgoing);
  }
}
Program: 161592
Project: 161592
Buggy source:
/** 
 * Download cafeteria menus from external interface (JSON)
 * @param force True to force download over normal sync period, else false
 * @throws Exception
 */
public void downloadFromExternal(Context context,boolean force) throws Exception {
  if (!force && !SyncManager.needSync(db,this,TIME_TO_SYNC)) {
    return;
  }
  cleanupDb();
  int count=Utils.dbGetTableCount(db,"String_Node_Str");
  Cursor c=db.rawQuery("String_Node_Str",null);
  if (c.getCount() > 0) {
    c.close();
    return;
  }
  c.close();
  String url="String_Node_Str";
  JSONObject json=NetUtils.downloadJson(context,url);
  removeCache();
  db.beginTransaction();
  try {
    JSONArray menu=json.getJSONArray("String_Node_Str");
    for (int j=0; j < menu.length(); j++) {
      replaceIntoDb(getFromJson(menu.getJSONObject(j)));
    }
    JSONArray beilagen=json.getJSONArray("String_Node_Str");
    for (int j=0; j < beilagen.length(); j++) {
      replaceIntoDb(getFromJsonAddendum(beilagen.getJSONObject(j)));
    }
    db.setTransactionSuccessful();
  }
  finally {
    db.endTransaction();
  }
  SyncManager.replaceIntoDb(db,this);
  lastInserted+=Utils.dbGetTableCount(db,"String_Node_Str") - count;
}

Fixed version (ground truth):
/** 
 * Download cafeteria menus from external interface (JSON)
 * @param force True to force download over normal sync period, else false
 * @throws Exception
 */
public void downloadFromExternal(Context context,boolean force) throws Exception {
  if (!force && !SyncManager.needSync(db,this,TIME_TO_SYNC)) {
    return;
  }
  String url="String_Node_Str";
  JSONObject json=NetUtils.downloadJson(context,url);
  db.beginTransaction();
  removeCache();
  try {
    JSONArray menu=json.getJSONArray("String_Node_Str");
    for (int j=0; j < menu.length(); j++) {
      replaceIntoDb(getFromJson(menu.getJSONObject(j)));
    }
    JSONArray beilagen=json.getJSONArray("String_Node_Str");
    for (int j=0; j < beilagen.length(); j++) {
      replaceIntoDb(getFromJsonAddendum(beilagen.getJSONObject(j)));
    }
    db.setTransactionSuccessful();
  }
  finally {
    db.endTransaction();
  }
  SyncManager.replaceIntoDb(db,this);
}
Program: 161593
Project: 161593
Buggy source:
/** 
 * Saves the given message into database
 */
public void replaceInto(List<ChatMessage> m){
  db.beginTransaction();
  for (  ChatMessage msg : m) {
    replaceInto(msg,false);
  }
  db.setTransactionSuccessful();
  db.endTransaction();
}

Fixed version (ground truth):
/** 
 * Saves the given message into database
 */
public void replaceInto(List<ChatMessage> m){
  ChatMember member=Utils.getSetting(mContext,Const.CHAT_MEMBER,ChatMember.class);
  db.beginTransaction();
  for (  ChatMessage msg : m) {
    replaceInto(msg,member.getId());
  }
  db.setTransactionSuccessful();
  db.endTransaction();
}
Program: 161596
Project: 161596
Buggy source:
@Override public Intent getIntent(){
  return new Intent(mContext,ChatRoomsActivity.class);
}

Fixed version (ground truth):
@Override public Intent getIntent(){
  Bundle bundle=new Bundle();
  final Intent intent=new Intent(mContext,ChatActivity.class);
  ChatRoom currentChatRoom=new ChatRoom(mRoomIdString);
  currentChatRoom.setId(mRoomId);
  intent.putExtra(Const.CURRENT_CHAT_ROOM,new Gson().toJson(currentChatRoom));
  intent.putExtra(Const.CURRENT_CHAT_MEMBER,new Gson().toJson(mMember));
  intent.putExtras(bundle);
  return intent;
}
Program: 161597
Project: 161597
Buggy source:
/** 
 * Sets the information needed to build the card
 * @param roomName Name of the chat room
 * @param roomId Id of the chat room
 */
public void setChatRoom(String roomName,int roomId){
  mRoomName=roomName;
  mRoomName=mRoomName.replaceAll("String_Node_Str","String_Node_Str");
  mRoomName=mRoomName.replaceAll("String_Node_Str","String_Node_Str");
  mRoomName=mRoomName.replaceAll("String_Node_Str","String_Node_Str");
  mRoomName=mRoomName.trim();
  manager=new ChatMessageManager(mContext,roomId);
  mUnread=manager.getLastUnread();
}

Fixed version (ground truth):
/** 
 * Sets the information needed to build the card
 * @param roomName Name of the chat room
 * @param roomId Id of the chat room
 */
public void setChatRoom(String roomName,int roomId,String roomIdString,ChatMember member){
  mRoomName=roomName;
  mRoomName=mRoomName.replaceAll("String_Node_Str","String_Node_Str");
  mRoomName=mRoomName.replaceAll("String_Node_Str","String_Node_Str");
  mRoomName=mRoomName.replaceAll("String_Node_Str","String_Node_Str");
  mRoomName=mRoomName.trim();
  manager=new ChatMessageManager(mContext,roomId);
  mUnread=manager.getLastUnread();
  mRoomIdString=roomIdString;
  mRoomId=roomId;
  mMember=member;
}
Program: 161598
Project: 161598
Buggy source:
public Cursor getNewMessages(PrivateKey pk,ChatMember member,int messageId){
  ArrayList<ChatMessage> messages;
  if (messageId == -1)   messages=ChatClient.getInstance(mContext).getNewMessages(mChatRoom,new ChatVerification(pk,member));
 else   messages=ChatClient.getInstance(mContext).getMessages(mChatRoom,messageId + 1,new ChatVerification(pk,member));
  replaceInto(messages);
  return getUnread();
}

Fixed version (ground truth):
public Cursor getNewMessages(PrivateKey pk,ChatMember member,int messageId){
  ArrayList<ChatMessage> messages;
  if (messageId == -1)   messages=ChatClient.getInstance(mContext).getNewMessages(mChatRoom,new ChatVerification(pk,member));
 else   messages=ChatClient.getInstance(mContext).getMessages(mChatRoom,messageId,new ChatVerification(pk,member));
  replaceInto(messages);
  return getUnread();
}
Program: 161599
Project: 161599
Buggy source:
@Override public void onRequestCard(Context context){
  ChatRoomManager manager=new ChatRoomManager(context);
  new ChatMessageManager(context,0);
  if (Utils.getSettingBool(context,Const.AUTO_JOIN_NEW_ROOMS,false)) {
    ArrayList<String> newRooms=manager.getNewUnjoined();
    for (    String roomId : newRooms) {
      try {
        ChatRoom currentChatRoom=new ChatRoom(roomId);
        currentChatRoom=ChatClient.getInstance(context).createGroup(currentChatRoom);
        manager.join(currentChatRoom);
      }
 catch (      RetrofitError e) {
        Utils.log(e);
      }
    }
  }
  Cursor cur=manager.getUnreadRooms();
  if (cur.moveToFirst()) {
    do {
      ChatMessagesCard card=new ChatMessagesCard(context);
      card.setChatRoom(cur.getString(0),cur.getInt(1));
      card.apply();
    }
 while (cur.moveToNext());
  }
  cur.close();
}

Fixed version (ground truth):
@Override public void onRequestCard(Context context){
  ChatRoomManager manager=new ChatRoomManager(context);
  new ChatMessageManager(context,0);
  ChatMember member;
  try {
    if (Utils.getSettingBool(context,Const.AUTO_JOIN_NEW_ROOMS,false)) {
      ArrayList<String> newRooms=manager.getNewUnjoined();
      for (      String roomId : newRooms) {
        try {
          ChatRoom currentChatRoom=new ChatRoom(roomId);
          currentChatRoom=ChatClient.getInstance(context).createGroup(currentChatRoom);
          manager.join(currentChatRoom);
        }
 catch (        RetrofitError e) {
          Utils.log(e);
        }
      }
    }
    String lrzId=Utils.getSetting(context,Const.LRZ_ID,"String_Node_Str");
    member=ChatClient.getInstance(context).getMember(lrzId);
    if (member == null || member.getLrzId() == null) {
      return;
    }
  }
 catch (  RetrofitError e) {
    Utils.log(e);
    return;
  }
  Cursor cur=manager.getUnreadRooms();
  if (cur.moveToFirst()) {
    do {
      ChatMessagesCard card=new ChatMessagesCard(context);
      card.setChatRoom(cur.getString(0),cur.getInt(1),cur.getString(2) + "String_Node_Str" + cur.getString(0),member);
      card.apply();
    }
 while (cur.moveToNext());
  }
  cur.close();
}
Program: 161600
Project: 161600
Buggy source:
@Override public void run(){
  adapter.changeCursor(newCursor);
  Utils.showToast(ChatRoomsActivity.this,R.string.joined_chat_room);
}

Fixed version (ground truth):
public void run(){
  GooglePlayServicesUtil.getErrorDialog(resultCode,ChatRoomsActivity.this,PLAY_SERVICES_RESOLUTION_REQUEST).show();
}
Program: 161601
Project: 161601
Buggy source:
/** 
 * Check the device to make sure it has the Google Play Services APK. If it doesn't, display a dialog that allows users to download the APK from the Google Play Store or enable it in the device's system settings.
 */
private boolean checkPlayServices(){
  int resultCode=GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
  if (resultCode != ConnectionResult.SUCCESS) {
    if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
      try {
        GooglePlayServicesUtil.getErrorDialog(resultCode,this,PLAY_SERVICES_RESOLUTION_REQUEST).show();
      }
 catch (      Exception e) {
        Utils.log(e);
        return false;
      }
    }
 else {
      Utils.log("String_Node_Str");
      finish();
    }
    return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Check the device to make sure it has the Google Play Services APK. If it doesn't, display a dialog that allows users to download the APK from the Google Play Store or enable it in the device's system settings.
 */
private boolean checkPlayServices(){
  final int resultCode=GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
  if (resultCode != ConnectionResult.SUCCESS) {
    if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
      this.runOnUiThread(new Runnable(){
        public void run(){
          GooglePlayServicesUtil.getErrorDialog(resultCode,ChatRoomsActivity.this,PLAY_SERVICES_RESOLUTION_REQUEST).show();
        }
      }
);
    }
 else {
      Utils.log("String_Node_Str");
      finish();
    }
    return false;
  }
  return true;
}
Program: 161602
Project: 161602
Buggy source:
/** 
 * Sets the actionbar title to the current chat room
 */
private void getIntentData(){
  Bundle extras=getIntent().getExtras();
  currentChatRoom=new Gson().fromJson(extras.getString(Const.CURRENT_CHAT_ROOM),ChatRoom.class);
  currentChatMember=new Gson().fromJson(extras.getString(Const.CURRENT_CHAT_MEMBER),ChatMember.class);
  getSupportActionBar().setTitle(currentChatRoom.getName().substring(4));
  CharSequence message=getMessageText(getIntent());
  if (message != null) {
    sendMessage(message.toString());
  }
}

Fixed version (ground truth):
/** 
 * Sets the actionbar title to the current chat room
 */
private void getIntentData(){
  Bundle extras=getIntent().getExtras();
  currentChatRoom=new Gson().fromJson(extras.getString(Const.CURRENT_CHAT_ROOM),ChatRoom.class);
  currentChatMember=new Gson().fromJson(extras.getString(Const.CURRENT_CHAT_MEMBER),ChatMember.class);
  getSupportActionBar().setTitle(currentChatRoom.getName().substring(4));
  chatManager=new ChatMessageManager(this,currentChatRoom.getId());
  CharSequence message=getMessageText(getIntent());
  if (message != null) {
    sendMessage(message.toString());
  }
}
Program: 161603
Project: 161603
Buggy source:
@Override public void onReceive(Context context,Intent intent){
  Bundle extras=intent.getExtras();
  String chatRoomString=extras.getString("String_Node_Str");
  if (chatRoomString.equals("String_Node_Str" + currentChatRoom.getId())) {
    if (extras.getBoolean("String_Node_Str",false)) {
      chatHistoryAdapter.setUnsentMessages(chatManager.getAllUnsent());
    }
 else {
      AudioManager am=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
      if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
        MediaPlayer mediaPlayer=MediaPlayer.create(ChatActivity.this,R.raw.message);
        mediaPlayer.start();
      }
 else       if (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
        Vibrator v=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(500);
      }
    }
    chatHistoryAdapter.changeCursor(chatManager.getAll());
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
  Bundle extras=intent.getExtras();
  String chatRoomString=extras.getString("String_Node_Str");
  if (chatRoomString.equals("String_Node_Str" + currentChatRoom.getId()) && chatHistoryAdapter != null) {
    if (extras.getBoolean("String_Node_Str",false)) {
      chatHistoryAdapter.setUnsentMessages(chatManager.getAllUnsent());
    }
 else {
      AudioManager am=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
      if (am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
        MediaPlayer mediaPlayer=MediaPlayer.create(ChatActivity.this,R.raw.message);
        mediaPlayer.start();
      }
 else       if (am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
        Vibrator v=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
        v.vibrate(500);
      }
    }
    chatHistoryAdapter.changeCursor(chatManager.getAll());
  }
}
Program: 161604
Project: 161604
Buggy source:
@Override protected void onResume(){
  super.onResume();
  getNextHistoryFromServer();
  mCurrentOpenChatRoom=currentChatRoom;
  chatManager=new ChatMessageManager(this,currentChatRoom.getId());
}

Fixed version (ground truth):
@Override protected void onResume(){
  super.onResume();
  getNextHistoryFromServer();
  mCurrentOpenChatRoom=currentChatRoom;
}
Program: 161605
Project: 161605
Buggy source:
/** 
 * Translates room title to Geo HINT: Don't call from UI thread
 * @param loc Room title
 * @return Location or null on failure
 */
public Geo roomLocationStringToGeo(String loc){
  TUMRoomFinderRequest requestHandler=new TUMRoomFinderRequest();
  loc=loc.substring(0,loc.indexOf('(')).trim();
  ArrayList<HashMap<String,String>> request=requestHandler.fetchRooms(loc);
  if (request.size() > 0) {
    String room=request.get(0).get(TUMRoomFinderRequest.KEY_ARCHITECT_NUMBER);
    return requestHandler.fetchCoordinates(room);
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Translates room title to Geo HINT: Don't call from UI thread
 * @param loc Room title
 * @return Location or null on failure
 */
public Geo roomLocationStringToGeo(String loc){
  TUMRoomFinderRequest requestHandler=new TUMRoomFinderRequest();
  if (loc.contains("String_Node_Str"))   loc=loc.substring(0,loc.indexOf('(')).trim();
  ArrayList<HashMap<String,String>> request=requestHandler.fetchRooms(loc);
  if (request.size() > 0) {
    String room=request.get(0).get(TUMRoomFinderRequest.KEY_ARCHITECT_NUMBER);
    return requestHandler.fetchCoordinates(room);
  }
  return null;
}
Program: 161606
Project: 161606
Buggy source:
@Override protected Cursor onLoadInBackground(Integer... arg){
  LecturesSearchRowSet lecturesList=requestHandler.fetch();
  if (lecturesList != null) {
    List<LecturesSearchRow> lectures=lecturesList.getLehrveranstaltungen();
    manager.replaceInto(lectures);
  }
  populateCurrentChatMember();
  try {
    List<ChatRoom> rooms=ChatClient.getInstance(this).getMemberRooms(currentChatMember.getId(),new ChatVerification(currentPrivateKey,currentChatMember));
    manager.replaceIntoRooms(rooms);
    return manager.getAllByStatus(arg[0]);
  }
 catch (  RetrofitError e) {
    Utils.log(e);
    return null;
  }
}

Fixed version (ground truth):
@Override protected Cursor onLoadInBackground(Void... arg){
  if (!firstLoad) {
    LecturesSearchRowSet lecturesList=requestHandler.fetch();
    if (lecturesList != null) {
      List<LecturesSearchRow> lectures=lecturesList.getLehrveranstaltungen();
      manager.replaceInto(lectures);
    }
  }
  populateCurrentChatMember();
  if (!firstLoad) {
    try {
      List<ChatRoom> rooms=ChatClient.getInstance(this).getMemberRooms(currentChatMember.getId(),new ChatVerification(currentPrivateKey,currentChatMember));
      manager.replaceIntoRooms(rooms);
    }
 catch (    RetrofitError e) {
      Utils.log(e);
      return null;
    }
  }
  firstLoad=false;
  return manager.getAllByStatus(mCurrentMode);
}
Program: 161607
Project: 161607
Buggy source:
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  lvMyLecturesList=(StickyListHeadersListView)findViewById(R.id.lvMyLecturesList);
  lvMyLecturesList.setOnItemClickListener(this);
  manager=new ChatRoomManager(this);
  requestHandler=new TUMOnlineRequest<LecturesSearchRowSet>(TUMOnlineConst.LECTURES_PERSONAL,this,true);
  final ActionBar actionBar=getSupportActionBar();
  actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  ActionBar.TabListener tabListener=new ActionBar.TabListener(){
    public void onTabSelected(    ActionBar.Tab tab,    FragmentTransaction ft){
      mCurrentMode=1 - tab.getPosition();
      startLoading(mCurrentMode);
    }
    public void onTabUnselected(    ActionBar.Tab tab,    FragmentTransaction ft){
    }
    public void onTabReselected(    ActionBar.Tab tab,    FragmentTransaction ft){
    }
  }
;
  actionBar.addTab(actionBar.newTab().setText(R.string.joined).setTabListener(tabListener));
  actionBar.addTab(actionBar.newTab().setText(R.string.not_joined).setTabListener(tabListener));
}

Fixed version (ground truth):
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  lvMyLecturesList=(StickyListHeadersListView)findViewById(R.id.lvMyLecturesList);
  lvMyLecturesList.setOnItemClickListener(this);
  manager=new ChatRoomManager(this);
  requestHandler=new TUMOnlineRequest<LecturesSearchRowSet>(TUMOnlineConst.LECTURES_PERSONAL,this,true);
  final ActionBar actionBar=getSupportActionBar();
  actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  ActionBar.TabListener tabListener=new ActionBar.TabListener(){
    public void onTabSelected(    ActionBar.Tab tab,    FragmentTransaction ft){
      mCurrentMode=1 - tab.getPosition();
      firstLoad=true;
      startLoading();
    }
    public void onTabUnselected(    ActionBar.Tab tab,    FragmentTransaction ft){
    }
    public void onTabReselected(    ActionBar.Tab tab,    FragmentTransaction ft){
    }
  }
;
  actionBar.addTab(actionBar.newTab().setText(R.string.joined).setTabListener(tabListener));
  actionBar.addTab(actionBar.newTab().setText(R.string.not_joined).setTabListener(tabListener));
}
Program: 161608
Project: 161608
Buggy source:
public void onTabSelected(ActionBar.Tab tab,FragmentTransaction ft){
  mCurrentMode=1 - tab.getPosition();
  startLoading(mCurrentMode);
}

Fixed version (ground truth):
public void onTabSelected(ActionBar.Tab tab,FragmentTransaction ft){
  mCurrentMode=1 - tab.getPosition();
  firstLoad=true;
  startLoading();
}
Program: 161609
Project: 161609
Buggy source:
@Override public long getHeaderId(int i){
  Cursor item=(Cursor)getItem(i);
  String semesterId=item.getString(ChatRoomManager.COL_SEMESTER_ID);
  if (!filters.contains(semesterId)) {
    filters.add(semesterId);
  }
  return filters.indexOf(semesterId);
}

Fixed version (ground truth):
@Override public long getHeaderId(int i){
  Cursor item=(Cursor)getItem(i);
  String semester=item.getString(ChatRoomManager.COL_SEMESTER);
  if (!filters.contains(semester)) {
    filters.add(semester);
  }
  return filters.indexOf(semester);
}
Program: 161610
Project: 161610
Buggy source:
/** 
 * this function allows us to import all lecture items from TUMOnline
 */
void importLecturesFromTUMOnline(){
  TUMOnlineRequest<LecturesSearchRowSet> requestHandler=new TUMOnlineRequest<LecturesSearchRowSet>(TUMOnlineConst.LECTURES_PERSONAL,mContext);
  if (!shouldRefresh(requestHandler.getRequestURL()))   return;
  requestHandler.fetch();
}

Fixed version (ground truth):
/** 
 * this function allows us to import all lecture items from TUMOnline
 */
void importLecturesFromTUMOnline(){
  TUMOnlineRequest<LecturesSearchRowSet> requestHandler=new TUMOnlineRequest<LecturesSearchRowSet>(TUMOnlineConst.LECTURES_PERSONAL,mContext);
  if (!shouldRefresh(requestHandler.getRequestURL()))   return;
  LecturesSearchRowSet lecturesList=requestHandler.fetch();
  List<LecturesSearchRow> lectures=lecturesList.getLehrveranstaltungen();
  ChatRoomManager manager=new ChatRoomManager(mContext);
  manager.replaceInto(lectures);
}
Program: 161611
Project: 161611
Buggy source:
/** 
 * Saves the given chat rooms into database
 */
public void replaceIntoRooms(List<ChatRoom> rooms){
  for (  ChatRoom room : rooms) {
    String roomName=room.getName();
    String semester="String_Node_Str";
    if (roomName.contains("String_Node_Str")) {
      semester=roomName.substring(0,3);
      roomName=roomName.substring(4);
    }
    Cursor cur=db.rawQuery("String_Node_Str",new String[]{roomName,semester});
    cur.moveToFirst();
    if (cur.getCount() >= 1) {
      db.execSQL("String_Node_Str",new String[]{"String_Node_Str" + room.getId(),roomName,semester});
    }
 else {
      db.execSQL("String_Node_Str" + "String_Node_Str",new String[]{roomName,semester});
    }
  }
}

Fixed version (ground truth):
/** 
 * Saves the given chat rooms into database
 */
public void replaceIntoRooms(List<ChatRoom> rooms){
  for (  ChatRoom room : rooms) {
    String roomName=room.getName();
    String semester="String_Node_Str";
    if (roomName.contains("String_Node_Str")) {
      semester=roomName.substring(0,3);
      roomName=roomName.substring(4);
    }
    Cursor cur=db.rawQuery("String_Node_Str",new String[]{roomName,semester});
    cur.moveToFirst();
    if (cur.getCount() >= 1) {
      db.execSQL("String_Node_Str",new String[]{"String_Node_Str" + room.getId(),roomName,semester});
    }
 else {
      db.execSQL("String_Node_Str" + "String_Node_Str",new String[]{"String_Node_Str" + room.getId(),roomName,semester});
    }
  }
}
Program: 161612
Project: 161612
Buggy source:
/** 
 * Setup action bar navigation (to switch between cafeterias)
 */
@Override protected void onStart(){
  super.onStart();
  mCafeterias=new LocationManager(this).getCafeterias();
  int selIndex=-1;
  for (int i=0; i < mCafeterias.size(); i++) {
    Cafeteria c=mCafeterias.get(i);
    if (mCafeteriaId == -1 || mCafeteriaId == c.id) {
      mCafeteriaId=c.id;
      selIndex=i;
      break;
    }
  }
  if (mCafeterias.size() == 0) {
    showErrorLayout();
    return;
  }
  ArrayAdapter adapterCafeterias=new ArrayAdapter<Cafeteria>(this,R.layout.simple_spinner_item_actionbar,mCafeterias){
    final LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    @Override public View getDropDownView(    int position,    View convertView,    ViewGroup parent){
      View v=inflater.inflate(R.layout.simple_spinner_dropdown_item_actionbar,parent,false);
      Cafeteria c=getItem(position);
      TextView name=(TextView)v.findViewById(android.R.id.text1);
      name.setText(c.name);
      TextView address=(TextView)v.findViewById(android.R.id.text2);
      address.setText(c.address);
      TextView dist=(TextView)v.findViewById(R.id.distance);
      dist.setText(Utils.formatDist(c.distance));
      return v;
    }
  }
;
  getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
  getSupportActionBar().setListNavigationCallbacks(adapterCafeterias,this);
  if (selIndex > -1)   getSupportActionBar().setSelectedNavigationItem(selIndex);
}

Fixed version (ground truth):
/** 
 * Setup action bar navigation (to switch between cafeterias)
 */
@Override protected void onStart(){
  super.onStart();
  mCafeterias=new LocationManager(this).getCafeterias();
  if (mCafeterias.size() == 0) {
    if (!NetUtils.isConnected(this)) {
      showNoInternetLayout();
    }
 else {
      showErrorLayout();
    }
    return;
  }
  int selIndex=-1;
  for (int i=0; i < mCafeterias.size(); i++) {
    Cafeteria c=mCafeterias.get(i);
    if (mCafeteriaId == -1 || mCafeteriaId == c.id) {
      mCafeteriaId=c.id;
      selIndex=i;
      break;
    }
  }
  ArrayAdapter adapterCafeterias=new ArrayAdapter<Cafeteria>(this,R.layout.simple_spinner_item_actionbar,mCafeterias){
    final LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    @Override public View getDropDownView(    int position,    View convertView,    ViewGroup parent){
      View v=inflater.inflate(R.layout.simple_spinner_dropdown_item_actionbar,parent,false);
      Cafeteria c=getItem(position);
      TextView name=(TextView)v.findViewById(android.R.id.text1);
      name.setText(c.name);
      TextView address=(TextView)v.findViewById(android.R.id.text2);
      address.setText(c.address);
      TextView dist=(TextView)v.findViewById(R.id.distance);
      dist.setText(Utils.formatDist(c.distance));
      return v;
    }
  }
;
  getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
  getSupportActionBar().setListNavigationCallbacks(adapterCafeterias,this);
  if (selIndex > -1)   getSupportActionBar().setSelectedNavigationItem(selIndex);
}
Program: 161613
Project: 161613
Buggy source:
@Override protected Cursor onLoadInBackground(Void... arg){
  if (!firstLoad) {
    LecturesSearchRowSet lecturesList=requestHandler.fetch();
    if (lecturesList != null) {
      List<LecturesSearchRow> lectures=lecturesList.getLehrveranstaltungen();
      manager.replaceInto(lectures);
    }
  }
  populateCurrentChatMember();
  if (!firstLoad) {
    try {
      List<ChatRoom> rooms=ChatClient.getInstance(this).getMemberRooms(currentChatMember.getId(),new ChatVerification(currentPrivateKey,currentChatMember));
      manager.replaceIntoRooms(rooms);
    }
 catch (    RetrofitError e) {
      Utils.log(e);
      return null;
    }
  }
  firstLoad=false;
  return manager.getAllByStatus(mCurrentMode);
}

Fixed version (ground truth):
@Override protected Cursor onLoadInBackground(Void... arg){
  if (!firstLoad) {
    LecturesSearchRowSet lecturesList=requestHandler.fetch();
    if (lecturesList != null) {
      List<LecturesSearchRow> lectures=lecturesList.getLehrveranstaltungen();
      manager.replaceInto(lectures);
    }
  }
  populateCurrentChatMember();
  if (!firstLoad && currentChatMember != null) {
    try {
      List<ChatRoom> rooms=ChatClient.getInstance(this).getMemberRooms(currentChatMember.getId(),new ChatVerification(currentPrivateKey,currentChatMember));
      manager.replaceIntoRooms(rooms);
    }
 catch (    RetrofitError e) {
      Utils.log(e);
      return null;
    }
  }
  firstLoad=false;
  return manager.getAllByStatus(mCurrentMode);
}
Program: 161614
Project: 161614
Buggy source:
@Override protected void onStart(){
  super.onStart();
  nm=new NewsManager(this);
  Cursor cursor=nm.getAllFromDb(this);
  if (cursor.getCount() > 0) {
    NewsAdapter adapter=new NewsAdapter(this,cursor);
    lv=(ListView)findViewById(R.id.activity_news_list_view);
    lv.setOnItemClickListener(this);
    lv.setDividerHeight(0);
    lv.setAdapter(adapter);
    lv.setSelection(nm.getTodayIndex());
    if (state != null)     lv.onRestoreInstanceState(state);
  }
 else {
    showErrorLayout();
  }
}

Fixed version (ground truth):
@Override protected void onStart(){
  super.onStart();
  nm=new NewsManager(this);
  Cursor cursor=nm.getAllFromDb(this);
  if (cursor.getCount() > 0) {
    NewsAdapter adapter=new NewsAdapter(this,cursor);
    lv=(ListView)findViewById(R.id.activity_news_list_view);
    lv.setOnItemClickListener(this);
    lv.setDividerHeight(0);
    lv.setAdapter(adapter);
    lv.setSelection(nm.getTodayIndex());
    if (state != null)     lv.onRestoreInstanceState(state);
  }
 else   if (!NetUtils.isConnected(this)) {
    showNoInternetLayout();
  }
 else {
    showErrorLayout();
  }
}
Program: 161615
Project: 161615
Buggy source:
/** 
 * Shows the stations
 * @param stationCursor Cursor with stations (name, _id)
 */
@Override protected void onSearchFinished(Cursor stationCursor){
  showLoadingEnded();
  if (stationCursor == null)   return;
  if (stationCursor.getCount() == 1 && mQuery != null) {
    stationCursor.moveToFirst();
    showStation(stationCursor.getString(0));
    return;
  }
 else   if (stationCursor.getCount() == 0) {
    if (stationCursor instanceof MatrixCursor) {
      listViewResults.setAdapter(new NoResultsAdapter(this));
      listViewResults.requestFocus();
    }
 else {
      finish();
    }
    return;
  }
  adapterStations.changeCursor(stationCursor);
  listViewResults.setAdapter(adapterStations);
  listViewResults.requestFocus();
}

Fixed version (ground truth):
/** 
 * Shows the stations
 * @param stationCursor Cursor with stations (name, _id)
 */
@Override protected void onSearchFinished(Cursor stationCursor){
  if (stationCursor == null)   return;
  showLoadingEnded();
  if (stationCursor.getCount() == 1 && mQuery != null) {
    stationCursor.moveToFirst();
    showStation(stationCursor.getString(0));
    return;
  }
 else   if (stationCursor.getCount() == 0) {
    if (stationCursor instanceof MatrixCursor) {
      listViewResults.setAdapter(new NoResultsAdapter(this));
      listViewResults.requestFocus();
    }
 else {
      finish();
    }
    return;
  }
  adapterStations.changeCursor(stationCursor);
  listViewResults.setAdapter(adapterStations);
  listViewResults.requestFocus();
}