Program: 24918
Project: 24918
Buggy source:
@Override protected void onHandleIntent(Intent intent){
  final EventORamaApplication eora=(EventORamaApplication)getApplication();
  final Gson gson=new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
  final Uri uri=EventStreamContentProvider.content_uri;
  HTTPResponse resp=eora.doHttpRequest("String_Node_Str",null,EventORamaApplication.HTTP_METHOD_GET);
  if (resp.getRespCode() == 200) {
    ActivityElement[] serverElements=gson.fromJson(resp.getBody(),ActivityElement[].class);
    Log.v(TAG,"String_Node_Str" + serverElements.length + "String_Node_Str");
    for (int i=0; i < serverElements.length; i++) {
      String timestamp=serverElements[i].getTimestamp() + "String_Node_Str";
      Cursor c=mContentResolver.query(uri,null,EventStreamContentProvider.Columns.CREATED + "String_Node_Str",new String[]{timestamp},null);
      if (c != null && !c.moveToFirst()) {
        ContentValues cv=new ContentValues();
        cv.put(EventStreamContentProvider.Columns.CREATED,serverElements[i].getTimestamp());
        cv.put(EventStreamContentProvider.Columns.PEOPLE_ID,serverElements[i].getUser_id());
        cv.put(EventStreamContentProvider.Columns.TEXT,serverElements[i].getText());
        cv.put(EventStreamContentProvider.Columns.TYPE,serverElements[i].getType());
        cv.put(EventStreamContentProvider.Columns.TYPE,EventStreamContentProvider.SAVE_STATE_SERVER);
        mContentResolver.insert(uri,cv);
        c.close();
      }
 else       Log.v(TAG,"String_Node_Str" + serverElements[i].toString());
    }
  }
  Cursor c=mContentResolver.query(uri,null,EventStreamContentProvider.Columns.SAVE_STATE + "String_Node_Str" + EventStreamContentProvider.SAVE_STATE_LOCAL,null,null);
  if (c != null && c.getCount() > 0) {
    ActivityElement[] activities=new ActivityElement[c.getCount()];
    if (c.moveToFirst()) {
      int counter=0;
      final int idCol=c.getColumnIndex(EventStreamContentProvider.Columns.ID);
      final int textCol=c.getColumnIndex(EventStreamContentProvider.Columns.TEXT);
      final int useridCol=c.getColumnIndex(EventStreamContentProvider.Columns.PEOPLE_ID);
      final int timestampCol=c.getColumnIndex(EventStreamContentProvider.Columns.CREATED);
      final int typeCol=c.getColumnIndex(EventStreamContentProvider.Columns.TYPE);
      do {
        activities[counter]=new ActivityElement(c.getInt(idCol),c.getLong(timestampCol),c.getString(textCol),c.getInt(typeCol),c.getInt(useridCol));
      }
 while (c.moveToNext());
      c.close();
      final String json=gson.toJson(activities);
      Log.v(TAG,"String_Node_Str" + json);
      resp=eora.doHttpRequest("String_Node_Str",json,EventORamaApplication.HTTP_METHOD_POST);
      final int responseCode=resp.getRespCode();
switch (responseCode) {
case 200:
default :
        StringBuilder sb=new StringBuilder(EventStreamContentProvider.Columns.ID).append("String_Node_Str");
      int[] idsfromserver=gson.fromJson(resp.getBody(),int[].class);
    for (int i=0; i < idsfromserver.length; i++) {
      if (idsfromserver[i] > 0) {
        sb.append(activities[i].getInternal_id());
      }
 else       Log.e(TAG,"String_Node_Str" + idsfromserver[i]);
      sb.append(',');
    }
  sb.deleteCharAt(sb.length() - 1);
sb.append("String_Node_Str");
ContentValues cv=new ContentValues();
cv.put(EventStreamContentProvider.Columns.SAVE_STATE,EventStreamContentProvider.SAVE_STATE_SERVER);
int updates=mContentResolver.update(uri,cv,sb.toString(),null);
Log.v(TAG,"String_Node_Str" + updates + "String_Node_Str");
break;
}
}
}
}

