Program: 102444
Project: 102444
Buggy source:
@GET @Path("String_Node_Str") @RolesAllowed("String_Node_Str") @ApiOperation(value="String_Node_Str",httpMethod="String_Node_Str",response=Response.class,notes="String_Node_Str") public Response getActivitiesOfUser(@Context UriInfo uriInfo,@ApiParam(value="String_Node_Str",required=true) @PathParam("String_Node_Str") String id,@ApiParam(value="String_Node_Str",required=false,defaultValue="String_Node_Str") @QueryParam("String_Node_Str") int offset,@ApiParam(value="String_Node_Str",required=false,defaultValue="String_Node_Str") @QueryParam("String_Node_Str") int limit,@ApiParam(value="String_Node_Str",required=false) @QueryParam("String_Node_Str") long before,@ApiParam(value="String_Node_Str",required=false) @QueryParam("String_Node_Str") long after,@ApiParam(value="String_Node_Str",defaultValue="String_Node_Str") @QueryParam("String_Node_Str") boolean returnSize,@ApiParam(value="String_Node_Str",required=false) @QueryParam("String_Node_Str") String expand) throws Exception {
  String authenticatedUser=ConversationState.getCurrent().getIdentity().getUserId();
  Identity target=CommonsUtils.getService(IdentityManager.class).getOrCreateIdentity(OrganizationIdentityProvider.NAME,id,true);
  if (target == null) {
    throw new WebApplicationException(Response.Status.BAD_REQUEST);
  }
  String type=RestUtils.getQueryParam(uriInfo,"String_Node_Str");
  ACTIVITY_STREAM_TYPE streamType;
  try {
    streamType=ACTIVITY_STREAM_TYPE.valueOf(type);
  }
 catch (  Exception e) {
    streamType=ACTIVITY_STREAM_TYPE.all;
  }
  ActivityManager activityManager=CommonsUtils.getService(ActivityManager.class);
  RealtimeListAccess<ExoSocialActivity> listAccess=null;
  List<ExoSocialActivity> activities=null;
switch (streamType) {
case all:
{
      listAccess=activityManager.getActivityFeedWithListAccess(target);
      break;
    }
case owner:
{
    listAccess=activityManager.getActivitiesWithListAccess(target);
    break;
  }
case connections:
{
  listAccess=activityManager.getActivitiesOfConnectionsWithListAccess(target);
  break;
}
case spaces:
{
listAccess=activityManager.getActivitiesOfUserSpacesWithListAccess(target);
break;
}
default :
break;
}
if (after > 0) {
activities=listAccess.loadNewer(after,limit);
}
 else if (before > 0) {
activities=listAccess.loadOlder(before,limit);
}
 else {
activities=listAccess.loadAsList(offset,limit);
}
Identity currentUser=CommonsUtils.getService(IdentityManager.class).getOrCreateIdentity(OrganizationIdentityProvider.NAME,authenticatedUser,true);
List<DataEntity> activityEntities=new ArrayList<DataEntity>();
for (ExoSocialActivity activity : activities) {
DataEntity as=EntityBuilder.getActivityStream(activity,currentUser);
if (as == null) continue;
ActivityEntity activityEntity=EntityBuilder.buildEntityFromActivity(activity,uriInfo.getPath(),expand);
activityEntity.setActivityStream(as);
activityEntities.add(activityEntity.getDataEntity());
}
CollectionEntity collectionActivity=new CollectionEntity(activityEntities,EntityBuilder.ACTIVITIES_TYPE,offset,limit);
if (returnSize) {
collectionActivity.setSize(listAccess.getSize());
}
return EntityBuilder.getResponse(collectionActivity,uriInfo,RestUtils.getJsonMediaType(),Response.Status.OK);
}

Fixed version (ground truth):
@GET @Path("String_Node_Str") @RolesAllowed("String_Node_Str") @ApiOperation(value="String_Node_Str",httpMethod="String_Node_Str",response=Response.class,notes="String_Node_Str") public Response getActivitiesOfUser(@Context UriInfo uriInfo,@ApiParam(value="String_Node_Str",required=true) @PathParam("String_Node_Str") String id,@ApiParam(value="String_Node_Str",required=false,defaultValue="String_Node_Str") @QueryParam("String_Node_Str") int offset,@ApiParam(value="String_Node_Str",required=false,defaultValue="String_Node_Str") @QueryParam("String_Node_Str") int limit,@ApiParam(value="String_Node_Str",required=false) @QueryParam("String_Node_Str") String before,@ApiParam(value="String_Node_Str",required=false) @QueryParam("String_Node_Str") String after,@ApiParam(value="String_Node_Str",defaultValue="String_Node_Str") @QueryParam("String_Node_Str") boolean returnSize,@ApiParam(value="String_Node_Str",required=false) @QueryParam("String_Node_Str") String expand) throws Exception {
  String authenticatedUser=ConversationState.getCurrent().getIdentity().getUserId();
  Identity target=CommonsUtils.getService(IdentityManager.class).getOrCreateIdentity(OrganizationIdentityProvider.NAME,id,true);
  if (target == null) {
    throw new WebApplicationException(Response.Status.BAD_REQUEST);
  }
  String type=RestUtils.getQueryParam(uriInfo,"String_Node_Str");
  ACTIVITY_STREAM_TYPE streamType;
  try {
    streamType=ACTIVITY_STREAM_TYPE.valueOf(type);
  }
 catch (  Exception e) {
    streamType=ACTIVITY_STREAM_TYPE.all;
  }
  ActivityManager activityManager=CommonsUtils.getService(ActivityManager.class);
  RealtimeListAccess<ExoSocialActivity> listAccess=null;
  List<ExoSocialActivity> activities=null;
switch (streamType) {
case all:
{
      listAccess=activityManager.getActivityFeedWithListAccess(target);
      break;
    }
case owner:
{
    listAccess=activityManager.getActivitiesWithListAccess(target);
    break;
  }
case connections:
{
  listAccess=activityManager.getActivitiesOfConnectionsWithListAccess(target);
  break;
}
case spaces:
{
listAccess=activityManager.getActivitiesOfUserSpacesWithListAccess(target);
break;
}
default :
break;
}
if (after != null && RestUtils.getBaseTime(after) > 0) {
activities=listAccess.loadNewer(RestUtils.getBaseTime(after),limit);
}
 else if (before != null && RestUtils.getBaseTime(before) > 0) {
activities=listAccess.loadOlder(RestUtils.getBaseTime(before),limit);
}
 else {
activities=listAccess.loadAsList(offset,limit);
}
Identity currentUser=CommonsUtils.getService(IdentityManager.class).getOrCreateIdentity(OrganizationIdentityProvider.NAME,authenticatedUser,true);
List<DataEntity> activityEntities=new ArrayList<DataEntity>();
for (ExoSocialActivity activity : activities) {
DataEntity as=EntityBuilder.getActivityStream(activity,currentUser);
if (as == null) continue;
ActivityEntity activityEntity=EntityBuilder.buildEntityFromActivity(activity,uriInfo.getPath(),expand);
activityEntity.setActivityStream(as);
activityEntities.add(activityEntity.getDataEntity());
}
CollectionEntity collectionActivity=new CollectionEntity(activityEntities,EntityBuilder.ACTIVITIES_TYPE,offset,limit);
if (returnSize) {
collectionActivity.setSize(listAccess.getSize());
}
return EntityBuilder.getResponse(collectionActivity,uriInfo,RestUtils.getJsonMediaType(),Response.Status.OK);
}