Program: 14069
Project: 14069
Buggy source:
public DescribePrincipalResponseType describePrincipal(final DescribePrincipalType request) throws IdentityServiceException {
  final DescribePrincipalResponseType response=request.getReply();
  final DescribePrincipalResult result=new DescribePrincipalResult();
  try {
    final UserPrincipal user;
    if (request.getAccessKeyId() != null) {
      user=principalProvider.lookupPrincipalByAccessKeyId(request.getAccessKeyId(),request.getNonce());
    }
 else     if (request.getCertificateId() != null) {
      user=principalProvider.lookupPrincipalByCertificateId(request.getCertificateId());
    }
 else     if (request.getUserId() != null) {
      user=principalProvider.lookupPrincipalByUserId(request.getUserId(),request.getNonce());
    }
 else     if (request.getRoleId() != null) {
      user=principalProvider.lookupPrincipalByRoleId(request.getRoleId(),request.getNonce());
    }
 else     if (request.getAccountId() != null && request.getUsername() != null) {
      user=principalProvider.lookupPrincipalByAccountNumberAndUsername(request.getAccountId(),request.getUsername());
    }
 else     if (request.getAccountId() != null) {
      user=principalProvider.lookupPrincipalByAccountNumber(request.getAccountId());
    }
 else     if (request.getCanonicalId() != null) {
      user=principalProvider.lookupPrincipalByCanonicalId(request.getCanonicalId());
    }
 else {
      user=null;
    }
    if (user != null) {
      final String ptag=UserPrincipalImpl.ptag(user);
      final Principal principal=new Principal();
      principal.setArn(Accounts.getUserArn(user));
      principal.setUserId(user.getUserId());
      principal.setRoleId(Accounts.isRoleIdentifier(user.getAuthenticatedId()) ? user.getAuthenticatedId() : null);
      principal.setCanonicalId(user.getCanonicalId());
      principal.setPtag(ptag);
      if (!ptag.equals(request.getPtag())) {
        principal.setAccountAlias(user.getAccountAlias());
        principal.setEnabled(user.isEnabled());
        principal.setToken(user.getToken());
        principal.setPasswordHash(user.getPassword());
        principal.setPasswordExpiry(user.getPasswordExpires());
        final ArrayList<com.eucalyptus.auth.euare.common.identity.AccessKey> accessKeys=Lists.newArrayList();
        for (        final AccessKey accessKey : Iterables.filter(user.getKeys(),AccessKeys.isActive())) {
          final com.eucalyptus.auth.euare.common.identity.AccessKey key=new com.eucalyptus.auth.euare.common.identity.AccessKey();
          key.setAccessKeyId(accessKey.getAccessKey());
          key.setSecretAccessKey(accessKey.getSecretKey());
          accessKeys.add(key);
        }
        principal.setAccessKeys(accessKeys);
        final ArrayList<com.eucalyptus.auth.euare.common.identity.Certificate> certificates=Lists.newArrayList();
        for (        final Certificate certificate : Iterables.filter(user.getCertificates(),propertyPredicate(true,Certificate.Util.active()))) {
          final com.eucalyptus.auth.euare.common.identity.Certificate cert=new com.eucalyptus.auth.euare.common.identity.Certificate();
          cert.setCertificateId(certificate.getCertificateId());
          cert.setCertificateBody(certificate.getPem());
          certificates.add(cert);
        }
        principal.setCertificates(certificates);
        final ArrayList<Policy> policies=Lists.newArrayList();
        if (user.isEnabled()) {
          Iterables.addAll(policies,Iterables.transform(user.getPrincipalPolicies(),TypeMappers.lookup(PolicyVersion.class,Policy.class)));
        }
        principal.setPolicies(policies);
      }
      result.setPrincipal(principal);
    }
  }
 catch (  InvalidAccessKeyAuthException e) {
  }
catch (  AuthException e) {
    throw handleException(e);
  }
  response.setDescribePrincipalResult(result);
  return response;
}

