Program: 30203
Project: 30203
Buggy source:
/** 
 * Get the principal/distinguished name from thread local storage.
 * @return the security context.
 */
private SecurityContext getIdentity() throws SecurityMechanismException {
  if (_logger.isLoggable(Level.FINE)) {
    _logger.log(Level.FINE,"String_Node_Str");
  }
  SecurityContext ctx=new SecurityContext();
  final SecurityContext sCtx=ctx;
  com.sun.enterprise.security.SecurityContext scontext=com.sun.enterprise.security.SecurityContext.getCurrent();
  if ((scontext == null) || scontext.didServerGenerateCredentials()) {
    sCtx.identcls=AnonCredential.class;
    AccessController.doPrivileged(new PrivilegedAction<Object>(){
      public java.lang.Object run(){
        Subject sub=new Subject();
        sCtx.subject=sub;
        sCtx.subject.getPublicCredentials().add(new AnonCredential());
        return null;
      }
    }
);
    return sCtx;
  }
  Subject s=getSubjectFromSecurityCurrent();
  ctx.subject=s;
  final Subject sub=s;
  Set credSet=AccessController.doPrivileged(new PrivilegedAction<Set>(){
    public Set run(){
      return sub.getPrivateCredentials(PasswordCredential.class);
    }
  }
);
  if (credSet.size() == 1) {
    ctx.identcls=GSSUPName.class;
    final Set cs=credSet;
    Subject subj=AccessController.doPrivileged(new PrivilegedAction<Subject>(){
      public Subject run(){
        Subject ss=new Subject();
        Iterator iter=cs.iterator();
        PasswordCredential pc=(PasswordCredential)iter.next();
        GSSUPName gssname=new GSSUPName(pc.getUser(),pc.getRealm());
        ss.getPublicCredentials().add(gssname);
        return ss;
      }
    }
);
    ctx.subject=subj;
    return ctx;
  }
  credSet=s.getPublicCredentials();
  if (credSet.size() != 1) {
    _logger.log(Level.SEVERE,"String_Node_Str");
    return null;
  }
 else {
    Iterator credIter=credSet.iterator();
    if (credIter.hasNext()) {
      Object o=credIter.next();
      if (o instanceof GSSUPName) {
        ctx.identcls=GSSUPName.class;
      }
 else       if (o instanceof X500Name) {
        ctx.identcls=X500Name.class;
      }
 else {
        ctx.identcls=X509CertificateCredential.class;
      }
    }
 else {
      _logger.log(Level.SEVERE,"String_Node_Str");
      return null;
    }
  }
  return ctx;
}

Fixed version (ground truth):
/** 
 * Get the principal/distinguished name from thread local storage.
 * @return the security context.
 */
private SecurityContext getIdentity() throws SecurityMechanismException {
  if (_logger.isLoggable(Level.FINE)) {
    _logger.log(Level.FINE,"String_Node_Str");
  }
  SecurityContext ctx=new SecurityContext();
  final SecurityContext sCtx=ctx;
  com.sun.enterprise.security.SecurityContext scontext=com.sun.enterprise.security.SecurityContext.getCurrent();
  if ((scontext == null) || scontext.didServerGenerateCredentials()) {
    sCtx.identcls=AnonCredential.class;
    AccessController.doPrivileged(new PrivilegedAction<Object>(){
      public java.lang.Object run(){
        Subject sub=new Subject();
        sCtx.subject=sub;
        sCtx.subject.getPublicCredentials().add(new AnonCredential());
        return null;
      }
    }
);
    return sCtx;
  }
  Subject s=getSubjectFromSecurityCurrent();
  ctx.subject=s;
  final Subject sub=s;
  Set<PasswordCredential> credSet=AccessController.doPrivileged(new PrivilegedAction<Set>(){
    public Set run(){
      return sub.getPrivateCredentials(PasswordCredential.class);
    }
  }
);
  if (credSet.size() == 1) {
    ctx.identcls=GSSUPName.class;
    final Set cs=credSet;
    Subject subj=AccessController.doPrivileged(new PrivilegedAction<Subject>(){
      public Subject run(){
        Subject ss=new Subject();
        Iterator<PasswordCredential> iter=cs.iterator();
        PasswordCredential pc=iter.next();
        GSSUPName gssname=new GSSUPName(pc.getUser(),pc.getRealm());
        ss.getPublicCredentials().add(gssname);
        return ss;
      }
    }
);
    ctx.subject=subj;
    return ctx;
  }
  Set pubCredSet=s.getPublicCredentials();
  if (pubCredSet.size() != 1) {
    _logger.log(Level.SEVERE,"String_Node_Str");
    return null;
  }
 else {
    Iterator credIter=pubCredSet.iterator();
    if (credIter.hasNext()) {
      Object o=credIter.next();
      if (o instanceof GSSUPName) {
        ctx.identcls=GSSUPName.class;
      }
 else       if (o instanceof X500Name) {
        ctx.identcls=X500Name.class;
      }
 else {
        ctx.identcls=X509CertificateCredential.class;
      }
    }
 else {
      _logger.log(Level.SEVERE,"String_Node_Str");
      return null;
    }
  }
  return ctx;
}