Program: 15396
Project: 15396
Buggy source:
public void action(final Activity activity,final RedditAPI.RedditAction action){
  final RedditAccount user=RedditAccountManager.getInstance(activity).getDefaultAccount();
  if (user.isAnonymous()) {
    General.quickToast(activity,"String_Node_Str");
    return;
  }
  final int lastVoteDirection=voteDirection;
switch (action) {
case DOWNVOTE:
    voteDirection=-1;
  break;
case UNVOTE:
voteDirection=0;
break;
case UPVOTE:
voteDirection=1;
break;
case SAVE:
saved=true;
break;
case UNSAVE:
saved=false;
break;
}
refreshView(activity);
RedditAPI.action(CacheManager.getInstance(activity),new APIResponseHandler.ActionResponseHandler(activity){
@Override protected void onCallbackException(final Throwable t){
throw new RuntimeException(t);
}
@Override protected void onFailure(final RequestFailureType type,final Throwable t,final StatusLine status,final String readableMessage){
revertOnFailure();
if (t != null) t.printStackTrace();
final RRError error=General.getGeneralErrorForFailure(context,type,t,status,null);
General.UI_THREAD_HANDLER.post(new Runnable(){
public void run(){
General.showResultDialog(activity,error);
}
}
);
}
@Override protected void onFailure(final APIFailureType type){
revertOnFailure();
final RRError error=General.getGeneralErrorForFailure(context,type);
General.UI_THREAD_HANDLER.post(new Runnable(){
public void run(){
General.showResultDialog(activity,error);
}
}
);
}
@Override protected void onSuccess(){
lastChange=RRTime.utcCurrentTimeMillis();
RedditChangeDataManager.getInstance(context).update(src.link_id,user,RedditPreparedComment.this,true);
refreshView(activity);
}
private void revertOnFailure(){
switch (action) {
case DOWNVOTE:
case UNVOTE:
case UPVOTE:
voteDirection=lastVoteDirection;
break;
case SAVE:
saved=false;
break;
case UNSAVE:
saved=true;
break;
}
refreshView(context);
}
}
,user,idAndType,action,activity);
}

Fixed version (ground truth):
public void action(final Activity activity,final RedditAPI.RedditAction action){
  final RedditAccount user=RedditAccountManager.getInstance(activity).getDefaultAccount();
  if (user.isAnonymous()) {
    General.quickToast(activity,"String_Node_Str");
    return;
  }
  final int lastVoteDirection=voteDirection;
switch (action) {
case DOWNVOTE:
    if (!src.archived) {
      voteDirection=-1;
    }
  break;
case UNVOTE:
if (!src.archived) {
  voteDirection=0;
}
break;
case UPVOTE:
if (!src.archived) {
voteDirection=1;
}
break;
case SAVE:
saved=true;
break;
case UNSAVE:
saved=false;
break;
}
refreshView(activity);
boolean vote=(action == RedditAPI.RedditAction.DOWNVOTE | action == RedditAPI.RedditAction.UPVOTE | action == RedditAPI.RedditAction.UNVOTE);
if (src.archived && vote) {
Toast.makeText(activity,"String_Node_Str",Toast.LENGTH_SHORT).show();
return;
}
RedditAPI.action(CacheManager.getInstance(activity),new APIResponseHandler.ActionResponseHandler(activity){
@Override protected void onCallbackException(final Throwable t){
throw new RuntimeException(t);
}
@Override protected void onFailure(final RequestFailureType type,final Throwable t,final StatusLine status,final String readableMessage){
revertOnFailure();
if (t != null) t.printStackTrace();
final RRError error=General.getGeneralErrorForFailure(context,type,t,status,null);
General.UI_THREAD_HANDLER.post(new Runnable(){
public void run(){
General.showResultDialog(activity,error);
}
}
);
}
@Override protected void onFailure(final APIFailureType type){
revertOnFailure();
final RRError error=General.getGeneralErrorForFailure(context,type);
General.UI_THREAD_HANDLER.post(new Runnable(){
public void run(){
General.showResultDialog(activity,error);
}
}
);
}
@Override protected void onSuccess(){
lastChange=RRTime.utcCurrentTimeMillis();
RedditChangeDataManager.getInstance(context).update(src.link_id,user,RedditPreparedComment.this,true);
refreshView(activity);
}
private void revertOnFailure(){
switch (action) {
case DOWNVOTE:
case UNVOTE:
case UPVOTE:
voteDirection=lastVoteDirection;
break;
case SAVE:
saved=false;
break;
case UNSAVE:
saved=true;
break;
}
refreshView(context);
}
}
,user,idAndType,action,activity);
}