nus-yam/ex-repair huggingface dataset:
Program: 31216
Project: 31216
Buggy source:
public void run(){
  try {
    while (true) {
      int type=ins.readInt();
      if (type == TCPProvider.MESSAGE_TYPE_PUBLISH) {
        int channellen=ins.readInt();
        byte channel[]=new byte[channellen];
        ins.readFully(channel);
        int datalen=ins.readInt();
        byte data[]=new byte[datalen];
        ins.readFully(data);
        TCPService.this.relay(channel,data);
        bytesCount+=channellen + datalen + 8;
      }
 else       if (type == TCPProvider.MESSAGE_TYPE_SUBSCRIBE) {
        int channellen=ins.readInt();
        byte channel[]=new byte[channellen];
        ins.readFully(channel);
        subscriptions.add(new SubscriptionRecord(new String(channel)));
      }
 else       if (type == TCPProvider.MESSAGE_TYPE_UNSUBSCRIBE) {
        int channellen=ins.readInt();
        byte channel[]=new byte[channellen];
        ins.readFully(channel);
        String re=new String(channel);
        for (int i=0, n=subscriptions.size(); i < n; i++) {
          if (subscriptions.get(i).regex.equals(re)) {
            subscriptions.remove(i);
            break;
          }
        }
      }
    }
  }
 catch (  IOException ex) {
  }
  try {
    sock.close();
  }
 catch (  IOException ex) {
  }
synchronized (clients) {
    clients.remove(this);
  }
}

Fixed version (ground truth):
public void run(){
  try {
    while (true) {
      int type=ins.readInt();
      if (type == TCPProvider.MESSAGE_TYPE_PUBLISH) {
        int channellen=ins.readInt();
        byte channel[]=new byte[channellen];
        ins.readFully(channel);
        int datalen=ins.readInt();
        byte data[]=new byte[datalen];
        ins.readFully(data);
        TCPService.this.relay(channel,data);
        bytesCount+=channellen + datalen + 8;
      }
 else       if (type == TCPProvider.MESSAGE_TYPE_SUBSCRIBE) {
        int channellen=ins.readInt();
        byte channel[]=new byte[channellen];
        ins.readFully(channel);
synchronized (subscriptions) {
          subscriptions.add(new SubscriptionRecord(new String(channel)));
        }
      }
 else       if (type == TCPProvider.MESSAGE_TYPE_UNSUBSCRIBE) {
        int channellen=ins.readInt();
        byte channel[]=new byte[channellen];
        ins.readFully(channel);
        String re=new String(channel);
synchronized (subscriptions) {
          for (int i=0, n=subscriptions.size(); i < n; i++) {
            if (subscriptions.get(i).regex.equals(re)) {
              subscriptions.remove(i);
              break;
            }
          }
        }
      }
    }
  }
 catch (  IOException ex) {
  }
  try {
    sock.close();
  }
 catch (  IOException ex) {
  }
synchronized (clients) {
    clients.remove(this);
  }
}
Program: 31217
Project: 31217
Buggy source:
public synchronized void send(String chanstr,byte channel[],byte data[]){
  try {
    for (    SubscriptionRecord sr : subscriptions) {
      if (sr.pat.matcher(chanstr).matches()) {
        outs.writeInt(TCPProvider.MESSAGE_TYPE_PUBLISH);
        outs.writeInt(channel.length);
        outs.write(channel);
        outs.writeInt(data.length);
        outs.write(data);
        outs.flush();
        return;
      }
    }
  }
 catch (  IOException ex) {
  }
}

Fixed version (ground truth):
public void send(String chanstr,byte channel[],byte data[]){
  try {
synchronized (subscriptions) {
      for (      SubscriptionRecord sr : subscriptions) {
        if (sr.pat.matcher(chanstr).matches()) {
          outs.writeInt(TCPProvider.MESSAGE_TYPE_PUBLISH);
          outs.writeInt(channel.length);
          outs.write(channel);
          outs.writeInt(data.length);
          outs.write(data);
          outs.flush();
          return;
        }
      }
    }
  }
 catch (  IOException ex) {
  }
}
Program: 31218
Project: 31218
Buggy source:
void ensureSpace(int needed){
  if (pos + needed >= buf.length) {
    byte buf2[]=new byte[buf.length * 2];
    System.arraycopy(buf,0,buf2,0,pos);
    buf=buf2;
  }
}

Fixed version (ground truth):
void ensureSpace(int needed){
  if (pos + needed >= buf.length) {
    int newlen=buf.length;
    while (newlen < pos + needed)     newlen*=2;
    byte buf2[]=new byte[newlen];
    System.arraycopy(buf,0,buf2,0,pos);
    buf=buf2;
  }
}
Program: 31219
Project: 31219
Buggy source:
public synchronized int numMessagesAvailable(){
  return messages.size();
}

Fixed version (ground truth):
/** 
 * Returns the number of received messages waiting to be retrieved.
 */
public synchronized int numMessagesAvailable(){
  return messages.size();
}
Program: 31220
Project: 31220
Buggy source:
public synchronized void messageReceived(LCM lcm,String channel,DataInputStream dins){
  try {
    byte data[]=new byte[dins.available()];
    dins.readFully(data);
    messages.addLast(new Message(channel,data));
    queue_data_size+=data.length;
    while (queue_data_size > max_queue_data_size) {
      Message to_remove=messages.removeFirst();
      queue_data_size-=to_remove.data.length;
    }
    notify();
  }
 catch (  IOException xcp) {
  }
}

Fixed version (ground truth):
/** 
 * Internal method, called by LCM when a message is received.
 */
