Program: 15427
Project: 15427
Buggy source:
private void doSubredditListRequest(final RedditSubredditManager.SubredditListType type,final RequestResponseHandler<WritableHashSet,SubredditRequestFailure> handler,final String after){
  URI uri;
switch (type) {
case SUBSCRIBED:
    uri=Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_MINE_SUBSCRIBER);
  break;
case MODERATED:
uri=Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_MINE_MODERATOR);
break;
case MOST_POPULAR:
uri=Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_POPULAR);
break;
default :
throw new UnexpectedInternalStateException(type.name());
}
if (after != null) {
final Uri.Builder builder=Uri.parse(uri.toString()).buildUpon();
builder.appendQueryParameter("String_Node_Str",after);
uri=General.uriFromString(builder.toString());
}
final CacheRequest aboutSubredditCacheRequest=new CacheRequest(uri,user,null,Constants.Priority.API_SUBREDDIT_INVIDIVUAL,0,CacheRequest.DownloadType.FORCE,Constants.FileType.SUBREDDIT_LIST,true,true,false,context){
@Override protected void onCallbackException(Throwable t){
handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE,t,null,"String_Node_Str",url));
}
@Override protected void onDownloadNecessary(){
}
@Override protected void onDownloadStarted(){
}
@Override protected void onProgress(long bytesRead,long totalBytes){
}
@Override protected void onFailure(RequestFailureType type,Throwable t,StatusLine status,String readableMessage){
handler.onRequestFailed(new SubredditRequestFailure(type,t,status,readableMessage,url.toString()));
}
@Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile,long timestamp,UUID session,boolean fromCache,String mimetype){
}
@Override public void onJsonParseStarted(JsonValue result,long timestamp,UUID session,boolean fromCache){
try {
final HashSet<String> output=new HashSet<String>();
final ArrayList<RedditSubreddit> toWrite=new ArrayList<RedditSubreddit>();
final JsonBufferedObject redditListing=result.asObject().getObject("String_Node_Str");
final JsonBufferedArray subreddits=redditListing.getArray("String_Node_Str");
final JsonBuffered.Status joinStatus=subreddits.join();
if (joinStatus == JsonBuffered.Status.FAILED) {
handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE,null,null,"String_Node_Str",url.toString()));
return;
}
if (type == RedditSubredditManager.SubredditListType.SUBSCRIBED && subreddits.getCurrentItemCount() == 0) {
doSubredditListRequest(RedditSubredditManager.SubredditListType.MOST_POPULAR,handler,null);
return;
}
for (final JsonValue v : subreddits) {
final RedditThing thing=v.asObject(RedditThing.class);
final RedditSubreddit subreddit=thing.asSubreddit();
subreddit.downloadTime=timestamp;
toWrite.add(subreddit);
output.add(subreddit.getCanonicalName());
}
RedditSubredditManager.getInstance(context,user).offerRawSubredditData(toWrite,timestamp);
final String receivedAfter=redditListing.getString("String_Node_Str");
if (receivedAfter != null) {
doSubredditListRequest(type,new RequestResponseHandler<WritableHashSet,SubredditRequestFailure>(){
public void onRequestFailed(SubredditRequestFailure failureReason){
handler.onRequestFailed(failureReason);
}
public void onRequestSuccess(WritableHashSet result,long timeCached){
output.addAll(result.toHashset());
handler.onRequestSuccess(new WritableHashSet(output,timeCached,type.name()),timeCached);
}
}
,receivedAfter);
}
 else {
handler.onRequestSuccess(new WritableHashSet(output,timestamp,type.name()),timestamp);
}
}
 catch (Exception e) {
handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE,e,null,"String_Node_Str",url.toString()));
}
}
}
;
CacheManager.getInstance(context).makeRequest(aboutSubredditCacheRequest);
}

