Program: 44626
Project: 44626
Buggy source:
private Object grantOrDenyAccessToContentObject(ProceedingJoinPoint proceedingJoinPoint,String contentObjectIdOrSystemName,Object[] methodParameters,ResourceRepresentationType contentObjectOutput){
  if (contentObjectIdIsNotNull(contentObjectIdOrSystemName)) {
    SecurityContext activeSecurityContext=AbstractSecureContentObjectAspect.retrieveSecurityContext();
    Node contentObjectNode=null;
    try {
      if (!(proceedingJoinPoint.getTarget() instanceof ContentServiceImpl)) {
        return generateEmptyOutcome(contentObjectOutput);
      }
      contentObjectNode=((ContentServiceImpl)proceedingJoinPoint.getTarget()).getContentObjectNodeByIdOrSystemName(contentObjectIdOrSystemName);
      if (contentObjectNode == null) {
        return generateEmptyOutcome(contentObjectOutput);
      }
      String userId=activeSecurityContext.getIdentity();
      if (!AbstractSecureContentObjectAspect.userHasRole(activeSecurityContext,CmsRoleAffiliationFactory.INSTANCE.getCmsRoleAffiliationForActiveRepository(CmsRole.ROLE_CMS_INTERNAL_VIEWER))) {
        if (!contentObjectNode.hasProperty("String_Node_Str")) {
          logger.debug("String_Node_Str" + "String_Node_Str",userId,contentObjectIdOrSystemName);
          return generateEmptyOutcome(contentObjectOutput);
        }
        String profileContentObjectStatus=contentObjectNode.getProperty("String_Node_Str").getString();
        if (StringUtils.equals(ContentObjectStatus.published.toString(),profileContentObjectStatus) || StringUtils.equals(ContentObjectStatus.publishedAndArchived.toString(),profileContentObjectStatus)) {
          logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,profileContentObjectStatus});
          return proceedingJoinPoint.proceed(methodParameters);
        }
        logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,profileContentObjectStatus});
        return generateEmptyOutcome(contentObjectOutput);
      }
 else       if (!AbstractSecureContentObjectAspect.userHasRole(activeSecurityContext,CmsRoleAffiliationFactory.INSTANCE.getCmsRoleAffiliationForActiveRepository(CmsRole.ROLE_ADMIN))) {
        Subject subject=activeSecurityContext.getSubject();
        if (subject != null && CollectionUtils.isNotEmpty(subject.getPrincipals(RepositoryUserIdPrincipal.class)) && contentObjectNode.hasProperty(CmsBuiltInItem.OwnerCmsIdentifier.getJcrName())) {
          RepositoryUserIdPrincipal ownerIdPrincipal=subject.getPrincipals(RepositoryUserIdPrincipal.class).iterator().next();
          String ownerId=contentObjectNode.getProperty(CmsBuiltInItem.OwnerCmsIdentifier.getJcrName()).getString();
          if (StringUtils.equals(ownerId,ownerIdPrincipal.getName())) {
            logger.debug("String_Node_Str",userId,contentObjectIdOrSystemName);
            return proceedingJoinPoint.proceed(methodParameters);
          }
        }
        if (!contentObjectNode.hasProperty("String_Node_Str")) {
          logger.debug("String_Node_Str" + "String_Node_Str",userId,contentObjectIdOrSystemName);
          return generateEmptyOutcome(contentObjectOutput);
        }
        Value[] canBeReadByArr=contentObjectNode.getProperty("String_Node_Str").getValues();
        List<String> canBeReadBy=new ArrayList<String>();
        for (        Value value : canBeReadByArr) {
          canBeReadBy.add(value.getString());
        }
        if (canBeReadBy.contains(ContentAccessMode.ALL.toString())) {
          logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,canBeReadBy.toString()});
          return proceedingJoinPoint.proceed(methodParameters);
        }
        if (canBeReadBy.contains(ContentAccessMode.NONE.toString())) {
          logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,canBeReadBy.toString()});
          return generateEmptyOutcome(contentObjectOutput);
        }
        List<String> prefixedRoles=activeSecurityContext.getAllRoles();
        prefixedRoles.add(userId);
        for (        String prefixedRole : prefixedRoles) {
          if (canBeReadBy.contains(prefixedRole)) {
            logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,prefixedRole});
            return proceedingJoinPoint.proceed(methodParameters);
          }
        }
        logger.debug("String_Node_Str" + "String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,canBeReadBy,prefixedRoles});
        return generateEmptyOutcome(contentObjectOutput);
      }
 else {
        logger.debug("String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName});
        return proceedingJoinPoint.proceed(methodParameters);
      }
    }
 catch (    CmsException e) {
      throw e;
    }