public synchronized void messageReceived(LCM lcm,String channel,DataInputStream dins){
  try {
    byte data[]=new byte[dins.available()];
    dins.readFully(data);
    messages.addLast(new Message(channel,data));
    queue_data_size+=data.length;
    while (queue_data_size > max_queue_data_size) {
      Message to_remove=messages.removeFirst();
      queue_data_size-=to_remove.data.length;
    }
    notify();
  }
 catch (  IOException xcp) {
  }
}
Program: 31221
Project: 31221
Buggy source:
public synchronized Message getNextMessage(long timeout_ms){
  if (!messages.isEmpty())   return messages.removeFirst();
  if (timeout_ms == 0)   return null;
  try {
    if (timeout_ms > 0)     wait(timeout_ms);
 else     wait();
    if (!messages.isEmpty())     return messages.removeFirst();
  }
 catch (  InterruptedException xcp) {
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Attempt to retrieve the next received LCM message.
 * @param timeout_ms Max # of milliseconds to wait for a message.  If 0,then don't wait.  If less than 0, then wait indefinitely.
 * @return a Message, or null if no message was received.  
 */
public synchronized Message getNextMessage(long timeout_ms){
  if (!messages.isEmpty()) {
    Message m=messages.removeFirst();
    queue_data_size-=m.data.length;
    return m;
  }
  if (timeout_ms == 0)   return null;
  try {
    if (timeout_ms > 0)     wait(timeout_ms);
 else     wait();
    if (!messages.isEmpty()) {
      Message m=messages.removeFirst();
      queue_data_size-=m.data.length;
      return m;
    }
  }
 catch (  InterruptedException xcp) {
  }
  return null;
}
Program: 31222
Project: 31222
Buggy source:
/** 
 * Internal method, called by LCM when a message is received.
 */
public synchronized void messageReceived(LCM lcm,String channel,DataInputStream dins){
  try {
    byte data[]=new byte[dins.available()];
    dins.readFully(data);
    messages.addLast(new Message(channel,data));
    queue_data_size+=data.length;
    while (queue_data_size > max_queue_data_size || message.size() > max_queue_length) {
      Message to_remove=messages.removeFirst();
      queue_data_size-=to_remove.data.length;
    }
    notify();
  }
 catch (  IOException xcp) {
  }
}

Fixed version (ground truth):
/** 
 * Internal method, called by LCM when a message is received.
 */
public synchronized void messageReceived(LCM lcm,String channel,DataInputStream dins){
  try {
    byte data[]=new byte[dins.available()];
    dins.readFully(data);
    messages.addLast(new Message(channel,data));
    queue_data_size+=data.length;
    while (queue_data_size > max_queue_data_size || messages.size() > max_queue_length) {
      Message to_remove=messages.removeFirst();
      queue_data_size-=to_remove.data.length;
    }
    notify();
  }
 catch (  IOException xcp) {
  }
}
Program: 31223
Project: 31223
Buggy source:
public void subscribe(String regex,LCMSubscriber sub){
  SubscriptionRecord srec=new SubscriptionRecord();
  srec.regex=regex;
  srec.pat=Pattern.compile(regex);
  srec.lcsub=sub;
synchronized (subscriptions) {
    subscriptions.add(srec);
    for (    String channel : subscriptionsMap.keySet()) {
      if (srec.pat.matcher(channel).matches()) {
        ArrayList<SubscriptionRecord> subs=subscriptionsMap.get(channel);
        subs.add(srec);
      }
    }
  }
}

Fixed version (ground truth):
public void subscribe(String regex,LCMSubscriber sub){
  SubscriptionRecord srec=new SubscriptionRecord();
  srec.regex=regex;
  srec.pat=Pattern.compile(regex);
  srec.lcsub=sub;
synchronized (this) {
    for (    Provider p : providers)     p.subscribe(regex);
  }
synchronized (subscriptions) {
    subscriptions.add(srec);
    for (    String channel : subscriptionsMap.keySet()) {
      if (srec.pat.matcher(channel).matches()) {
        ArrayList<SubscriptionRecord> subs=subscriptionsMap.get(channel);
        subs.add(srec);
      }
    }
  }
}
Program: 31225
Project: 31225
Buggy source:
/** 
 * Performs a seek and fills the buffer accordingly. 
 */
void bufferSeek(long seekOffset) throws IOException {
  flushBuffer();
  long newOffset=seekOffset - (seekOffset & (BUFFER_SIZE - 1));
  if (newOffset == bufferOffset) {
    bufferPosition=(int)(seekOffset - bufferOffset);
    return;
  }
  bufferOffset=newOffset;
  bufferLength=(int)min(BUFFER_SIZE,length - bufferOffset);
  if (bufferLength < 0)   bufferLength=0;
  bufferPosition=(int)(seekOffset - bufferOffset);
  raf.seek(bufferOffset);
  raf.readFully(buffer,0,bufferLength);
}

Fixed version (ground truth):
/** 
 * Performs a seek and fills the buffer accordingly. 
 */
void bufferSeek(long seekOffset) throws IOException {
  flushBuffer();
  long newOffset=seekOffset - (seekOffset & (BUFFER_SIZE - 1L));
  if (newOffset == bufferOffset) {
    bufferPosition=(int)(seekOffset - bufferOffset);
    return;
  }
  bufferOffset=newOffset;
  bufferLength=(int)min(BUFFER_SIZE,length - bufferOffset);
  if (bufferLength < 0)   bufferLength=0;
  bufferPosition=(int)(seekOffset - bufferOffset);
  raf.seek(bufferOffset);
  raf.readFully(buffer,0,bufferLength);
}
Program: 31226
Project: 31226
Buggy source:
public int readInt() throws IOException {
  int v=0;
  v|=((read() & 0xff) << 24);
  v|=((read() & 0xff) << 16);
  v|=((read() & 0xff) << 8);
  v|=((read() & 0xff));
  return v;
}

Fixed version (ground truth):
public int readInt() throws IOException {
  int v=0;
  v|=(read() << 24);
  v|=(read() << 16);
  v|=(read() << 8);
  v|=(read());
  return v;
}
Program: 31227
Project: 31227
Buggy source:
public int read() throws IOException {
  if (bufferOffset + bufferPosition > length)   throw new EOFException("String_Node_Str");
  if (bufferPosition >= bufferLength)   bufferSeek(bufferOffset + bufferPosition);
  return buffer[bufferPosition++] & 0xff;
}

Fixed version (ground truth):
public final int read() throws IOException {
  if (bufferOffset + bufferPosition >= length)   throw new EOFException("String_Node_Str");
  if (bufferPosition >= bufferLength)   bufferSeek(bufferOffset + bufferPosition);
  return buffer[bufferPosition++] & 0xff;
}
Program: 31228
Project: 31228
Buggy source:
public short readShort() throws IOException {
  short v=0;
  v|=((read() & 0xff) << 8);
  v|=((read() & 0xff));
  return v;
}

Fixed version (ground truth):
public short readShort() throws IOException {
  short v=0;
  v|=(read() << 8);
  v|=(read());
  return v;
}
Program: 31229
Project: 31229
Buggy source:
/** 
 * This method can be used as an easy 'catch-all' mechanism.
 * @param domain the domain
 * @return Returns all received messages for given domain.
 */
MimeMessage[] getReceivedMessagesForDomain(String domain);

Fixed version (ground truth):
/** 
 * Gets all messages containing given domain.
 * @param domain the domain, such as 'icegreen.com' or 'some.example.com'
 * @return Returns all received messages for given domain.
 */
MimeMessage[] getReceivedMessagesForDomain(String domain);
Program: 31230
Project: 31230
Buggy source:
public boolean test(String userid,String password){
  GreenMailUser u=getUser(userid);
  return null != u && u.getPassword().equals(password);
}

Fixed version (ground truth):
public boolean test(String userID,String password){
  if (authRequired) {
    GreenMailUser u=getUser(userID);
    return null != u && u.getPassword().equals(password);
  }
  try {
    if (!userExists(userID)) {
      createUser(userID,userID,"String_Node_Str");
    }
  }
 catch (  UserException e) {
    log.error("String_Node_Str" + userID,e);
  }
  return true;
}
Program: 31231
Project: 31231
Buggy source:
public Header(String line){
  String[] strs=line.split("String_Node_Str");
  value=strs[0];
  if (0 != strs.length) {
    params=new HashSet<String>();
    for (int i=1; i < strs.length; i++) {
      String p=strs[i].trim();
      int e=p.indexOf('=');
      String key=p.substring(0,e);
      String val=p.substring(e + 1,p.length());
      p=Q + strip(key) + Q+ SP+ Q+ strip(val)+ Q;
      params.add(p);
    }
  }
}

Fixed version (ground truth):
public Header(String line){
  String[] strs=line.split("String_Node_Str");
  value=strs[0];
  if (0 != strs.length) {
    params=new HashSet<String>(strs.length);
    for (int i=1; i < strs.length; i++) {
      String p=strs[i].trim();
      int e=p.indexOf('=');
      String key=p.substring(0,e);
      String val=p.substring(e + 1,p.length());
      p=Q + strip(key) + Q+ SP+ Q+ strip(val)+ Q;
      params.add(p);
    }
  }
}
Program: 31232
Project: 31232
Buggy source:
@Override public String toString(){
  StringBuilder ret=new StringBuilder();
  if (null == params) {
    ret.append(Q).append(value).append(Q);
  }
 else {
    ret.append(LB);
    ret.append(Q).append(value).append(Q + SP);
    ret.append(LB);
    int i=0;
    for (    String param : params) {
      if (i++ > 0) {
        ret.append(SP);
      }
      ret.append(param);
    }
    ret.append(RB);
    ret.append(RB);
  }
  return ret.toString();
}

Fixed version (ground truth):
@Override public String toString(){
  StringBuilder ret=new StringBuilder();
  if (null == params) {
    ret.append(Q).append(value).append(Q);
  }
 else {
    if (params.size() == 0) {
      ret.append(NIL);
    }
 else {
      ret.append(LB);
      ret.append(Q).append(value).append(Q + SP);
      ret.append(LB);
      int i=0;
      for (      String param : params) {
        if (i++ > 0) {
          ret.append(SP);
        }
        ret.append(param);
      }
      ret.append(RB);
      ret.append(RB);
    }
  }
  return ret.toString();
}
Program: 31233
Project: 31233
Buggy source:
protected Session newEmailSession(boolean debug){
  Properties props=new Properties();
  props.put("String_Node_Str",emailServerHost);
  props.put("String_Node_Str",smtpPort);
  Session session=Session.getDefaultInstance(props,null);
  session.setDebug(debug);
  return session;
}

Fixed version (ground truth):
protected Session newEmailSession(boolean debug){
  Session session=greenMail.getSmtp().createSession();
  session.setDebug(debug);
  return session;
}
Program: 31234
Project: 31234
Buggy source:
@Test public void sendAndFetchMailMessageWithInlineAttachment() throws IOException, MessagingException, GeneralSecurityException {
  sendMailMessageWithInlineAttachment();
  fetchEmailWithInlineAttachment();
}

Fixed version (ground truth):
@Test public void sendAndFetchMailMessageWithInlineAttachment() throws IOException, MessagingException, GeneralSecurityException {
  greenMail.setUser(emailAddress,imapUserName,imapPassword);
  sendMailMessageWithInlineAttachment();
  fetchEmailWithInlineAttachment();
}
Program: 31235
Project: 31235
Buggy source:
private void fetchEmailWithInlineAttachment() throws MessagingException, GeneralSecurityException {
  Store store=connectToIMAPServer();
  Folder folder=openFolder(store,"String_Node_Str");
  Message[] messages=folder.getMessages();
  for (  Message message : messages) {
    System.out.println("String_Node_Str" + message.getContentType());
  }
}

Fixed version (ground truth):
private void fetchEmailWithInlineAttachment() throws MessagingException, GeneralSecurityException, IOException {
  Store store=connectToIMAPServer();
  Folder folder=openFolder(store,"String_Node_Str");
  Message[] messages=folder.getMessages();
  assertEquals(1,messages.length);
  assertTrue(messages[0].getContentType().startsWith("String_Node_Str"));
  final Multipart part=(Multipart)messages[0].getContent();
  assertEquals(1,part.getCount());
  final BodyPart bodyPart=part.getBodyPart(0);
  assertEquals("String_Node_Str",bodyPart.getContentType());
  Assert.assertEquals("String_Node_Str",bodyPart.getContent());
}
Program: 31236
Project: 31236
Buggy source:
private void sendMailMessageWithInlineAttachment() throws MessagingException {
  MimeMessage message=newEmailTo(newEmailSession(true),emailAddress,"String_Node_Str");
  MimeBodyPart textPart=new MimeBodyPart();
  textPart.setContent("String_Node_Str","String_Node_Str");
  textPart.setDisposition("String_Node_Str");
  Multipart mp=new MimeMultipart();
  mp.addBodyPart(textPart);
  message.setContent(mp);
  Transport.send(message);
}

Fixed version (ground truth):
private void sendMailMessageWithInlineAttachment() throws MessagingException {
  MimeMessage message=newEmailTo(newEmailSession(false),emailAddress,"String_Node_Str");
  MimeBodyPart textPart=new MimeBodyPart();
  textPart.setContent("String_Node_Str","String_Node_Str");
  textPart.setDisposition(Part.INLINE);
  Multipart mp=new MimeMultipart();
  mp.addBodyPart(textPart);
  message.setContent(mp);
  Transport.send(message);
}
Program: 31237
Project: 31237
Buggy source:
private Store connectToIMAPServer() throws GeneralSecurityException, MessagingException {
  Properties props=new Properties();
  MailSSLSocketFactory socketFactory=new MailSSLSocketFactory();
  socketFactory.setTrustedHosts(new String[]{"String_Node_Str","String_Node_Str"});
  props.put("String_Node_Str",socketFactory);
  Session session=Session.getInstance(props,null);
  Store store=session.getStore("String_Node_Str");
  store.connect(emailServerHost,imapsPort,imapUserName,imapPassword);
  return store;
}

Fixed version (ground truth):
private Store connectToIMAPServer() throws GeneralSecurityException, MessagingException {
  Store store=greenMail.getImap().createStore();
  store.connect(imapUserName,imapPassword);
  return store;
}
Program: 31239
Project: 31239
Buggy source:
public FetchRequest fetchRequest(ImapRequestLineReader request) throws ProtocolException {
  FetchRequest fetch=new FetchRequest();
  nextNonSpaceChar(request);
  consumeChar(request,'(');
  char next=nextNonSpaceChar(request);
  while (next != ')') {
    addNextElement(request,fetch);
    next=nextNonSpaceChar(request);
  }
  consumeChar(request,')');
  return fetch;
}

Fixed version (ground truth):
public FetchRequest fetchRequest(ImapRequestLineReader request) throws ProtocolException {
  FetchRequest fetch=new FetchRequest();
  char next=nextNonSpaceChar(request);
  boolean parenthesis='(' == next;
  if (parenthesis) {
    consumeChar(request,'(');
    next=nextNonSpaceChar(request);
    while (next != ')') {
      addNextElement(request,fetch);
      next=nextNonSpaceChar(request);
    }
    consumeChar(request,')');
  }
 else {
    addNextElement(request,fetch);
  }
  return fetch;
}
Program: 31241
Project: 31241
Buggy source:
protected synchronized void initServerSocket(){
  try {
    serverSocket=openServerSocket();
  }
 catch (  IOException e) {
    final String msg="String_Node_Str" + getName();
    log.error(msg,e);
    throw new IllegalStateException(msg,e);
  }
  setRunning(true);
}

Fixed version (ground truth):
protected synchronized void initServerSocket(){
  try {
    serverSocket=openServerSocket();
    setRunning(true);
  }
 catch (  IOException e) {
    final String msg="String_Node_Str" + getName();
    log.error(msg,e);
    throw new IllegalStateException(msg,e);
  }
 finally {
synchronized (startupMonitor) {
      startupMonitor.notifyAll();
    }
  }
}
Program: 31242
Project: 31242
Buggy source:
protected synchronized void quit(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + getName());
  }
  try {
    if (null != serverSocket) {
      serverSocket.close();
      serverSocket=null;
    }
synchronized (handlers) {
      for (      ProtocolHandler handler : handlers) {
        handler.close();
      }
      handlers.clear();
    }
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + getName());
    }
  }
 catch (  IOException e) {
    throw new IllegalStateException("String_Node_Str" + getName(),e);
  }
}

