Program: 15027
Project: 15027
Buggy source:
/** 
 * Uses the provided   {@code lookupFunction} to resolve the {@code identifier} to the underlyingobject  {@code T} with privileges determined by the current messaging context.
 * @param < T > type of object which needs looking up
 * @param identifier identifier of the desired object
 * @param lookupFunction class which resolves string identifiers to the underlying object
 * @return the object corresponding with the given {@code identifier}
 * @throws AuthException if the user is not authorized
 * @throws PersistenceException if an error occurred in the underlying retrieval mechanism
 * @throws NoSuchElementException if the requested {@code identifier} does not exist and the useris authorized.
 * @throws IllegalContextAccessException if the current request context cannot be determined.
 */
public static <T extends HasOwningAccount>T doPrivileged(String identifier,Function<String,T> lookupFunction) throws AuthException, IllegalContextAccessException, NoSuchElementException, PersistenceException {
  Context ctx=Contexts.lookup();
  Class<? extends BaseMessage> msgType=ctx.getRequest().getClass();
  LOG.debug("String_Node_Str" + identifier + "String_Node_Str"+ lookupFunction+ "String_Node_Str"+ Classes.genericsToClasses(lookupFunction));
  List<Class<?>> lookupTypes=Classes.genericsToClasses(lookupFunction);
  if (lookupTypes.isEmpty()) {
    throw new IllegalArgumentException("String_Node_Str" + lookupFunction.getClass() + "String_Node_Str"+ identifier+ "String_Node_Str");
  }
 else {
    Class<?> rscType=lookupTypes.get(0);
    Ats ats=Ats.inClassHierarchy(rscType);
    Ats msgAts=Ats.inClassHierarchy(msgType);
    if (!ats.has(PolicyVendor.class) && !msgAts.has(PolicyVendor.class)) {
      throw new IllegalArgumentException("String_Node_Str" + identifier + "String_Node_Str"+ rscType.getCanonicalName()+ "String_Node_Str"+ msgType.getCanonicalName());
    }
 else     if (!ats.has(PolicyResourceType.class) && !msgAts.has(PolicyResourceType.class)) {
      throw new IllegalArgumentException("String_Node_Str" + identifier + "String_Node_Str"+ rscType.getCanonicalName()+ "String_Node_Str"+ msgType.getCanonicalName());
    }
 else {
      PolicyVendor vendor=ats.get(PolicyVendor.class);
      PolicyResourceType type=ats.get(PolicyResourceType.class);
      String action=PolicySpec.requestToAction(ctx.getRequest());
      if (action == null) {
        action=vendor.value() + "String_Node_Str" + ctx.getRequest().getClass().getSimpleName().replaceAll("String_Node_Str","String_Node_Str").toLowerCase();
      }
      User requestUser=ctx.getUser();
      T requestedObject;
      try {
        requestedObject=lookupFunction.apply(identifier);
        if (requestedObject == null) {
          throw new NoSuchElementException("String_Node_Str" + rscType.getCanonicalName() + "String_Node_Str"+ identifier+ "String_Node_Str"+ lookupFunction.getClass());
        }
      }
 catch (      PersistenceException ex) {
        Logs.extreme().error(ex,ex);
        LOG.error(ex);
        throw ex;
      }
catch (      Exception ex) {
        Logs.extreme().error(ex,ex);
        LOG.error(ex);
        throw new PersistenceException("String_Node_Str" + identifier + "String_Node_Str"+ lookupFunction+ "String_Node_Str"+ Classes.genericsToClasses(lookupFunction),ex);
      }
      Account owningAccount=Accounts.lookupUserById(requestedObject.getOwner().getUniqueId()).getAccount();
      if (!Permissions.isAuthorized(vendor.value(),type.value(),identifier,owningAccount,action,requestUser)) {
        throw new AuthException("String_Node_Str" + type.value() + "String_Node_Str"+ identifier+ "String_Node_Str"+ requestUser.getName());
      }
      return requestedObject;
    }
  }
}

