Program: 102477
Project: 102477
Buggy source:
public Future<Void> createActivity(UserId userId,GroupId groupId,String appId,Set<String> fields,Activity activity,SecurityToken token) throws ProtocolException {
  try {
    activity.setAppId(appId);
    ExoSocialActivity exoActivity=convertFromOSActivity(activity,fields);
    if (token instanceof AnonymousSecurityToken) {
      throw new ProtocolException(HttpServletResponse.SC_UNAUTHORIZED,"String_Node_Str");
    }
    PortalContainer pc=getPortalContainer(token);
    ActivityManager am=(ActivityManager)pc.getComponentInstanceOfType(ActivityManager.class);
    IdentityManager identityManager=(IdentityManager)pc.getComponentInstanceOfType(IdentityManager.class);
    String user=userId.getUserId(token);
    if (user.contains("String_Node_Str")) {
      user=user.split("String_Node_Str")[1];
    }
    Identity userIdentity=identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,user,false);
    Identity targetStream=userIdentity;
    if (groupId.getType() == GroupId.Type.groupId) {
      String group=groupId.getGroupId();
      if (group.contains("String_Node_Str")) {
        group=group.split("String_Node_Str")[1];
      }
      targetStream=identityManager.getOrCreateIdentity(SpaceIdentityProvider.NAME,group,false);
    }
    if (targetStream == null) {
      throw new ProtocolException(HttpServletResponse.SC_FORBIDDEN,user + "String_Node_Str");
    }
    String activityUser=exoActivity.getUserId();
    if (activityUser == null) {
      exoActivity.setUserId(userIdentity.getId());
    }
 else {
      Identity activityUserIdentity=identityManager.getIdentity(activityUser);
      if (activityUserIdentity == null) {
        throw new ProtocolException(HttpServletResponse.SC_FORBIDDEN,activityUser + "String_Node_Str");
      }
    }
    am.saveActivityNoReturn(targetStream,exoActivity);
    return ImmediateFuture.newInstance(null);
  }
 catch (  Throwable e) {
    if (e instanceof ProtocolException) {
      throw (ProtocolException)e;
    }
    throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,e.getMessage(),e);
  }
}

Fixed version (ground truth):
public Future<Void> createActivity(UserId userId,GroupId groupId,String appId,Set<String> fields,Activity activity,SecurityToken token) throws ProtocolException {
  try {
    activity.setAppId(appId);
    ExoSocialActivity exoActivity=convertFromOSActivity(activity,fields);
    if (token instanceof AnonymousSecurityToken) {
      throw new ProtocolException(HttpServletResponse.SC_UNAUTHORIZED,"String_Node_Str");
    }
    PortalContainer pc=getPortalContainer(token);
    ActivityManager am=(ActivityManager)pc.getComponentInstanceOfType(ActivityManager.class);
    IdentityManager identityManager=(IdentityManager)pc.getComponentInstanceOfType(IdentityManager.class);
    String user=userId.getUserId(token);
    if (user.contains("String_Node_Str")) {
      user=user.split("String_Node_Str")[1];
    }
    Identity userIdentity=identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME,user,false);
    Identity targetStream=userIdentity;
    if (groupId.getType() == GroupId.Type.groupId) {
      String group=groupId.getGroupId();
      if (group.contains("String_Node_Str")) {
        group=group.split("String_Node_Str")[1];
      }
      targetStream=identityManager.getOrCreateIdentity(SpaceIdentityProvider.NAME,group,false);
    }
    if (targetStream == null) {
      throw new ProtocolException(HttpServletResponse.SC_FORBIDDEN,user + "String_Node_Str");
    }
    String activityUser=exoActivity.getUserId();
    if (activityUser == null) {
      exoActivity.setUserId(userIdentity.getId());
    }
 else {
      Identity activityUserIdentity=identityManager.getIdentity(activityUser);
      if (activityUserIdentity == null) {
        throw new ProtocolException(HttpServletResponse.SC_FORBIDDEN,activityUser + "String_Node_Str");
      }
    }
    am.saveActivityNoReturn(targetStream,exoActivity);
    return ImmediateFuture.newInstance(null);
  }
 catch (  Exception e) {
    if (e instanceof ProtocolException) {
      throw (ProtocolException)e;
    }
    throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,e.getMessage(),e);
  }
}