Fixed version (ground truth):
/** 
 * Quits server by closing server socket and closing client socket handlers.
 */
protected synchronized void quit(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + getName());
  }
  closeServerSocket();
synchronized (handlers) {
    for (    ProtocolHandler handler : handlers) {
      handler.close();
    }
    handlers.clear();
  }
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + getName());
  }
}
Program: 31243
Project: 31243
Buggy source:
@Override public void waitTillRunning(long timeoutInMs) throws InterruptedException {
  long t=System.currentTimeMillis();
synchronized (startupMonitor) {
    while (!isRunning() && System.currentTimeMillis() - t < timeoutInMs) {
      startupMonitor.wait(timeoutInMs);
    }
  }
}

Fixed version (ground truth):
@Override public boolean waitTillRunning(long timeoutInMs) throws InterruptedException {
  long t=System.currentTimeMillis();
synchronized (startupMonitor) {
    while (!isRunning() && System.currentTimeMillis() - t < timeoutInMs) {
      startupMonitor.wait(timeoutInMs);
    }
  }
  return isRunning();
}
Program: 31244
Project: 31244
Buggy source:
protected synchronized void quit(){
  try {
    if (null != serverSocket) {
      serverSocket.close();
      serverSocket=null;
    }
synchronized (handlers) {
      for (      ProtocolHandler handler : handlers) {
        handler.close();
      }
      handlers.clear();
    }
  }
 catch (  IOException e) {
    throw new IllegalStateException(e);
  }
}

