Program: 102443
Project: 102443
Buggy source:
@POST @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 addSpacesMemberships(@Context UriInfo uriInfo,@ApiParam(value="String_Node_Str",required=false) @QueryParam("String_Node_Str") String expand,@ApiParam(value="String_Node_Str",required=true) SpaceMembershipEntity model) throws Exception {
  if (model == null || model.getUser() == null || model.getSpace() == null) {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  String user=model.getUser();
  String space=model.getSpace();
  String authenticatedUser=ConversationState.getCurrent().getIdentity().getUserId();
  SpaceService spaceService=CommonsUtils.getService(SpaceService.class);
  if (space == null || spaceService.getSpaceByDisplayName(space) == null) {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  Space givenSpace=spaceService.getSpaceByDisplayName(space);
  IdentityManager identityManager=CommonsUtils.getService(IdentityManager.class);
  if (user == null || identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,user,true) == null) {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  if (RestUtils.isMemberOfAdminGroup() || spaceService.isManager(givenSpace,authenticatedUser) || (authenticatedUser.equals(user) && givenSpace.getRegistration().equals(Space.OPEN))) {
    spaceService.addMember(givenSpace,user);
    if ("String_Node_Str".equals(model.getRole())) {
      spaceService.setManager(givenSpace,user,true);
    }
  }
 else {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  SpaceMembershipEntity membershipEntity=EntityBuilder.buildEntityFromSpaceMembership(givenSpace,user,"String_Node_Str",uriInfo.getPath(),expand);
  return EntityBuilder.getResponse(membershipEntity,uriInfo,RestUtils.getJsonMediaType(),Response.Status.OK);
}

Fixed version (ground truth):
@POST @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 addSpacesMemberships(@Context UriInfo uriInfo,@ApiParam(value="String_Node_Str",required=false) @QueryParam("String_Node_Str") String expand,@ApiParam(value="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",required=true) SpaceMembershipEntity model) throws Exception {
  if (model == null || model.getUser() == null || model.getSpace() == null) {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  String user=model.getUser();
  String space=model.getSpace();
  String authenticatedUser=ConversationState.getCurrent().getIdentity().getUserId();
  SpaceService spaceService=CommonsUtils.getService(SpaceService.class);
  if (space == null || spaceService.getSpaceByDisplayName(space) == null) {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  Space givenSpace=spaceService.getSpaceByDisplayName(space);
  IdentityManager identityManager=CommonsUtils.getService(IdentityManager.class);
  if (user == null || identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,user,true) == null) {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  if (RestUtils.isMemberOfAdminGroup() || spaceService.isManager(givenSpace,authenticatedUser) || (authenticatedUser.equals(user) && givenSpace.getRegistration().equals(Space.OPEN))) {
    spaceService.addMember(givenSpace,user);
    if ("String_Node_Str".equals(model.getRole())) {
      spaceService.setManager(givenSpace,user,true);
    }
  }
 else {
    throw new WebApplicationException(Response.Status.UNAUTHORIZED);
  }
  SpaceMembershipEntity membershipEntity=EntityBuilder.buildEntityFromSpaceMembership(givenSpace,user,"String_Node_Str",uriInfo.getPath(),expand);
  return EntityBuilder.getResponse(membershipEntity,uriInfo,RestUtils.getJsonMediaType(),Response.Status.OK);
}