Program: 14875
Project: 14875
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 resolverFunction 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.
 */
@SuppressWarnings("String_Node_Str") public static <T extends RestrictedType>T doPrivileged(String identifier,Function<String,T> resolverFunction) throws AuthException, IllegalContextAccessException, NoSuchElementException, PersistenceException {
  assertThat("String_Node_Str" + identifier,resolverFunction,notNullValue());
  Context ctx=Contexts.lookup();
  if (ctx.hasAdministrativePrivileges()) {
    return resolverFunction.apply(identifier);
  }
 else {
    Class<? extends BaseMessage> msgType=ctx.getRequest().getClass();
    LOG.debug("String_Node_Str" + identifier + "String_Node_Str"+ resolverFunction.getClass()+ "String_Node_Str"+ Classes.genericsToClasses(resolverFunction));
    List<Class<?>> lookupTypes=Classes.genericsToClasses(resolverFunction);
    if (lookupTypes.isEmpty()) {
      throw new IllegalArgumentException("String_Node_Str" + resolverFunction.getClass() + "String_Node_Str"+ identifier+ "String_Node_Str");
    }
 else {
      Class<?> rscType;
      try {
        rscType=Iterables.find(lookupTypes,new Predicate<Class<?>>(){
          @Override public boolean apply(          Class<?> arg0){
            return RestrictedType.class.isAssignableFrom(arg0);
          }
        }
);
      }
 catch (      NoSuchElementException ex1) {
        LOG.error(ex1,ex1);
        throw ex1;
      }
      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=resolverFunction.apply(identifier);
          if (requestedObject == null) {
            throw new NoSuchElementException("String_Node_Str" + rscType.getCanonicalName() + "String_Node_Str"+ identifier+ "String_Node_Str"+ resolverFunction.getClass());
          }
        }
 catch (        NoSuchElementException ex) {
          throw ex;
        }
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"+ resolverFunction.getClass()+ "String_Node_Str"+ rscType,ex);
        }
        Account owningAccount=Principals.nobodyFullName().getAccountNumber().equals(requestedObject.getOwner().getAccountNumber()) ? null : Accounts.lookupAccountByName(requestedObject.getOwner().getAccountName());
        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 resolverFunction 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.
 */
@SuppressWarnings("String_Node_Str") public static <T extends RestrictedType>T doPrivileged(String identifier,Function<String,T> resolverFunction) throws AuthException, IllegalContextAccessException, NoSuchElementException, PersistenceException {
  assertThat("String_Node_Str" + identifier,resolverFunction,notNullValue());
  Context ctx=Contexts.lookup();
  if (ctx.hasAdministrativePrivileges()) {
    return resolverFunction.apply(identifier);
  }
 else {
    Class<? extends BaseMessage> msgType=ctx.getRequest().getClass();
    LOG.debug("String_Node_Str" + identifier + "String_Node_Str"+ resolverFunction.getClass()+ "String_Node_Str"+ Classes.genericsToClasses(resolverFunction));
    List<Class<?>> lookupTypes=Classes.genericsToClasses(resolverFunction);
    if (lookupTypes.isEmpty()) {
      throw new IllegalArgumentException("String_Node_Str" + resolverFunction.getClass() + "String_Node_Str"+ identifier+ "String_Node_Str");
    }
 else {
      Class<?> rscType;
      try {
        rscType=Iterables.find(lookupTypes,new Predicate<Class<?>>(){
          @Override public boolean apply(          Class<?> arg0){
            return RestrictedType.class.isAssignableFrom(arg0);
          }
        }
);
      }
 catch (      NoSuchElementException ex1) {
        LOG.error(ex1,ex1);
        throw ex1;
      }
      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=getIamActionByMessageType(ctx.getRequest());
        }
        User requestUser=ctx.getUser();
        T requestedObject;
        try {
          requestedObject=resolverFunction.apply(identifier);
          if (requestedObject == null) {
            throw new NoSuchElementException("String_Node_Str" + rscType.getCanonicalName() + "String_Node_Str"+ identifier+ "String_Node_Str"+ resolverFunction.getClass());
          }
        }
 catch (        NoSuchElementException ex) {
          throw ex;
        }
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"+ resolverFunction.getClass()+ "String_Node_Str"+ rscType,ex);
        }
        Account owningAccount=Principals.nobodyFullName().getAccountNumber().equals(requestedObject.getOwner().getAccountNumber()) ? null : Accounts.lookupAccountByName(requestedObject.getOwner().getAccountName());
        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;
      }
    }
  }
}