Fixed version (ground truth):
protected synchronized void quit(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + toString());
  }
  try {
    if (null != serverSocket) {
      serverSocket.close();
      serverSocket=null;
    }
synchronized (handlers) {
      for (      ProtocolHandler handler : handlers) {
        handler.close();
      }
      handlers.clear();
    }
  }
 catch (  IOException e) {
    throw new IllegalStateException(e);
  }
}
Program: 31245
Project: 31245
Buggy source:
@Override public synchronized void stop(){
  if (services != null) {
    for (    Service service : services.values()) {
      if (service.isRunning()) {
        service.stopService();
      }
    }
  }
  managers=new Managers();
  services=null;
}

Fixed version (ground truth):
@Override public synchronized void stop(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str");
  }
  if (services != null) {
    for (    Service service : services.values()) {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + service.toString());
      }
      service.stopService();
    }
  }
  managers=new Managers();
  services=null;
}
Program: 31246
Project: 31246
Buggy source:
/** 
 * Waits till service is up or timeout was reached.
 * @param timeoutInMs the timeout in milliseconds
 * @throws InterruptedException
 */
void waitTillRunning(long timeoutInMs) throws InterruptedException ;

Fixed version (ground truth):
/** 
 * Waits till service is up or timeout was reached.
 * @param timeoutInMs the timeout in milliseconds
 * @throws InterruptedException if interrupted while waiting.
 * @return true, if running otherwise false if timeout was reached.
 */
