Program: 102441
Project: 102441
Buggy source:
/** 
 * {@inheritDoc}
 */
@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") @ApiResponses(value={@ApiResponse(code=200,message="String_Node_Str"),@ApiResponse(code=500,message="String_Node_Str"),@ApiResponse(code=400,message="String_Node_Str")}) public Response getSpaceActivitiesById(@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();
  SpaceService spaceService=CommonsUtils.getService(SpaceService.class);
  Space space=spaceService.getSpaceById(id);
  if (space == null || !spaceService.isMember(space,authenticatedUser)) {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  Identity spaceIdentity=CommonsUtils.getService(IdentityManager.class).getOrCreateIdentity(SpaceIdentityProvider.NAME,space.getPrettyName(),false);
  RealtimeListAccess<ExoSocialActivity> listAccess=CommonsUtils.getService(ActivityManager.class).getActivitiesOfSpaceWithListAccess(spaceIdentity);
  List<ExoSocialActivity> activities=null;
  if (after > 0) {
    activities=listAccess.loadNewer(after,limit);
  }
 else   if (before > 0) {
    activities=listAccess.loadOlder(before,limit);
  }
 else {
    activities=listAccess.loadAsList(offset,limit);
  }
  List<DataEntity> activityEntities=new ArrayList<DataEntity>();
  BaseEntity as=new BaseEntity(spaceIdentity.getRemoteId());
  as.setProperty(RestProperties.TYPE,EntityBuilder.SPACE_ACTIVITY_TYPE);
  for (  ExoSocialActivity activity : activities) {
    ActivityEntity activityInfo=EntityBuilder.buildEntityFromActivity(activity,uriInfo.getPath(),expand);
    activityInfo.setActivityStream(as.getDataEntity());
    activityEntities.add(activityInfo.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):
/** 
 * {@inheritDoc}
 */
@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") @ApiResponses(value={@ApiResponse(code=200,message="String_Node_Str"),@ApiResponse(code=500,message="String_Node_Str"),@ApiResponse(code=400,message="String_Node_Str")}) public Response getSpaceActivitiesById(@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();
  SpaceService spaceService=CommonsUtils.getService(SpaceService.class);
  Space space=spaceService.getSpaceById(id);
  if (space == null || !spaceService.isMember(space,authenticatedUser)) {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  Identity spaceIdentity=CommonsUtils.getService(IdentityManager.class).getOrCreateIdentity(SpaceIdentityProvider.NAME,space.getPrettyName(),false);
  RealtimeListAccess<ExoSocialActivity> listAccess=CommonsUtils.getService(ActivityManager.class).getActivitiesOfSpaceWithListAccess(spaceIdentity);
  List<ExoSocialActivity> activities=null;
  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);
  }
  List<DataEntity> activityEntities=new ArrayList<DataEntity>();
  BaseEntity as=new BaseEntity(spaceIdentity.getRemoteId());
  as.setProperty(RestProperties.TYPE,EntityBuilder.SPACE_ACTIVITY_TYPE);
  for (  ExoSocialActivity activity : activities) {
    ActivityEntity activityInfo=EntityBuilder.buildEntityFromActivity(activity,uriInfo.getPath(),expand);
    activityInfo.setActivityStream(as.getDataEntity());
    activityEntities.add(activityInfo.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);
}