catch (    Throwable e) {
      throw new CmsException(e);
    }
  }
 else {
    logger.debug("String_Node_Str",contentObjectIdOrSystemName);
    return generateEmptyOutcome(contentObjectOutput);
  }
}

Fixed version (ground truth):
private Object grantOrDenyAccessToContentObject(ProceedingJoinPoint proceedingJoinPoint,String contentObjectIdOrSystemName,Object[] methodParameters,ResourceRepresentationType contentObjectOutput){
  if (contentObjectIdIsNotNull(contentObjectIdOrSystemName)) {
    SecurityContext activeSecurityContext=AbstractSecureContentObjectAspect.retrieveSecurityContext();
    Node contentObjectNode=null;
    try {
      if (!(proceedingJoinPoint.getTarget() instanceof ContentServiceImpl)) {
        return generateEmptyOutcome(contentObjectOutput);
      }
      contentObjectNode=((ContentServiceImpl)proceedingJoinPoint.getTarget()).getContentObjectNodeByIdOrSystemName(contentObjectIdOrSystemName);
      if (contentObjectNode == null) {
        return generateEmptyOutcome(contentObjectOutput);
      }
      String userId=activeSecurityContext.getIdentity();
      if (!AbstractSecureContentObjectAspect.userHasRole(activeSecurityContext,CmsRoleAffiliationFactory.INSTANCE.getCmsRoleAffiliationForActiveRepository(CmsRole.ROLE_CMS_INTERNAL_VIEWER))) {
        if (!contentObjectNode.hasProperty("String_Node_Str")) {
          logger.debug("String_Node_Str" + "String_Node_Str",userId,contentObjectIdOrSystemName);
          return generateEmptyOutcome(contentObjectOutput);
        }
        String profileContentObjectStatus=contentObjectNode.getProperty("String_Node_Str").getString();
        if (StringUtils.equals(ContentObjectStatus.published.toString(),profileContentObjectStatus) || StringUtils.equals(ContentObjectStatus.publishedAndArchived.toString(),profileContentObjectStatus)) {
          logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,profileContentObjectStatus});
          if (!CmsConstants.UUIDPattern.matcher(contentObjectIdOrSystemName).matches() && methodParameters != null && methodParameters.length > 1 && contentObjectNode.hasProperty(CmsBuiltInItem.CmsIdentifier.getJcrName())) {
            methodParameters[0]=contentObjectNode.getProperty(CmsBuiltInItem.CmsIdentifier.getJcrName()).getString();
          }
          return proceedingJoinPoint.proceed(methodParameters);
        }
        logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,profileContentObjectStatus});
        return generateEmptyOutcome(contentObjectOutput);
      }
 else       if (!AbstractSecureContentObjectAspect.userHasRole(activeSecurityContext,CmsRoleAffiliationFactory.INSTANCE.getCmsRoleAffiliationForActiveRepository(CmsRole.ROLE_ADMIN))) {
        Subject subject=activeSecurityContext.getSubject();
        if (subject != null && CollectionUtils.isNotEmpty(subject.getPrincipals(RepositoryUserIdPrincipal.class)) && contentObjectNode.hasProperty(CmsBuiltInItem.OwnerCmsIdentifier.getJcrName())) {
          RepositoryUserIdPrincipal ownerIdPrincipal=subject.getPrincipals(RepositoryUserIdPrincipal.class).iterator().next();
          String ownerId=contentObjectNode.getProperty(CmsBuiltInItem.OwnerCmsIdentifier.getJcrName()).getString();
          if (StringUtils.equals(ownerId,ownerIdPrincipal.getName())) {
            logger.debug("String_Node_Str",userId,contentObjectIdOrSystemName);
            if (!CmsConstants.UUIDPattern.matcher(contentObjectIdOrSystemName).matches() && methodParameters != null && methodParameters.length > 1 && contentObjectNode.hasProperty(CmsBuiltInItem.CmsIdentifier.getJcrName())) {
              methodParameters[0]=contentObjectNode.getProperty(CmsBuiltInItem.CmsIdentifier.getJcrName()).getString();
            }
            return proceedingJoinPoint.proceed(methodParameters);
          }
        }
        if (!contentObjectNode.hasProperty("String_Node_Str")) {
          logger.debug("String_Node_Str" + "String_Node_Str",userId,contentObjectIdOrSystemName);
          return generateEmptyOutcome(contentObjectOutput);
        }
        Value[] canBeReadByArr=contentObjectNode.getProperty("String_Node_Str").getValues();
        List<String> canBeReadBy=new ArrayList<String>();
        for (        Value value : canBeReadByArr) {
          canBeReadBy.add(value.getString());
        }
        if (canBeReadBy.contains(ContentAccessMode.ALL.toString())) {
          logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,canBeReadBy.toString()});
          if (!CmsConstants.UUIDPattern.matcher(contentObjectIdOrSystemName).matches() && methodParameters != null && methodParameters.length > 1 && contentObjectNode.hasProperty(CmsBuiltInItem.CmsIdentifier.getJcrName())) {
            methodParameters[0]=contentObjectNode.getProperty(CmsBuiltInItem.CmsIdentifier.getJcrName()).getString();
          }
          return proceedingJoinPoint.proceed(methodParameters);
        }
        if (canBeReadBy.contains(ContentAccessMode.NONE.toString())) {
          logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,canBeReadBy.toString()});
          return generateEmptyOutcome(contentObjectOutput);
        }
        List<String> prefixedRoles=activeSecurityContext.getAllRoles();
        prefixedRoles.add(userId);
        for (        String prefixedRole : prefixedRoles) {
          if (canBeReadBy.contains(prefixedRole)) {
            logger.debug("String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,prefixedRole});
            if (!CmsConstants.UUIDPattern.matcher(contentObjectIdOrSystemName).matches() && methodParameters != null && methodParameters.length > 1 && contentObjectNode.hasProperty(CmsBuiltInItem.CmsIdentifier.getJcrName())) {
              methodParameters[0]=contentObjectNode.getProperty(CmsBuiltInItem.CmsIdentifier.getJcrName()).getString();
            }
            return proceedingJoinPoint.proceed(methodParameters);
          }
        }
        logger.debug("String_Node_Str" + "String_Node_Str" + "String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName,canBeReadBy,prefixedRoles});
        return generateEmptyOutcome(contentObjectOutput);
      }
 else {
        logger.debug("String_Node_Str",new Object[]{userId,contentObjectIdOrSystemName});
        if (!CmsConstants.UUIDPattern.matcher(contentObjectIdOrSystemName).matches() && methodParameters != null && methodParameters.length > 1 && contentObjectNode.hasProperty(CmsBuiltInItem.CmsIdentifier.getJcrName())) {
          methodParameters[0]=contentObjectNode.getProperty(CmsBuiltInItem.CmsIdentifier.getJcrName()).getString();
        }
        return proceedingJoinPoint.proceed(methodParameters);
      }
    }
 catch (    CmsException e) {
      throw e;
    }
catch (    Throwable e) {
      throw new CmsException(e);
    }
  }
 else {
    logger.debug("String_Node_Str",contentObjectIdOrSystemName);
    return generateEmptyOutcome(contentObjectOutput);
  }
}