boolean waitTillRunning(long timeoutInMs) throws InterruptedException ;
Program: 31247
Project: 31247
Buggy source:
@Override public synchronized void start(){
  init();
  for (  Service service : services.values()) {
    service.startService();
  }
  for (  Service service : services.values()) {
    try {
      service.waitTillRunning(100L);
    }
 catch (    InterruptedException ex) {
      throw new IllegalStateException("String_Node_Str" + service + "String_Node_Str",ex);
    }
  }
  doConfigure();
}

Fixed version (ground truth):
@Override public synchronized void start(){
  init();
  final Collection<AbstractServer> servers=services.values();
  for (  AbstractServer service : servers) {
    service.startService();
  }
  for (  AbstractServer service : servers) {
    try {
      service.waitTillRunning(service.getServerSetup().getServerStartupTimeout());
    }
 catch (    InterruptedException ex) {
      throw new IllegalStateException("String_Node_Str" + service,ex);
    }
  }
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str");
  }
  for (  AbstractServer service : servers) {
    if (!service.isRunning()) {
      throw new IllegalStateException("String_Node_Str" + service + "String_Node_Str"+ service.getServerSetup().getServerStartupTimeout()+ "String_Node_Str"+ ServerSetup.class.getSimpleName()+ "String_Node_Str");
    }
  }
  doConfigure();
}
Program: 31248
Project: 31248
Buggy source:
/** 
 * Create the required services according to the server setup
 * @param config Service configuration
 * @return Services map
 */
private static Map<String,Service> createServices(ServerSetup[] config,Managers mgr){
  Map<String,Service> srvc=new HashMap<String,Service>();
  for (  ServerSetup setup : config) {
    if (srvc.containsKey(setup.getProtocol())) {
      throw new IllegalArgumentException("String_Node_Str" + setup.getProtocol() + "String_Node_Str");
    }
    final String protocol=setup.getProtocol();
    if (protocol.startsWith(ServerSetup.PROTOCOL_SMTP)) {
      srvc.put(protocol,new SmtpServer(setup,mgr));
    }
 else     if (protocol.startsWith(ServerSetup.PROTOCOL_POP3)) {
      srvc.put(protocol,new Pop3Server(setup,mgr));
    }
 else     if (protocol.startsWith(ServerSetup.PROTOCOL_IMAP)) {
      srvc.put(protocol,new ImapServer(setup,mgr));
    }
  }
  return srvc;
}

Fixed version (ground truth):
/** 
 * Create the required services according to the server setup
 * @param config Service configuration
 * @return Services map
 */
private static Map<String,AbstractServer> createServices(ServerSetup[] config,Managers mgr){
  Map<String,AbstractServer> srvc=new HashMap<String,AbstractServer>();
  for (  ServerSetup setup : config) {
    if (srvc.containsKey(setup.getProtocol())) {
      throw new IllegalArgumentException("String_Node_Str" + setup.getProtocol() + "String_Node_Str");
    }
    final String protocol=setup.getProtocol();
    if (protocol.startsWith(ServerSetup.PROTOCOL_SMTP)) {
      srvc.put(protocol,new SmtpServer(setup,mgr));
    }
 else     if (protocol.startsWith(ServerSetup.PROTOCOL_POP3)) {
      srvc.put(protocol,new Pop3Server(setup,mgr));
    }
 else     if (protocol.startsWith(ServerSetup.PROTOCOL_IMAP)) {
      srvc.put(protocol,new ImapServer(setup,mgr));
    }
  }
  return srvc;
}
Program: 31249
Project: 31249
Buggy source:
@Test public void testStartStop(){
  GreenMail service=new GreenMail(ServerSetupTest.ALL);
  service.stop();
  service.start();
  service.stop();
  service.reset();
  service.reset();
  service.stop();
}

Fixed version (ground truth):
@Test public void testStartStop(){
  GreenMail service=new GreenMail(ServerSetupTest.ALL);
  try {
    service.stop();
    service.start();
    service.stop();
    service.reset();
    service.reset();
  }
  finally {
    service.stop();
  }
}
Program: 31250
Project: 31250
Buggy source:
/** 
 * Resets the handler data to a basic state.
 */
@Override public void close(){
  if (socket != null) {
    try {
      socket.close();
    }
 catch (    IOException e) {
      log.warn("String_Node_Str",e);
    }
 finally {
      socket=null;
    }
  }
  session=null;
  response=null;
}

Fixed version (ground truth):
/** 
 * Resets the handler data to a basic state.
 */
@Override public void close(){
synchronized (closeMonitor) {
    if (socket != null) {
      try {
        socket.close();
      }
 catch (      IOException e) {
        log.warn("String_Node_Str",e);
      }
 finally {
        socket=null;
      }
    }
    session=null;
    response=null;
  }
}
Program: 31251
Project: 31251
Buggy source:
@Override public GreenMailUser setUser(String email,String login,String password){
  GreenMailUser user=managers.getUserManager().getUser(email);
  if (null == user) {
    try {
      user=managers.getUserManager().createUser(email,login,password);
    }
 catch (    UserException e) {
      throw new RuntimeException(e);
    }
  }
 else {
    user.setPassword(password);
  }
  return user;
}

Fixed version (ground truth):
@Override public GreenMailUser setUser(String email,String login,String password){
  GreenMailUser user=managers.getUserManager().getUser(login);
  if (null == user) {
    try {
      user=managers.getUserManager().createUser(email,login,password);
    }
 catch (    UserException e) {
      throw new RuntimeException(e);
    }
  }
 else {
    user.setPassword(password);
  }
  return user;
}
Program: 31252
Project: 31252
Buggy source:
/** 
 * Moves the request line reader to end of the line, checking that no non-space character are found.
 * @throws ProtocolException If more non-space tokens are found in this line,or the end-of-file is reached.
 */
