Program: 36394
Project: 36394
Buggy source:
/** 
 * Updates the cache either by inserting a new entry or by replacing an invalid (expired) entry.
 * @param loginContext {@link LoginContext} of the authentication
 * @param subject {@link Subject} resulted from JAAS login
 * @param principal {@link Principal} representing the user's identity
 * @param credential user's proof of identity
 * @return authenticated {@link Subject}
 */
private Subject updateCache(LoginContext loginContext,Subject subject,Principal principal,Object credential){
  if (domainCache == null || principal == null)   return subject;
  DomainInfo info=new DomainInfo();
  info.loginContext=loginContext;
  info.subject=new Subject();
  SubjectActions.copySubject(subject,info.subject,true,this.deepCopySubjectOption);
  info.credential=credential;
  PicketBoxLogger.LOGGER.traceUpdateCache(SubjectActions.toString(subject),SubjectActions.toString(info.subject));
  Set<Group> subjectGroups=subject.getPrincipals(Group.class);
  Iterator<Group> iter=subjectGroups.iterator();
  while (iter.hasNext()) {
    Group grp=iter.next();
    String name=grp.getName();
    if (name.equals("String_Node_Str")) {
      Enumeration<? extends Principal> members=grp.members();
      if (members.hasMoreElements())       info.callerPrincipal=members.nextElement();
    }
  }
  if (info.callerPrincipal == null) {
    Set<Principal> subjectPrincipals=subject.getPrincipals(Principal.class);
    Iterator<? extends Principal> iterPrincipals=subjectPrincipals.iterator();
    while (iterPrincipals.hasNext()) {
      Principal p=iterPrincipals.next();
      if (!(p instanceof Group)) {
        info.callerPrincipal=p;
        break;
      }
    }
  }
  domainCache.put(principal,info);
  PicketBoxLogger.LOGGER.traceInsertedCacheInfo(info.toString());
  return info.subject;
}

Fixed version (ground truth):
/** 
 * Updates the cache either by inserting a new entry or by replacing an invalid (expired) entry.
 * @param loginContext {@link LoginContext} of the authentication
 * @param subject {@link Subject} resulted from JAAS login
 * @param principal {@link Principal} representing the user's identity
 * @param credential user's proof of identity
 * @return authenticated {@link Subject}
 */
private Subject updateCache(LoginContext loginContext,Subject subject,Principal principal,Object credential){
  if (domainCache == null)   return subject;
  DomainInfo info=new DomainInfo();
  info.loginContext=loginContext;
  info.subject=new Subject();
  SubjectActions.copySubject(subject,info.subject,true,this.deepCopySubjectOption);
  info.credential=credential;
  PicketBoxLogger.LOGGER.traceUpdateCache(SubjectActions.toString(subject),SubjectActions.toString(info.subject));
  Set<Group> subjectGroups=subject.getPrincipals(Group.class);
  Iterator<Group> iter=subjectGroups.iterator();
  while (iter.hasNext()) {
    Group grp=iter.next();
    String name=grp.getName();
    if (name.equals("String_Node_Str")) {
      Enumeration<? extends Principal> members=grp.members();
      if (members.hasMoreElements())       info.callerPrincipal=members.nextElement();
    }
  }
  if (info.callerPrincipal == null) {
    Set<Principal> subjectPrincipals=subject.getPrincipals(Principal.class);
    Iterator<? extends Principal> iterPrincipals=subjectPrincipals.iterator();
    while (iterPrincipals.hasNext()) {
      Principal p=iterPrincipals.next();
      if (!(p instanceof Group)) {
        info.callerPrincipal=p;
        break;
      }
    }
  }
  domainCache.put(principal != null ? principal : new org.jboss.security.SimplePrincipal("String_Node_Str"),info);
  PicketBoxLogger.LOGGER.traceInsertedCacheInfo(info.toString());
  return info.subject;
}