Fixed version (ground truth):
private void doSubredditListRequest(final RedditSubredditManager.SubredditListType type,final RequestResponseHandler<WritableHashSet,SubredditRequestFailure> handler,final String after){
  URI uri;
switch (type) {
case SUBSCRIBED:
    uri=Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_MINE_SUBSCRIBER);
  break;
case MODERATED:
uri=Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_MINE_MODERATOR);
break;
case MOST_POPULAR:
uri=Constants.Reddit.getUri(Constants.Reddit.PATH_SUBREDDITS_POPULAR);
break;
default :
throw new UnexpectedInternalStateException(type.name());
}
if (after != null) {
final Uri.Builder builder=Uri.parse(uri.toString()).buildUpon();
builder.appendQueryParameter("String_Node_Str",after);
uri=General.uriFromString(builder.toString());
}
final CacheRequest aboutSubredditCacheRequest=new CacheRequest(uri,user,null,Constants.Priority.API_SUBREDDIT_INVIDIVUAL,0,CacheRequest.DownloadType.FORCE,Constants.FileType.SUBREDDIT_LIST,true,true,false,context){
@Override protected void onCallbackException(Throwable t){
handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE,t,null,"String_Node_Str",url));
}
@Override protected void onDownloadNecessary(){
}
@Override protected void onDownloadStarted(){
}
@Override protected void onProgress(long bytesRead,long totalBytes){
}
@Override protected void onFailure(RequestFailureType type,Throwable t,StatusLine status,String readableMessage){
handler.onRequestFailed(new SubredditRequestFailure(type,t,status,readableMessage,url.toString()));
}
@Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile,long timestamp,UUID session,boolean fromCache,String mimetype){
}
@Override public void onJsonParseStarted(JsonValue result,long timestamp,UUID session,boolean fromCache){
try {
final HashSet<String> output=new HashSet<String>();
final ArrayList<RedditSubreddit> toWrite=new ArrayList<RedditSubreddit>();
final JsonBufferedObject redditListing=result.asObject().getObject("String_Node_Str");
final JsonBufferedArray subreddits=redditListing.getArray("String_Node_Str");
final JsonBuffered.Status joinStatus=subreddits.join();
if (joinStatus == JsonBuffered.Status.FAILED) {
handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE,null,null,"String_Node_Str",url.toString()));
return;
}
if (type == RedditSubredditManager.SubredditListType.SUBSCRIBED && subreddits.getCurrentItemCount() == 0) {
doSubredditListRequest(RedditSubredditManager.SubredditListType.MOST_POPULAR,handler,null);
return;
}
for (final JsonValue v : subreddits) {
final RedditThing thing=v.asObject(RedditThing.class);
final RedditSubreddit subreddit=thing.asSubreddit();
subreddit.downloadTime=timestamp;
toWrite.add(subreddit);
output.add(subreddit.getCanonicalName());
}
RedditSubredditManager.getInstance(context,user).offerRawSubredditData(toWrite,timestamp);
final String receivedAfter=redditListing.getString("String_Node_Str");
if (receivedAfter != null && type != RedditSubredditManager.SubredditListType.MOST_POPULAR) {
doSubredditListRequest(type,new RequestResponseHandler<WritableHashSet,SubredditRequestFailure>(){
public void onRequestFailed(SubredditRequestFailure failureReason){
handler.onRequestFailed(failureReason);
}
public void onRequestSuccess(WritableHashSet result,long timeCached){
output.addAll(result.toHashset());
handler.onRequestSuccess(new WritableHashSet(output,timeCached,type.name()),timeCached);
}
}
,receivedAfter);
}
 else {
handler.onRequestSuccess(new WritableHashSet(output,timestamp,type.name()),timestamp);
}
}
 catch (Exception e) {
handler.onRequestFailed(new SubredditRequestFailure(RequestFailureType.PARSE,e,null,"String_Node_Str",url.toString()));
}
}
}
;
CacheManager.getInstance(context).makeRequest(aboutSubredditCacheRequest);
}