public void eol() throws ProtocolException {
  char next=nextChar();
  while (next == ' ') {
    consume();
    next=nextChar();
  }
  if (next == '\r') {
    consume();
    next=nextChar();
  }
  if (next != '\n') {
    throw new ProtocolException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Moves the request line reader to end of the line, checking that no non-space character are found.
 * @throws ProtocolException If more non-space tokens are found in this line,or the end-of-file is reached.
 */
public void eol() throws ProtocolException {
  char next=nextChar();
  while (next == ' ') {
    consume();
    next=nextChar();
  }
  if (next == '\r') {
    consume();
    next=nextChar();
  }
  if (next != '\n') {
    throw new ProtocolException("String_Node_Str" + next);
  }
}
Program: 31253
Project: 31253
Buggy source:
/** 
 * Reads and consumes a number of characters from the underlying reader, filling the char array provided.
 * @param holder A char array which will be filled with chars read from the underlying reader.
 * @throws ProtocolException If a char can't be read into each array element.
 */
public void read(byte[] holder) throws ProtocolException {
  int readTotal=0;
  try {
    while (readTotal < holder.length) {
      int count=0;
      count=input.read(holder,readTotal,holder.length - readTotal);
      if (count == -1) {
        throw new ProtocolException("String_Node_Str");
      }
      readTotal+=count;
    }
    nextSeen=false;
    nextChar=0;
  }
 catch (  IOException e) {
    throw new ProtocolException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Reads and consumes a number of characters from the underlying reader, filling the char array provided.
 * @param holder A char array which will be filled with chars read from the underlying reader.
 * @throws ProtocolException If a char can't be read into each array element.
 */
public void read(byte[] holder) throws ProtocolException {
  int readTotal=0;
  try {
    while (readTotal < holder.length) {
      int count=input.read(holder,readTotal,holder.length - readTotal);
      if (count == -1) {
        throw new ProtocolException("String_Node_Str");
      }
      readTotal+=count;
    }
    nextSeen=false;
    nextChar=0;
  }
 catch (  IOException e) {
    throw new ProtocolException("String_Node_Str",e);
  }
}
Program: 31254
Project: 31254
Buggy source:
/** 
 * Reads the next character in the current line. This method will continue to return the same character until the   {@link #consume()} method is called.
 * @return The next character.
 * @throws ProtocolException If the end-of-stream is reached.
 */
public char nextChar() throws ProtocolException {
  if (!nextSeen) {
    int next=-1;
    try {
      next=input.read();
    }
 catch (    IOException e) {
      throw new ProtocolException("String_Node_Str",e);
    }
    if (next == -1) {
      throw new ProtocolException("String_Node_Str");
    }
    nextSeen=true;
    nextChar=(char)next;
  }
  return nextChar;
}

Fixed version (ground truth):
/** 
 * Reads the next character in the current line. This method will continue to return the same character until the   {@link #consume()} method is called.
 * @return The next character.
 * @throws ProtocolException If the end-of-stream is reached.
 */
public char nextChar() throws ProtocolException {
  if (!nextSeen) {
    try {
      nextChar=(char)input.read();
      nextSeen=true;
    }
 catch (    IOException e) {
      throw new ProtocolException("String_Node_Str",e);
    }
  }
  return nextChar;
}
Program: 31255
Project: 31255
Buggy source:
/** 
 * Sends a server command continuation request '+' back to the client, requesting more data to be sent.
 */
public void commandContinuationRequest() throws ProtocolException {
  try {
    output.write('+');
    output.write('\r');
    output.write('\n');
    output.flush();
  }
 catch (  IOException e) {
    throw new ProtocolException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Sends a server command continuation request '+' back to the client, requesting more data to be sent.
 */
public void commandContinuationRequest() throws ProtocolException {
  try {
    output.write('+');
    output.write('\r');
    output.write('\n');
    output.flush();
  }
 catch (  IOException e) {
    throw new ProtocolException("String_Node_Str",e);
  }
}
Program: 31256
Project: 31256
Buggy source:
/** 
 * Reads a MimeMessage encoded as a string literal from the request. TODO shouldn't need to read as a string and write out bytes use FixedLengthInputStream instead. Hopefully it can then be dynamic.
 * @param request The Imap APPEND request
 * @return A MimeMessage read off the request.
 */
public MimeMessage mimeMessage(ImapRequestLineReader request) throws ProtocolException {
  request.nextWordChar();
  byte[] mail=consumeLiteralAsBytes(request);
  try {
    return GreenMailUtil.newMimeMessage(new ByteArrayInputStream(mail));
  }
 catch (  Exception e) {
    throw new ProtocolException("String_Node_Str" + e.getMessage());
  }
}

Fixed version (ground truth):
/** 
 * Reads a MimeMessage encoded as a string literal from the request. TODO shouldn't need to read as a string and write out bytes use FixedLengthInputStream instead. Hopefully it can then be dynamic.
 * @param request The Imap APPEND request
 * @return A MimeMessage read off the request.
 */
public MimeMessage mimeMessage(ImapRequestLineReader request) throws ProtocolException {
  request.nextWordChar();
  byte[] mail=consumeLiteralAsBytes(request);
  try {
    return GreenMailUtil.newMimeMessage(new ByteArrayInputStream(mail));
  }
 catch (  Exception e) {
    throw new ProtocolException("String_Node_Str",e);
  }
}
Program: 31258
Project: 31258
Buggy source:
public void execute(SmtpConnection conn,SmtpState state,SmtpManager manager,String commandLine){
  Matcher m=param.matcher(commandLine);
  try {
    if (m.matches()) {
      String from=m.group(1);
      MailAddress fromAddr=new MailAddress(from);
      String err=manager.checkSender(state,fromAddr);
      if (err != null) {
        conn.send(err);
        return;
      }
      state.clearMessage();
      state.getMessage().setReturnPath(fromAddr);
      conn.send("String_Node_Str");
    }
 else {
      conn.send("String_Node_Str");
    }
  }
 catch (  AddressException e) {
    conn.send("String_Node_Str");
  }
}

Fixed version (ground truth):
public void execute(SmtpConnection conn,SmtpState state,SmtpManager manager,String commandLine){
  Matcher m=param.matcher(commandLine);
  try {
    if (m.matches()) {
      String from=m.group(1);
      if (!from.isEmpty()) {
        MailAddress fromAddr=new MailAddress(from);
        String err=manager.checkSender(state,fromAddr);
        if (err != null) {
          conn.send(err);
          return;
        }
        state.clearMessage();
        state.getMessage().setReturnPath(fromAddr);
        conn.send("String_Node_Str");
      }
 else {
        state.clearMessage();
        state.getMessage();
        conn.send("String_Node_Str");
      }
    }
 else {
      conn.send("String_Node_Str");
    }
  }
 catch (  AddressException e) {
    conn.send("String_Node_Str");
  }
}
Program: 31259
Project: 31259
Buggy source:
public List getMessages(){
  return _folder.getMessages();
}

Fixed version (ground truth):
public List<StoredMessage> getMessages(){
  return _folder.getMessages();
}
Program: 31260
Project: 31260
Buggy source:
public void expunged(int msn){
synchronized (_expungedMsns) {
    _expungedMsns.add(Integer.valueOf(msn));
  }
}

Fixed version (ground truth):
public void expunged(int msn){
synchronized (_expungedMsns) {
    _expungedMsns.add(msn);
  }
}
Program: 31261
Project: 31261
Buggy source:
public int[] getExpunged() throws FolderException {
synchronized (_expungedMsns) {
    int[] expungedMsns=new int[_expungedMsns.size()];
    for (int i=0; i < expungedMsns.length; i++) {
      int msn=((Integer)_expungedMsns.get(i)).intValue();
      expungedMsns[i]=msn;
    }
    _expungedMsns.clear();
    if (!(_modifiedFlags.isEmpty() && !_sizeChanged)) {
      throw new IllegalStateException("String_Node_Str");
    }
    return expungedMsns;
  }
}

Fixed version (ground truth):
public int[] getExpunged() throws FolderException {
synchronized (_expungedMsns) {
    int[] expungedMsns=new int[_expungedMsns.size()];
    for (int i=0; i < expungedMsns.length; i++) {
      int msn=_expungedMsns.get(i);
      expungedMsns[i]=msn;
    }
    _expungedMsns.clear();
    if (!(_modifiedFlags.isEmpty() && !_sizeChanged)) {
      throw new IllegalStateException("String_Node_Str");
    }
    return expungedMsns;
  }
}
Program: 31262
Project: 31262
Buggy source:
/** 
 * Adjust an actual mailbox msn for the expunged messages in this mailbox that have not yet been notified. TODO - need a test for this
 */
private int correctForExpungedMessages(int absoluteMsn){
  int correctedMsn=absoluteMsn;
  for (int i=(_expungedMsns.size() - 1); i >= 0; i--) {
    Integer expunged=(Integer)_expungedMsns.get(i);
    if (expunged.intValue() <= absoluteMsn) {
      correctedMsn++;
    }
  }
  return correctedMsn;
}

Fixed version (ground truth):
/** 
 * Adjust an actual mailbox msn for the expunged messages in this mailbox that have not yet been notified. TODO - need a test for this
 */
private int correctForExpungedMessages(int absoluteMsn){
  int correctedMsn=absoluteMsn;
  for (int i=(_expungedMsns.size() - 1); i >= 0; i--) {
    int expunged=_expungedMsns.get(i);
    if (expunged <= absoluteMsn) {
      correctedMsn++;
    }
  }
  return correctedMsn;
}
Program: 31263
Project: 31263
Buggy source:
public void flagsUpdated(int msn,Flags flags,Long uid){
  _modifiedFlags.put(Integer.valueOf(msn),new FlagUpdate(msn,uid,flags));
}

Fixed version (ground truth):
public void flagsUpdated(int msn,Flags flags,Long uid){
  _modifiedFlags.put(msn,new FlagUpdate(msn,uid,flags));
}
Program: 31264
Project: 31264
Buggy source:
public List getFlagUpdates() throws FolderException {
  if (_modifiedFlags.isEmpty()) {
    return Collections.EMPTY_LIST;
  }
  List retVal=new ArrayList();
  retVal.addAll(_modifiedFlags.values());
  _modifiedFlags.clear();
  return retVal;
}

Fixed version (ground truth):
public List<ImapSessionFolder.FlagUpdate> getFlagUpdates() throws FolderException {
  if (_modifiedFlags.isEmpty()) {
    return Collections.emptyList();
  }
  List<FlagUpdate> retVal=new ArrayList<FlagUpdate>();
  retVal.addAll(_modifiedFlags.values());
  _modifiedFlags.clear();
  return retVal;
}
Program: 31265
Project: 31265
Buggy source:
public ImapSessionImpl(ImapHostManager imapHost,UserManager users,ImapHandler handler,String clientHostName,String clientAddress){
  this.imapHost=imapHost;
  this.users=users;
  this.handler=handler;
  this.clientHostName=clientHostName;
  this.clientAddress=clientAddress;
}

Fixed version (ground truth):
public ImapSessionImpl(ImapHostManager imapHost,UserManager users,ImapHandler handler,String clientAddress){
  this.imapHost=imapHost;
  this.users=users;
  this.handler=handler;
  this.clientAddress=clientAddress;
}
Program: 31266
Project: 31266
Buggy source:
public void unsolicitedResponses(ImapResponse response,boolean omitExpunged) throws FolderException {
  ImapSessionFolder selected=getSelected();
  if (selected != null) {
    if (selected.isSizeChanged()) {
      response.existsResponse(selected.getMessageCount());
      response.recentResponse(selected.getRecentCount(true));
      selected.setSizeChanged(false);
    }
    List flagUpdates=selected.getFlagUpdates();
    Iterator iter=flagUpdates.iterator();
    while (iter.hasNext()) {
      ImapSessionFolder.FlagUpdate entry=(ImapSessionFolder.FlagUpdate)iter.next();
      int msn=entry.getMsn();
      Flags updatedFlags=entry.getFlags();
      StringBuilder out=new StringBuilder("String_Node_Str");
      out.append(MessageFlags.format(updatedFlags));
      if (entry.getUid() != null) {
        out.append("String_Node_Str");
        out.append(entry.getUid());
      }
      response.fetchResponse(msn,out.toString());
    }
    if (!omitExpunged) {
      int[] expunged=selected.getExpunged();
      for (int i=0; i < expunged.length; i++) {
        int msn=expunged[i];
        response.expungeResponse(msn);
      }
    }
  }
}

Fixed version (ground truth):
public void unsolicitedResponses(ImapResponse response,boolean omitExpunged) throws FolderException {
  ImapSessionFolder selected=getSelected();
  if (selected != null) {
    if (selected.isSizeChanged()) {
      response.existsResponse(selected.getMessageCount());
      response.recentResponse(selected.getRecentCount(true));
      selected.setSizeChanged(false);
    }
    final List<ImapSessionFolder.FlagUpdate> flagUpdates=selected.getFlagUpdates();
    for (    ImapSessionFolder.FlagUpdate update : flagUpdates) {
      int msn=update.getMsn();
      Flags updatedFlags=update.getFlags();
      StringBuilder out=new StringBuilder("String_Node_Str");
      out.append(MessageFlags.format(updatedFlags));
      if (update.getUid() != null) {
        out.append("String_Node_Str");
        out.append(update.getUid());
      }
      response.fetchResponse(msn,out.toString());
    }
    if (!omitExpunged) {
      int[] expunged=selected.getExpunged();
      for (      int msn : expunged) {
        response.expungeResponse(msn);
      }
    }
  }
}
Program: 31267
Project: 31267
Buggy source:
/** 
 * For testing only
 */
SmtpConnection(){
}

Fixed version (ground truth):
public SmtpConnection(SmtpHandler handler,Socket sock) throws IOException {
  this.sock=sock;
  sock.setSoTimeout(TIMEOUT_MILLIS);
  clientAddress=sock.getInetAddress();
  OutputStream o=sock.getOutputStream();
  InputStream i=sock.getInputStream();
  out=new InternetPrintWriter(o,true);
  in=new BufferedReader(new InputStreamReader(i));
  this.handler=handler;
}
Program: 31268
Project: 31268
Buggy source:
public String getClientAddress(){
  return clientAddress.getHostName();
}

Fixed version (ground truth):
public String getClientAddress(){
  return clientAddress.getHostAddress();
}
Program: 31269
Project: 31269
Buggy source:
protected AbstractServer(ServerSetup setup,Managers managers){
  try {
    this.setup=setup;
    bindTo=(setup.getBindAddress() == null) ? InetAddress.getByName("String_Node_Str") : InetAddress.getByName(setup.getBindAddress());
  }
 catch (  UnknownHostException e) {
    throw new RuntimeException(e);
  }
  this.managers=managers;
  handlers=new Vector();
}

Fixed version (ground truth):
protected AbstractServer(ServerSetup setup,Managers managers){
  try {
    this.setup=setup;
    bindTo=(setup.getBindAddress() == null) ? InetAddress.getByName("String_Node_Str") : InetAddress.getByName(setup.getBindAddress());
  }
 catch (  UnknownHostException e) {
    throw new RuntimeException(e);
  }
  this.managers=managers;
}
Program: 31270
Project: 31270
Buggy source:
public void run(){
  try {
    ins=socket.getInputStream();
    in=new BufferedReader(new InputStreamReader(socket.getInputStream(),"String_Node_Str"),512);
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
  try {
    outs=new BufferedOutputStream(socket.getOutputStream(),1024);
    out=new InternetPrintWriter(outs,true);
    ImapResponse response=new ImapResponse(outs);
    String responseBuffer=VERSION + "String_Node_Str";
    response.okResponse(null,responseBuffer);
    session=new ImapSessionImpl(imapHost,userManager,this,socket.getInetAddress().getHostName(),socket.getInetAddress().getHostAddress());
    while (requestHandler.handleRequest(ins,outs,session)) {
    }
  }
 catch (  Exception e) {
    log.error("String_Node_Str",e);
  }
 finally {
    resetHandler();
  }
}

Fixed version (ground truth):
public void run(){
  try {
    ins=socket.getInputStream();
    in=new BufferedReader(new InputStreamReader(socket.getInputStream(),"String_Node_Str"),512);
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
  try {
    outs=new BufferedOutputStream(socket.getOutputStream(),1024);
    out=new InternetPrintWriter(outs,true);
    ImapResponse response=new ImapResponse(outs);
    String responseBuffer=VERSION + "String_Node_Str";
    response.okResponse(null,responseBuffer);
    session=new ImapSessionImpl(imapHost,userManager,this,socket.getInetAddress().getHostAddress());
    while (requestHandler.handleRequest(ins,outs,session)) {
    }
  }
 catch (  Exception e) {
    log.error("String_Node_Str",e);
  }
 finally {
    resetHandler();
  }
}
Program: 31271
Project: 31271
Buggy source:
public synchronized void quit(){
  try {
    for (    Object handler : handlers) {
      ImapHandler imapHandler=(ImapHandler)handler;
      imapHandler.resetHandler();
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  try {
    if (null != serverSocket && !serverSocket.isClosed()) {
      serverSocket.close();
      serverSocket=null;
    }
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
public synchronized void quit(){
  try {
synchronized (handlers) {
      for (      ImapHandler handler : handlers) {
        handler.resetHandler();
      }
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  try {
    if (null != serverSocket && !serverSocket.isClosed()) {
      serverSocket.close();
      serverSocket=null;
    }
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}
Program: 31272
Project: 31272
Buggy source:
public void run(){
  try {
    try {
      serverSocket=openServerSocket();
      setRunning(true);
synchronized (this) {
        this.notifyAll();
      }
    }
 catch (    IOException e) {
      throw new RuntimeException(e);
    }
    while (keepOn()) {
      try {
        Socket clientSocket=serverSocket.accept();
        ImapHandler imapHandler=new ImapHandler(managers.getUserManager(),managers.getImapHostManager(),clientSocket);
        handlers.add(imapHandler);
        imapHandler.start();
      }
 catch (      IOException ignored) {
      }
    }
  }
  finally {
    quit();
  }
}

Fixed version (ground truth):
public void run(){
  try {
    try {
      serverSocket=openServerSocket();
      setRunning(true);
synchronized (this) {
        this.notifyAll();
      }
    }
 catch (    IOException e) {
      throw new RuntimeException(e);
    }
    while (keepOn()) {
      try {
        Socket clientSocket=serverSocket.accept();
synchronized (handlers) {
          if (!keepOn()) {
            clientSocket.close();
          }
 else {
            ImapHandler imapHandler=new ImapHandler(managers.getUserManager(),managers.getImapHostManager(),clientSocket);
            handlers.add(imapHandler);
            imapHandler.start();
          }
        }
      }
 catch (      IOException ignored) {
      }
    }
  }
  finally {
    quit();
  }
}