Program: 36392
Project: 36392
Buggy source:
/** 
 * Create the set of roles the user belongs to by querying a database
 * @param username - name of the user
 * @param roleGroup - group containing the user's roles
 * @param dsJndiName - JNDI name of the datasource
 * @param rolesQuery - prepared statement to query
 * @param suspendResume - flag to indicate if transactions should be suspended/resumed
 * @param tm - transaction manager
 */
static void addRolesToGroup(String username,RoleGroup roleGroup,String dsJndiName,String rolesQuery,boolean suspendResume,TransactionManager tm){
  Connection conn=null;
  PreparedStatement ps=null;
  ResultSet rs=null;
  if (suspendResume) {
    if (tm == null)     throw PicketBoxMessages.MESSAGES.invalidNullTransactionManager();
  }
  Transaction tx=null;
  if (suspendResume) {
    try {
      tx=tm.suspend();
    }
 catch (    SystemException e) {
      throw new RuntimeException(e);
    }
  }
  try {
    InitialContext ctx=new InitialContext();
    DataSource ds=(DataSource)ctx.lookup(dsJndiName);
    conn=ds.getConnection();
    PicketBoxLogger.LOGGER.traceExecuteQuery(rolesQuery,username);
    ps=conn.prepareStatement(rolesQuery);
    try {
      ps.setString(1,username);
    }
 catch (    ArrayIndexOutOfBoundsException ignore) {
    }
    rs=ps.executeQuery();
    if (!rs.next()) {
      PicketBoxLogger.LOGGER.traceQueryWithEmptyResult();
    }
    do {
      String name=rs.getString(1);
      roleGroup.addRole(new SimpleRole(name));
    }
 while (rs.next());
  }
 catch (  NamingException ex) {
    throw new IllegalArgumentException(PicketBoxMessages.MESSAGES.failedToLookupDataSourceMessage(dsJndiName),ex);
  }
catch (  SQLException ex) {
    throw new IllegalArgumentException(PicketBoxMessages.MESSAGES.failedToProcessQueryMessage(),ex);
  }
 finally {
    if (rs != null) {
      try {
        rs.close();
      }
 catch (      SQLException e) {
      }
    }
    if (ps != null) {
      try {
        ps.close();
      }
 catch (      SQLException e) {
      }
    }
    if (conn != null) {
      try {
        conn.close();
      }
 catch (      Exception ex) {
      }
    }
    if (suspendResume) {
      try {
        tm.resume(tx);
      }
 catch (      Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Create the set of roles the user belongs to by querying a database
 * @param username - name of the user
 * @param roleGroup - group containing the user's roles
 * @param dsJndiName - JNDI name of the datasource
 * @param rolesQuery - prepared statement to query
 * @param suspendResume - flag to indicate if transactions should be suspended/resumed
 * @param tm - transaction manager
 */
static void addRolesToGroup(String username,RoleGroup roleGroup,String dsJndiName,String rolesQuery,boolean suspendResume,TransactionManager tm){
  Connection conn=null;
  PreparedStatement ps=null;
  ResultSet rs=null;
  if (suspendResume) {
    if (tm == null)     throw PicketBoxMessages.MESSAGES.invalidNullTransactionManager();
  }
  Transaction tx=null;
  if (suspendResume) {
    try {
      tx=tm.suspend();
    }
 catch (    SystemException e) {
      throw new RuntimeException(e);
    }
  }
  try {
    InitialContext ctx=new InitialContext();
    DataSource ds=(DataSource)ctx.lookup(dsJndiName);
    conn=ds.getConnection();
    PicketBoxLogger.LOGGER.traceExecuteQuery(rolesQuery,username);
    ps=conn.prepareStatement(rolesQuery);
    try {
      ps.setString(1,username);
    }
 catch (    ArrayIndexOutOfBoundsException ignore) {
    }
    rs=ps.executeQuery();
    if (!rs.next()) {
      PicketBoxLogger.LOGGER.traceQueryWithEmptyResult();
    }
 else {
      do {
        String name=rs.getString(1);
        roleGroup.addRole(new SimpleRole(name));
      }
 while (rs.next());
    }
  }
 catch (  NamingException ex) {
    throw new IllegalArgumentException(PicketBoxMessages.MESSAGES.failedToLookupDataSourceMessage(dsJndiName),ex);
  }
catch (  SQLException ex) {
    throw new IllegalArgumentException(PicketBoxMessages.MESSAGES.failedToProcessQueryMessage(),ex);
  }
 finally {
    if (rs != null) {
      try {
        rs.close();
      }
 catch (      SQLException e) {
      }
    }
    if (ps != null) {
      try {
        ps.close();
      }
 catch (      SQLException e) {
      }
    }
    if (conn != null) {
      try {
        conn.close();
      }
 catch (      Exception ex) {
      }
    }
    if (suspendResume) {
      try {
        tm.resume(tx);
      }
 catch (      Exception e) {
        throw new RuntimeException(e);
      }
    }
  }
}