Fixed version (ground truth):
@Override protected void onHandleIntent(Intent intent){
  final EventORamaApplication eora=(EventORamaApplication)getApplication();
  final Gson gson=new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
  final Uri uri=EventStreamContentProvider.content_uri;
  HTTPResponse resp=eora.doHttpRequest("String_Node_Str",null,EventORamaApplication.HTTP_METHOD_GET);
  if (resp.getRespCode() == 200) {
    ActivityElement[] serverElements=gson.fromJson(resp.getBody(),ActivityElement[].class);
    Log.v(TAG,"String_Node_Str" + serverElements.length + "String_Node_Str");
    for (int i=0; i < serverElements.length; i++) {
      String timestamp=serverElements[i].getTimestamp() + "String_Node_Str";
      Cursor c=mContentResolver.query(uri,null,EventStreamContentProvider.Columns.CREATED + "String_Node_Str",new String[]{timestamp},null);
      if (c != null && !c.moveToFirst()) {
        ContentValues cv=new ContentValues();
        cv.put(EventStreamContentProvider.Columns.CREATED,serverElements[i].getTimestamp());
        cv.put(EventStreamContentProvider.Columns.PEOPLE_ID,serverElements[i].getUser_id());
        cv.put(EventStreamContentProvider.Columns.TEXT,serverElements[i].getText());
        cv.put(EventStreamContentProvider.Columns.TYPE,serverElements[i].getType());
        cv.put(EventStreamContentProvider.Columns.TYPE,EventStreamContentProvider.SAVE_STATE_SERVER);
        mContentResolver.insert(uri,cv);
      }
 else       Log.v(TAG,"String_Node_Str" + serverElements[i].toString());
      if (c != null)       c.close();
    }
  }
  Cursor c=mContentResolver.query(uri,null,EventStreamContentProvider.Columns.SAVE_STATE + "String_Node_Str" + EventStreamContentProvider.SAVE_STATE_LOCAL,null,null);
  if (c != null && c.getCount() > 0) {
    ActivityElement[] activities=new ActivityElement[c.getCount()];
    if (c.moveToFirst()) {
      int counter=0;
      final int idCol=c.getColumnIndex(EventStreamContentProvider.Columns.ID);
      final int textCol=c.getColumnIndex(EventStreamContentProvider.Columns.TEXT);
      final int useridCol=c.getColumnIndex(EventStreamContentProvider.Columns.PEOPLE_ID);
      final int timestampCol=c.getColumnIndex(EventStreamContentProvider.Columns.CREATED);
      final int typeCol=c.getColumnIndex(EventStreamContentProvider.Columns.TYPE);
      do {
        activities[counter]=new ActivityElement(c.getInt(idCol),c.getLong(timestampCol),c.getString(textCol),c.getInt(typeCol),c.getInt(useridCol));
      }
 while (c.moveToNext());
      final String json=gson.toJson(activities);
      Log.v(TAG,"String_Node_Str" + json);
      resp=eora.doHttpRequest("String_Node_Str",json,EventORamaApplication.HTTP_METHOD_POST);
      final int responseCode=resp.getRespCode();
switch (responseCode) {
case 200:
default :
        StringBuilder sb=new StringBuilder(EventStreamContentProvider.Columns.ID).append("String_Node_Str");
      int[] idsfromserver=gson.fromJson(resp.getBody(),int[].class);
    for (int i=0; i < idsfromserver.length; i++) {
      if (idsfromserver[i] > 0) {
        sb.append(activities[i].getInternal_id());
      }
 else       Log.e(TAG,"String_Node_Str" + idsfromserver[i]);
      sb.append(',');
    }
  sb.deleteCharAt(sb.length() - 1);
sb.append("String_Node_Str");
ContentValues cv=new ContentValues();
cv.put(EventStreamContentProvider.Columns.SAVE_STATE,EventStreamContentProvider.SAVE_STATE_SERVER);
int updates=mContentResolver.update(uri,cv,sb.toString(),null);
Log.v(TAG,"String_Node_Str" + updates + "String_Node_Str");
break;
}
}
}
if (c != null) c.close();
}