Program: 150549
Project: 150549
Buggy source:
/** 
 * Creates the intial response to be sent to the server.
 * @param challenge  Challenge in bytes recived form the Server
 * @return Initial response to be sent to the server
 */
private String createDigestResponse(byte[] challenge) throws SaslException {
  char[] response;
  StringBuffer digestResponse=new StringBuffer(512);
  int realmSize;
  m_dc=new DigestChallenge(challenge);
  m_digestURI=m_protocol + "String_Node_Str" + m_serverName;
  if ((m_dc.getQop() & DigestChallenge.QOP_AUTH) == DigestChallenge.QOP_AUTH)   m_qopValue="String_Node_Str";
 else   throw new SaslException("String_Node_Str");
  Callback[] callbacks=new Callback[3];
  ArrayList realms=m_dc.getRealms();
  realmSize=realms.size();
  if (realmSize == 0) {
    callbacks[0]=new RealmCallback("String_Node_Str");
  }
 else   if (realmSize == 1) {
    callbacks[0]=new RealmCallback("String_Node_Str",(String)realms.get(0));
  }
 else {
    callbacks[0]=new RealmChoiceCallback("String_Node_Str",(String[])realms.toArray(new String[realmSize]),0,false);
  }
  callbacks[1]=new PasswordCallback("String_Node_Str",false);
  if (m_authorizationId == null || m_authorizationId.length() == 0)   callbacks[2]=new NameCallback("String_Node_Str");
 else   callbacks[2]=new NameCallback("String_Node_Str",m_authorizationId);
  try {
    m_cbh.handle(callbacks);
  }
 catch (  UnsupportedCallbackException e) {
    throw new SaslException("String_Node_Str" + "String_Node_Str",e);
  }
catch (  IOException e) {
    throw new SaslException("String_Node_Str",e);
  }
  if (realmSize > 1) {
    int[] selections=((RealmChoiceCallback)callbacks[0]).getSelectedIndexes();
    if (selections.length > 0)     m_realm=((RealmChoiceCallback)callbacks[0]).getChoices()[selections[0]];
 else     m_realm=((RealmChoiceCallback)callbacks[0]).getChoices()[0];
  }
 else   m_realm=((RealmCallback)callbacks[0]).getText();
  m_clientNonce=getClientNonce();
  m_name=((NameCallback)callbacks[2]).getName();
  if (m_name == null)   m_name=((NameCallback)callbacks[2]).getDefaultName();
  if (m_name == null)   throw new SaslException("String_Node_Str");
  m_HA1=DigestCalcHA1(m_dc.getAlgorithm(),m_name,m_realm,new String(((PasswordCallback)callbacks[1]).getPassword()),m_dc.getNonce(),m_clientNonce);
  response=DigestCalcResponse(m_HA1,m_dc.getNonce(),"String_Node_Str",m_clientNonce,m_qopValue,"String_Node_Str",m_digestURI,true);
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_authorizationId);
  if (0 != m_realm.length()) {
    digestResponse.append("String_Node_Str");
    digestResponse.append(m_realm);
  }
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_clientNonce);
  digestResponse.append("String_Node_Str");
  digestResponse.append("String_Node_Str");
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_qopValue);
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_serverName);
  digestResponse.append("String_Node_Str");
  digestResponse.append(response);
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_dc.getNonce());
  digestResponse.append("String_Node_Str");
  return digestResponse.toString();
}

Fixed version (ground truth):
/** 
 * Creates the intial response to be sent to the server.
 * @param challenge  Challenge in bytes recived form the Server
 * @return Initial response to be sent to the server
 */
private String createDigestResponse(byte[] challenge) throws SaslException {
  char[] response;
  StringBuffer digestResponse=new StringBuffer(512);
  int realmSize;
  m_dc=new DigestChallenge(challenge);
  m_digestURI=m_protocol + "String_Node_Str" + m_serverName;
  if ((m_dc.getQop() & DigestChallenge.QOP_AUTH) == DigestChallenge.QOP_AUTH)   m_qopValue="String_Node_Str";
 else   throw new SaslException("String_Node_Str");
  Callback[] callbacks=new Callback[3];
  ArrayList realms=m_dc.getRealms();
  realmSize=realms.size();
  if (realmSize == 0) {
    callbacks[0]=new RealmCallback("String_Node_Str");
  }
 else   if (realmSize == 1) {
    callbacks[0]=new RealmCallback("String_Node_Str",(String)realms.get(0));
  }
 else {
    callbacks[0]=new RealmChoiceCallback("String_Node_Str",(String[])realms.toArray(new String[realmSize]),0,false);
  }
  callbacks[1]=new PasswordCallback("String_Node_Str",false);
  if (m_authorizationId == null || m_authorizationId.length() == 0)   callbacks[2]=new NameCallback("String_Node_Str");
 else   callbacks[2]=new NameCallback("String_Node_Str",m_authorizationId);
  try {
    m_cbh.handle(callbacks);
  }
 catch (  UnsupportedCallbackException e) {
    throw new SaslException("String_Node_Str" + "String_Node_Str",e);
  }
catch (  IOException e) {
    throw new SaslException("String_Node_Str",e);
  }
  if (realmSize > 1) {
    int[] selections=((RealmChoiceCallback)callbacks[0]).getSelectedIndexes();
    if (selections.length > 0)     m_realm=((RealmChoiceCallback)callbacks[0]).getChoices()[selections[0]];
 else     m_realm=((RealmChoiceCallback)callbacks[0]).getChoices()[0];
  }
 else   m_realm=((RealmCallback)callbacks[0]).getText();
  m_clientNonce=getClientNonce();
  m_name=((NameCallback)callbacks[2]).getName();
  if (m_name == null)   m_name=((NameCallback)callbacks[2]).getDefaultName();
  if (m_name == null)   throw new SaslException("String_Node_Str");
  m_HA1=DigestCalcHA1(m_dc.getAlgorithm(),m_name,m_realm,new String(((PasswordCallback)callbacks[1]).getPassword()),m_dc.getNonce(),m_clientNonce);
  response=DigestCalcResponse(m_HA1,m_dc.getNonce(),"String_Node_Str",m_clientNonce,m_qopValue,"String_Node_Str",m_digestURI,true);
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_name);
  if (0 != m_realm.length()) {
    digestResponse.append("String_Node_Str");
    digestResponse.append(m_realm);
  }
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_clientNonce);
  digestResponse.append("String_Node_Str");
  digestResponse.append("String_Node_Str");
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_qopValue);
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_serverName);
  digestResponse.append("String_Node_Str");
  digestResponse.append(response);
  digestResponse.append("String_Node_Str");
  digestResponse.append(m_dc.getNonce());
  if (m_authorizationId != null && m_authorizationId.length() > 0) {
    digestResponse.append("String_Node_Str");
    digestResponse.append(m_authorizationId);
  }
  digestResponse.append("String_Node_Str");
  return digestResponse.toString();
}