Fixed version (ground truth):
/** 
 * Uses the provided   {@code lookupFunction} to resolve the {@code identifier} to the underlyingobject  {@code T} with privileges determined by the current messaging context.
 * @param < T > type of object which needs looking up
 * @param identifier identifier of the desired object
 * @param lookupFunction class which resolves string identifiers to the underlying object
 * @return the object corresponding with the given {@code identifier}
 * @throws AuthException if the user is not authorized
 * @throws PersistenceException if an error occurred in the underlying retrieval mechanism
 * @throws NoSuchElementException if the requested {@code identifier} does not exist and the useris authorized.
 * @throws IllegalContextAccessException if the current request context cannot be determined.
 */
public static <T extends HasOwningAccount>T doPrivileged(String identifier,Function<String,T> lookupFunction) throws AuthException, IllegalContextAccessException, NoSuchElementException, PersistenceException {
  Context ctx=Contexts.lookup();
  Class<? extends BaseMessage> msgType=ctx.getRequest().getClass();
  LOG.debug("String_Node_Str" + identifier + "String_Node_Str"+ lookupFunction+ "String_Node_Str"+ Classes.genericsToClasses(lookupFunction));
  List<Class<?>> lookupTypes=Classes.genericsToClasses(lookupFunction);
  if (lookupTypes.isEmpty() || lookupTypes.size() != 2) {
    throw new IllegalArgumentException("String_Node_Str" + lookupFunction.getClass() + "String_Node_Str"+ identifier+ "String_Node_Str");
  }
 else {
    Class<?> rscType=lookupTypes.get(1);
    Ats ats=Ats.inClassHierarchy(rscType);
    Ats msgAts=Ats.inClassHierarchy(msgType);
    if (!ats.has(PolicyVendor.class) && !msgAts.has(PolicyVendor.class)) {
      throw new IllegalArgumentException("String_Node_Str" + identifier + "String_Node_Str"+ rscType.getCanonicalName()+ "String_Node_Str"+ msgType.getCanonicalName());
    }
 else     if (!ats.has(PolicyResourceType.class) && !msgAts.has(PolicyResourceType.class)) {
      throw new IllegalArgumentException("String_Node_Str" + identifier + "String_Node_Str"+ rscType.getCanonicalName()+ "String_Node_Str"+ msgType.getCanonicalName());
    }
 else {
      PolicyVendor vendor=ats.get(PolicyVendor.class);
      PolicyResourceType type=ats.get(PolicyResourceType.class);
      String action=PolicySpec.requestToAction(ctx.getRequest());
      if (action == null) {
        action=vendor.value() + "String_Node_Str" + ctx.getRequest().getClass().getSimpleName().replaceAll("String_Node_Str","String_Node_Str").toLowerCase();
      }
      User requestUser=ctx.getUser();
      T requestedObject;
      try {
        requestedObject=lookupFunction.apply(identifier);
        if (requestedObject == null) {
          throw new NoSuchElementException("String_Node_Str" + rscType.getCanonicalName() + "String_Node_Str"+ identifier+ "String_Node_Str"+ lookupFunction.getClass());
        }
      }
 catch (      PersistenceException ex) {
        Logs.extreme().error(ex,ex);
        LOG.error(ex);
        throw ex;
      }
catch (      Exception ex) {
        Logs.extreme().error(ex,ex);
        LOG.error(ex);
        throw new PersistenceException("String_Node_Str" + identifier + "String_Node_Str"+ lookupFunction+ "String_Node_Str"+ Classes.genericsToClasses(lookupFunction),ex);
      }
      Account owningAccount=Accounts.lookupUserById(requestedObject.getOwner().getUniqueId()).getAccount();
      if (!Permissions.isAuthorized(vendor.value(),type.value(),identifier,owningAccount,action,requestUser)) {
        throw new AuthException("String_Node_Str" + type.value() + "String_Node_Str"+ identifier+ "String_Node_Str"+ requestUser.getName());
      }
      return requestedObject;
    }
  }
}