Fixed version (ground truth):
public DescribePrincipalResponseType describePrincipal(final DescribePrincipalType request) throws IdentityServiceException {
  final DescribePrincipalResponseType response=request.getReply();
  final DescribePrincipalResult result=new DescribePrincipalResult();
  try {
    final UserPrincipal user;
    if (request.getAccessKeyId() != null) {
      user=principalProvider.lookupPrincipalByAccessKeyId(request.getAccessKeyId(),request.getNonce());
    }
 else     if (request.getCertificateId() != null) {
      user=principalProvider.lookupPrincipalByCertificateId(request.getCertificateId());
    }
 else     if (request.getUserId() != null) {
      user=principalProvider.lookupPrincipalByUserId(request.getUserId(),request.getNonce());
    }
 else     if (request.getRoleId() != null) {
      user=principalProvider.lookupPrincipalByRoleId(request.getRoleId(),request.getNonce());
    }
 else     if (request.getAccountId() != null && request.getUsername() != null) {
      user=principalProvider.lookupPrincipalByAccountNumberAndUsername(request.getAccountId(),request.getUsername());
    }
 else     if (request.getAccountId() != null) {
      user=principalProvider.lookupPrincipalByAccountNumber(request.getAccountId());
    }
 else     if (request.getCanonicalId() != null) {
      user=principalProvider.lookupPrincipalByCanonicalId(request.getCanonicalId());
    }
 else {
      user=null;
    }
    if (user != null) {
      final String ptag=UserPrincipalImpl.ptag(user);
      final Principal principal=new Principal();
      principal.setArn(Accounts.getUserArn(user));
      principal.setUserId(user.getUserId());
      principal.setRoleId(Accounts.isRoleIdentifier(user.getAuthenticatedId()) ? user.getAuthenticatedId() : null);
      principal.setCanonicalId(user.getCanonicalId());
      principal.setPtag(ptag);
      if (!ptag.equals(request.getPtag())) {
        principal.setAccountAlias(user.getAccountAlias());
        principal.setEnabled(user.isEnabled());
        principal.setToken(user.getToken());
        principal.setPasswordHash(user.getPassword());
        principal.setPasswordExpiry(user.getPasswordExpires());
        final ArrayList<com.eucalyptus.auth.euare.common.identity.AccessKey> accessKeys=Lists.newArrayList();
        for (        final AccessKey accessKey : Iterables.filter(user.getKeys(),AccessKeys.isActive())) {
          final com.eucalyptus.auth.euare.common.identity.AccessKey key=new com.eucalyptus.auth.euare.common.identity.AccessKey();
          key.setAccessKeyId(accessKey.getAccessKey());
          key.setSecretAccessKey(accessKey.getSecretKey());
          accessKeys.add(key);
        }
        principal.setAccessKeys(accessKeys);
        final ArrayList<com.eucalyptus.auth.euare.common.identity.Certificate> certificates=Lists.newArrayList();
        for (        final Certificate certificate : Iterables.filter(user.getCertificates(),propertyPredicate(true,Certificate.Util.active()))) {
          final com.eucalyptus.auth.euare.common.identity.Certificate cert=new com.eucalyptus.auth.euare.common.identity.Certificate();
          cert.setCertificateId(certificate.getCertificateId());
          cert.setCertificateBody(certificate.getPem());
          certificates.add(cert);
        }
        principal.setCertificates(certificates);
        final ArrayList<Policy> policies=Lists.newArrayList();
        if (user.isEnabled()) {
          Iterables.addAll(policies,Iterables.transform(user.getPrincipalPolicies(),TypeMappers.lookup(PolicyVersion.class,Policy.class)));
        }
        principal.setPolicies(policies);
      }
      result.setPrincipal(principal);
    }
  }
 catch (  InvalidAccessKeyAuthException e) {
  }
catch (  AuthException e) {
    if (!isNotFoundError(e)) {
      throw handleException(e);
    }
  }
  response.setDescribePrincipalResult(result);
  return response;
}