nus-yam/ex-repair huggingface dataset:
Program: 152098
Project: 152098
Buggy source:
/** 
 * Send a message
 * @param sms sms to be sent
 * @return whether the message was sent successfully
 */
public boolean sendMessage(SMS sms) throws Exception {
  Gateway gateway=Gateways.getInstance().get(sms.getGateway());
  logger.log(Level.FINE,"String_Node_Str",gateway);
  init();
  executor=new GatewayExecutor(sms);
  if (gateway == null) {
    executor.setProblem(Problem.INTERNAL_MESSAGE,l10n.getString("String_Node_Str"));
    return false;
  }
  this.variables=extractVariables(sms,gateway);
  Reader reader=null;
  boolean sentOk=false;
  try {
    reader=new InputStreamReader(gateway.getScript().openStream(),"String_Node_Str");
    String language=getPreferredLanguage(gateway);
    executor.setPreferredLanguage(language);
    forwardVariables();
    engine.eval(reader);
    sentOk=(Boolean)invocable.invokeFunction("String_Node_Str",new Object[0]);
    logger.log(Level.FINE,"String_Node_Str",sentOk);
  }
 catch (  ScriptException ex) {
    logger.log(Level.SEVERE,"String_Node_Str" + gateway,ex);
    executor.setProblem(Problem.UNKNOWN,null);
    return false;
  }
 finally {
    try {
      reader.close();
    }
 catch (    Exception ex) {
      logger.log(Level.SEVERE,"String_Node_Str" + gateway,ex);
    }
  }
  return sentOk;
}

Fixed version (ground truth):
/** 
 * Send a message
 * @param sms sms to be sent
 * @return whether the message was sent successfully
 */
public boolean sendMessage(SMS sms) throws Exception {
  Gateway gateway=Gateways.getInstance().get(sms.getGateway());
  logger.log(Level.FINE,"String_Node_Str",gateway);
  init();
  executor=new GatewayExecutor(sms);
  if (gateway == null) {
    executor.setProblem(Problem.INTERNAL_MESSAGE,l10n.getString("String_Node_Str"));
    return false;
  }
  this.variables=extractVariables(sms,gateway);
  Reader reader=null;
  boolean sentOk=false;
  try {
    reader=new InputStreamReader(gateway.getScript().openStream(),"String_Node_Str");
    String language=getPreferredLanguage(gateway);
    executor.setPreferredLanguage(language);
    forwardVariables();
    engine.eval(reader);
    sentOk=(Boolean)invocable.invokeFunction("String_Node_Str",new Object[0]);
    logger.log(Level.FINE,"String_Node_Str",sentOk);
    if (!sentOk && sms.getProblem() == null) {
      executor.setProblem(Problem.UNKNOWN,null);
    }
  }
 catch (  ScriptException ex) {
    logger.log(Level.SEVERE,"String_Node_Str" + gateway,ex);
    executor.setProblem(Problem.UNKNOWN,null);
    return false;
  }
 finally {
    try {
      reader.close();
    }
 catch (    Exception ex) {
      logger.log(Level.SEVERE,"String_Node_Str" + gateway,ex);
    }
  }
  return sentOk;
}
Program: 152101
Project: 152101
Buggy source:
/** 
 * Test if it is possible to write to a certain file/directory. It doesn't have to exist. This method is available because of Java bug on Windows which does not check permissions in File.canWrite() but only read-only bit (<a href="http://www.velocityreviews.com/forums/t303199-java-reporting-incorrect-directory-permission-under-windows-xp.html">reference1</a>, <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4939819>referece2</a>).
 * @param file File, existing or not existing; not null
 * @return true if file can be written, false if not
 */
public static boolean canWrite(File file){
  Validate.notNull(file);
  if (!RuntimeUtils.isWindows()) {
    return file.canWrite();
  }
  boolean success=false;
  try {
    if (file.exists()) {
      if (file.isDirectory()) {
        String name="String_Node_Str";
        File f=new File(file,name);
        while (f.exists()) {
          name=name + "String_Node_Str";
          f=new File(file,name);
        }
        f.createNewFile();
        success=f.delete();
      }
 else {
        FileOutputStream out=new FileOutputStream(file);
        out.close();
        success=true;
      }
    }
 else {
      FileUtils.touch(file);
      success=file.delete();
    }
  }
 catch (  Exception ex) {
    success=false;
  }
  return success;
}

Fixed version (ground truth):
/** 
 * Test if it is possible to write to a certain file/directory. It doesn't have to exist. This method is available because of Java bug on Windows which does not check permissions in File.canWrite() but only read-only bit (<a href="http://www.velocityreviews.com/forums/t303199-java-reporting-incorrect-directory-permission-under-windows-xp.html">reference1</a>, <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4939819">reference2</a>).
 * @param file File, existing or not existing; not null
 * @return true if file can be written, false if not
 */
public static boolean canWrite(File file){
  Validate.notNull(file);
  if (!RuntimeUtils.isWindows()) {
    return file.canWrite();
  }
  boolean success=false;
  try {
    if (file.exists()) {
      if (file.isDirectory()) {
        String name="String_Node_Str";
        File f=new File(file,name);
        while (f.exists()) {
          name=name + "String_Node_Str";
          f=new File(file,name);
        }
        f.createNewFile();
        success=f.delete();
      }
 else {
        FileOutputStream out=new FileOutputStream(file);
        out.close();
        success=true;
      }
    }
 else {
      FileUtils.touch(file);
      success=file.delete();
    }
  }
 catch (  Exception ex) {
    success=false;
  }
  return success;
}
Program: 152102
Project: 152102
Buggy source:
/** 
 * This method <b>must not</b> be called from EDT. For description see  {@link ImageCodeResolver#resolveImageCode(esmska.data.SMS)}
 */
@Override public boolean resolveImageCode(final SMS sms){
  if (SwingUtilities.isEventDispatchThread()) {
    throw new IllegalStateException("String_Node_Str");
  }
  Validate.notNull(sms);
  if (sms.getImage() == null && StringUtils.isEmpty(sms.getImageHint())) {
    sms.setImageCode(null);
    return false;
  }
  final Semaphore semaphore=new Semaphore(0);
  try {
    SwingUtilities.invokeLater(new Runnable(){
      @Override public void run(){
        GatewayMessageDialog gmd=GatewayMessageDialog.getInstance();
        gmd.addImageCodeMsg(sms,new ActionListener(){
          @Override public void actionPerformed(          ActionEvent e){
            semaphore.release();
          }
        }
);
      }
    }
);
    semaphore.acquire();
    return StringUtils.isNotEmpty(sms.getImageCode());
  }
 catch (  Exception ex) {
    logger.log(Level.WARNING,"String_Node_Str",ex);
    return false;
  }
}

Fixed version (ground truth):
/** 
 * This method <b>must not</b> be called from EDT. For description see  {@link ImageCodeResolver#resolveImageCode(esmska.data.SMS)}
 */
@Override public boolean resolveImageCode(final SMS sms){
  if (SwingUtilities.isEventDispatchThread()) {
    throw new IllegalStateException("String_Node_Str");
  }
  Validate.notNull(sms);
  if (sms.getImage() == null && StringUtils.isEmpty(sms.getImageHint())) {
    sms.setImageCode(null);
    return false;
  }
  final Semaphore semaphore=new Semaphore(0);
  try {
    SwingUtilities.invokeLater(new Runnable(){
      @Override public void run(){
        GatewayMessageFrame gmf=GatewayMessageFrame.getInstance();
        gmf.addImageCodeMsg(sms,new ActionListener(){
          @Override public void actionPerformed(          ActionEvent e){
            semaphore.release();
          }
        }
);
      }
    }
);
    semaphore.acquire();
    return StringUtils.isNotEmpty(sms.getImageCode());
  }
 catch (  Exception ex) {
    logger.log(Level.WARNING,"String_Node_Str",ex);
    return false;
  }
}
Program: 152103
Project: 152103
Buggy source:
@Override public void run(){
  GatewayMessageDialog gmd=GatewayMessageDialog.getInstance();
  gmd.addImageCodeMsg(sms,new ActionListener(){
    @Override public void actionPerformed(    ActionEvent e){
      semaphore.release();
    }
  }
);
}

Fixed version (ground truth):
@Override public void run(){
  GatewayMessageFrame gmf=GatewayMessageFrame.getInstance();
  gmf.addImageCodeMsg(sms,new ActionListener(){
    @Override public void actionPerformed(    ActionEvent e){
      semaphore.release();
    }
  }
);
}
Program: 152104
Project: 152104
Buggy source:
/** 
 * set selected contacts in contact list or contact to display 
 */
public void setContacts(Collection<Contact> contacts){
  Validate.notNull(contacts);
  disableContactListeners=true;
  int count=contacts.size();
  if (count == 1) {
    Contact c=contacts.iterator().next();
    recipientField.setContact(c);
    gatewayComboBox.setSelectedGateway(c.getGateway());
  }
  boolean multiSendMode=(count > 1);
  if (multiSendMode) {
    recipientTextField.setText(l10n.getString("String_Node_Str"));
  }
  recipientTextField.setEnabled(!multiSendMode);
  gatewayComboBox.setEnabled(!multiSendMode);
  Set<Contact> set=new HashSet<Contact>();
  set.addAll(contacts);
  if (count < 1) {
    Contact contact=recipientField.getContact();
    set.add(new Contact(contact != null ? contact.getName() : null,recipientField.getNumber(),gatewayComboBox.getSelectedGatewayName()));
  }
  envelope.setContacts(set);
  sendAction.updateStatus();
  smsTextPaneDocumentFilter.requestUpdate();
  updateNumberInfoLabel();
  disableContactListeners=false;
}

Fixed version (ground truth):
/** 
 * set selected contacts in contact list or contact to display 
 */
public void setContacts(Collection<Contact> contacts){
  Validate.notNull(contacts);
  disableContactListeners=true;
  int count=contacts.size();
  if (count == 1) {
    Contact c=contacts.iterator().next();
    recipientField.setContact(c);
    gatewayComboBox.setSelectedGateway(c.getGateway());
  }
  boolean multiSendMode=(count > 1);
  if (multiSendMode) {
    recipientTextField.setText(l10n.getString("String_Node_Str"));
    gatewayComboBox.setSelectedGateway(null);
  }
  recipientTextField.setEnabled(!multiSendMode);
  gatewayComboBox.setEnabled(!multiSendMode);
  Set<Contact> set=new HashSet<Contact>();
  set.addAll(contacts);
  if (count < 1) {
    Contact contact=recipientField.getContact();
    set.add(new Contact(contact != null ? contact.getName() : null,recipientField.getNumber(),gatewayComboBox.getSelectedGatewayName()));
  }
  envelope.setContacts(set);
  sendAction.updateStatus();
  smsTextPaneDocumentFilter.requestUpdate();
  updateNumberInfoLabel();
  disableContactListeners=false;
}
Program: 152105
Project: 152105
Buggy source:
/** 
 * Mark the SMS as successfully sent.
 * @param sms sent SMS, not null
 */
public void setSMSSent(SMS sms){
  Validate.notNull(sms);
  logger.fine("String_Node_Str" + sms);
  sms.setStatus(SMS.Status.SENT);
  valuedSupport.fireEventOccured(Events.SMS_SENT,sms);
  updateGatewayDelay(sms.getGateway());
  remove(sms);
  timer.start();
}

Fixed version (ground truth):
/** 
 * Mark the SMS as successfully sent.
 * @param sms sent SMS, not null
 */
public void setSMSSent(SMS sms){
  Validate.notNull(sms);
  logger.log(Level.FINE,"String_Node_Str",sms);
  sms.setStatus(SMS.Status.SENT);
  valuedSupport.fireEventOccured(Events.SMS_SENT,sms);
  updateGatewayDelay(sms.getGateway());
  remove(sms);
  timer.start();
}
Program: 152106
Project: 152106
Buggy source:
/** 
 * Move SMS in the queue to another position. Queue is always sorted by gateway, therefore SMS may be moved only within section of its gateway.
 * @param sms sms to be moved, not null
 * @param positionDelta direction and amount of movement. Positive number movesto the back of the queue, negative number moves to the front of the queue. The number corresponds to the number of positions to change. If the number is larger than current queue dimensions, the element will simply stop as the first or as the last element.
 */
public void movePosition(SMS sms,int positionDelta){
  Validate.notNull(sms,"String_Node_Str");
  String gateway=sms.getGateway();
synchronized (queue) {
    if (positionDelta == 0 || !queue.containsKey(gateway) || !queue.get(gateway).contains(sms)) {
      return;
    }
    logger.fine("String_Node_Str" + sms + "String_Node_Str"+ positionDelta);
    List<SMS> list=queue.get(gateway);
    int currentPos=list.indexOf(sms);
    int newPos=currentPos + positionDelta;
    if (newPos < 0) {
      newPos=0;
    }
    if (newPos > list.size() - 1) {
      newPos=list.size() - 1;
    }
    if (currentPos == newPos) {
      return;
    }
    list.remove(currentPos);
    list.add(newPos,sms);
  }
  valuedSupport.fireEventOccured(Events.SMS_POSITION_CHANGED,sms);
  if (sms.getStatus() == SMS.Status.READY) {
    sms.setStatus(SMS.Status.WAITING);
    markAllIfReady();
  }
}

Fixed version (ground truth):
/** 
 * Move SMS in the queue to another position. Queue is always sorted by gateway, therefore SMS may be moved only within section of its gateway.
 * @param sms sms to be moved, not null
 * @param positionDelta direction and amount of movement. Positive number movesto the back of the queue, negative number moves to the front of the queue. The number corresponds to the number of positions to change. If the number is larger than current queue dimensions, the element will simply stop as the first or as the last element.
 */
public void movePosition(SMS sms,int positionDelta){
  Validate.notNull(sms,"String_Node_Str");
  String gateway=sms.getGateway();
synchronized (queue) {
    if (positionDelta == 0 || !queue.containsKey(gateway) || !queue.get(gateway).contains(sms)) {
      return;
    }
    logger.log(Level.FINE,"String_Node_Str",new Object[]{sms,positionDelta});
    List<SMS> list=queue.get(gateway);
    int currentPos=list.indexOf(sms);
    int newPos=currentPos + positionDelta;
    if (newPos < 0) {
      newPos=0;
    }
    if (newPos > list.size() - 1) {
      newPos=list.size() - 1;
    }
    if (currentPos == newPos) {
      return;
    }
    list.remove(currentPos);
    list.add(newPos,sms);
  }
  valuedSupport.fireEventOccured(Events.SMS_POSITION_CHANGED,sms);
  if (sms.getStatus() == SMS.Status.READY) {
    sms.setStatus(SMS.Status.WAITING);
    markAllIfReady();
  }
}
Program: 152107
Project: 152107
Buggy source:
/** 
 * Check if sms is ready and set status if it is 
 */
private void markIfReady(SMS sms){
  Validate.notNull(sms);
  long delay=getSMSDelay(sms);
  if (sms.getStatus() == SMS.Status.WAITING && delay <= 0) {
    logger.finer("String_Node_Str" + sms);
    sms.setStatus(SMS.Status.READY);
    valuedSupport.fireEventOccured(Events.NEW_SMS_READY,sms);
  }
}

Fixed version (ground truth):
/** 
 * Check if sms is ready and set status if it is 
 */
private void markIfReady(SMS sms){
  Validate.notNull(sms);
  long delay=getSMSDelay(sms);
  if (sms.getStatus() == SMS.Status.WAITING && delay <= 0) {
    logger.log(Level.FINER,"String_Node_Str",sms);
    sms.setStatus(SMS.Status.READY);
    valuedSupport.fireEventOccured(Events.NEW_SMS_READY,sms);
  }
}
Program: 152108
Project: 152108
Buggy source:
/** 
 * Remove SMS from the queue. If the SMS is not present nothing happens.
 * @param sms SMS to be removed. Not null.
 * @return See {@link Collection#remove(java.lang.Object) }
 */
public boolean remove(SMS sms){
  Validate.notNull(sms);
  String gateway=sms.getGateway();
  boolean removed=false;
synchronized (queue) {
    if (queue.containsKey(gateway)) {
      removed=queue.get(gateway).remove(sms);
    }
    if (removed && queue.get(gateway).size() == 0) {
      queue.remove(gateway);
      gatewayDelay.remove(gateway);
    }
  }
  if (removed) {
    logger.fine("String_Node_Str" + sms);
    valuedSupport.fireEventOccured(Events.SMS_REMOVED,sms);
    markAllIfReady();
  }
  return removed;
}

Fixed version (ground truth):
/** 
 * Remove SMS from the queue. If the SMS is not present nothing happens.
 * @param sms SMS to be removed. Not null.
 * @return See {@link Collection#remove(java.lang.Object) }
 */
public boolean remove(SMS sms){
  Validate.notNull(sms);
  String gateway=sms.getGateway();
  boolean removed=false;
synchronized (queue) {
    if (queue.containsKey(gateway)) {
      removed=queue.get(gateway).remove(sms);
    }
    if (removed && queue.get(gateway).isEmpty()) {
      queue.remove(gateway);
      gatewayDelay.remove(gateway);
    }
  }
  if (removed) {
    logger.log(Level.FINE,"String_Node_Str",sms);
    valuedSupport.fireEventOccured(Events.SMS_REMOVED,sms);
    markAllIfReady();
  }
  return removed;
}
Program: 152109
Project: 152109
Buggy source:
/** 
 * Add new SMS to the queue. May not be null.
 * @return See {@link Collection#add}.
 */
public boolean add(SMS sms){
  Validate.notNull(sms);
  sms.setStatus(SMS.Status.WAITING);
  String gateway=sms.getGateway();
  boolean added=false;
synchronized (queue) {
    if (queue.containsKey(gateway)) {
      if (!queue.get(gateway).contains(sms)) {
        added=queue.get(gateway).add(sms);
      }
    }
 else {
      List<SMS> list=new ArrayList<SMS>();
      list.add(sms);
      queue.put(gateway,list);
      added=true;
    }
  }
  if (added) {
    logger.fine("String_Node_Str" + sms);
    valuedSupport.fireEventOccured(Events.SMS_ADDED,sms);
    markIfReady(sms);
    timer.start();
  }
  return added;
}

Fixed version (ground truth):
/** 
 * Add new SMS to the queue. May not be null.
 * @return See {@link Collection#add}.
 */
public boolean add(SMS sms){
  Validate.notNull(sms);
  sms.setStatus(SMS.Status.WAITING);
  String gateway=sms.getGateway();
  boolean added=false;
synchronized (queue) {
    if (queue.containsKey(gateway)) {
      if (!queue.get(gateway).contains(sms)) {
        added=queue.get(gateway).add(sms);
      }
    }
 else {
      List<SMS> list=new ArrayList<SMS>();
      list.add(sms);
      queue.put(gateway,list);
      added=true;
    }
  }
  if (added) {
    logger.log(Level.FINE,"String_Node_Str",sms);
    valuedSupport.fireEventOccured(Events.SMS_ADDED,sms);
    markIfReady(sms);
    timer.start();
  }
  return added;
}
Program: 152110
Project: 152110
Buggy source:
/** 
 * Check all sms for that which are ready and set their status 
 */
private void markAllIfReady(){
  ArrayList<SMS> ready=new ArrayList<SMS>();
synchronized (queue) {
    for (    String gateway : queue.keySet()) {
      long delay=getGatewayDelay(gateway);
      if (delay > 0) {
        continue;
      }
      for (      SMS sms : queue.get(gateway)) {
        long smsDelay=getSMSDelay(sms);
        if (smsDelay > 0) {
          break;
        }
        if (sms.getStatus() == SMS.Status.WAITING) {
          logger.finer("String_Node_Str" + sms);
          sms.setStatus(SMS.Status.READY);
          ready.add(sms);
        }
      }
    }
  }
  for (  SMS sms : ready) {
    valuedSupport.fireEventOccured(Events.NEW_SMS_READY,sms);
  }
}

Fixed version (ground truth):
/** 
 * Check all sms for that which are ready and set their status 
 */
private void markAllIfReady(){
  ArrayList<SMS> ready=new ArrayList<SMS>();
synchronized (queue) {
    for (    String gateway : queue.keySet()) {
      long delay=getGatewayDelay(gateway);
      if (delay > 0) {
        continue;
      }
      for (      SMS sms : queue.get(gateway)) {
        long smsDelay=getSMSDelay(sms);
        if (smsDelay > 0) {
          break;
        }
        if (sms.getStatus() == SMS.Status.WAITING) {
          logger.log(Level.FINER,"String_Node_Str",sms);
          sms.setStatus(SMS.Status.READY);
          ready.add(sms);
        }
      }
    }
  }
  for (  SMS sms : ready) {
    valuedSupport.fireEventOccured(Events.NEW_SMS_READY,sms);
  }
}
Program: 152111
Project: 152111
Buggy source:
/** 
 * Mark SMS as failed during sending. Pauses the queue.
 * @param sms SMS that has failed, not null
 */
public void setSMSFailed(SMS sms){
  Validate.notNull(sms);
  logger.fine("String_Node_Str" + sms);
  setPaused(true);
  sms.setStatus(SMS.Status.WAITING);
  valuedSupport.fireEventOccured(Events.SMS_SENDING_FAILED,sms);
  updateGatewayDelay(sms.getGateway());
  timer.start();
  markIfReady(sms);
}

Fixed version (ground truth):
/** 
 * Mark SMS as failed during sending. Pauses the queue.
 * @param sms SMS that has failed, not null
 */
public void setSMSFailed(SMS sms){
  Validate.notNull(sms);
  logger.log(Level.FINE,"String_Node_Str",sms);
  setPaused(true);
  sms.setStatus(SMS.Status.WAITING);
  valuedSupport.fireEventOccured(Events.SMS_SENDING_FAILED,sms);
  updateGatewayDelay(sms.getGateway());
  timer.start();
  markIfReady(sms);
}
Program: 152112
Project: 152112
Buggy source:
/** 
 * Add collection of new SMS to the queue.
 * @param collection Collection of SMS. May not be null, may not contain null element.
 * @return See {@link Collection#addAll(java.util.Collection)}
 */
public boolean addAll(Collection<SMS> collection){
  Validate.notNull(collection,"String_Node_Str");
  Validate.noNullElements(collection);
  logger.fine("String_Node_Str" + collection.size() + "String_Node_Str");
  boolean added=false;
  for (  SMS sms : collection) {
    if (add(sms)) {
      added=true;
    }
  }
  return added;
}

Fixed version (ground truth):
/** 
 * Add collection of new SMS to the queue.
 * @param collection Collection of SMS. May not be null, may not contain null element.
 * @return See {@link Collection#addAll(java.util.Collection)}
 */
public boolean addAll(Collection<SMS> collection){
  Validate.notNull(collection,"String_Node_Str");
  Validate.noNullElements(collection);
  logger.log(Level.FINE,"String_Node_Str",collection.size());
  boolean added=false;
  for (  SMS sms : collection) {
    if (add(sms)) {
      added=true;
    }
  }
  return added;
}
Program: 152113
Project: 152113
Buggy source:
/** 
 * Mark SMS as currently being sent.
 * @param sms SMS that is currently being sent, not null
 */
public void setSMSSending(SMS sms){
  Validate.notNull(sms);
  logger.fine("String_Node_Str" + sms);
  sms.setStatus(SMS.Status.SENDING);
  valuedSupport.fireEventOccured(Events.SENDING_SMS,sms);
}

Fixed version (ground truth):
/** 
 * Mark SMS as currently being sent.
 * @param sms SMS that is currently being sent, not null
 */
public void setSMSSending(SMS sms){
  Validate.notNull(sms);
  logger.log(Level.FINE,"String_Node_Str",sms);
  sms.setStatus(SMS.Status.SENDING);
  valuedSupport.fireEventOccured(Events.SENDING_SMS,sms);
}
Program: 152114
Project: 152114
Buggy source:
private void smsFailed(SMS sms){
  logger.info("String_Node_Str" + sms);
  log.addRecord(new Log.Record(MessageFormat.format(l10n.getString("String_Node_Str"),sms.getRecipient()),null,Icons.STATUS_WARNING));
  String cause=(sms.getErrMsg() != null ? sms.getErrMsg().trim() : "String_Node_Str");
  JHtmlLabel label=new JHtmlLabel(MessageFormat.format(l10n.getString("String_Node_Str"),sms.getRecipient(),cause));
  label.addValuedListener(new ValuedListener<JHtmlLabel.Events,String>(){
    @Override public void eventOccured(    ValuedEvent<JHtmlLabel.Events,String> e){
switch (e.getEvent()) {
case LINK_CLICKED:
        Actions.getBrowseAction(e.getValue()).actionPerformed(null);
    }
  }
}
);
label.setVerticalAlignment(SwingConstants.TOP);
JPanel panel=new JPanel(new BorderLayout());
panel.add(label,BorderLayout.CENTER);
JOptionPane pane=new JOptionPane(panel,JOptionPane.WARNING_MESSAGE);
JDialog dialog=pane.createDialog(MainFrame.this,null);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
int width=panel.getWidth();
int height=panel.getHeight();
if (dialog.getWidth() > screenSize.getWidth()) {
  width=(int)screenSize.getWidth() * 2 / 3;
  height=height * (panel.getWidth() / width);
  panel.setPreferredSize(new Dimension(width,height));
  dialog=pane.createDialog(MainFrame.this,null);
}
logger.fine("String_Node_Str");
RuntimeUtils.setDocumentModalDialog(dialog);
dialog.setResizable(true);
dialog.pack();
dialog.setVisible(true);
finish(sms);
}

Fixed version (ground truth):
private void smsFailed(SMS sms){
  logger.log(Level.INFO,"String_Node_Str",sms);
  log.addRecord(new Log.Record(MessageFormat.format(l10n.getString("String_Node_Str"),sms.getRecipient()),null,Icons.STATUS_WARNING));
  String cause=(sms.getErrMsg() != null ? sms.getErrMsg().trim() : "String_Node_Str");
  JHtmlLabel label=new JHtmlLabel(MessageFormat.format(l10n.getString("String_Node_Str"),sms.getRecipient(),cause));
  label.addValuedListener(new ValuedListener<JHtmlLabel.Events,String>(){
    @Override public void eventOccured(    ValuedEvent<JHtmlLabel.Events,String> e){
switch (e.getEvent()) {
case LINK_CLICKED:
        Actions.getBrowseAction(e.getValue()).actionPerformed(null);
    }
  }
}
);
label.setVerticalAlignment(SwingConstants.TOP);
JPanel panel=new JPanel(new BorderLayout());
panel.add(label,BorderLayout.CENTER);
JOptionPane pane=new JOptionPane(panel,JOptionPane.WARNING_MESSAGE);
JDialog dialog=pane.createDialog(MainFrame.this,null);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
int width=panel.getWidth();
int height=panel.getHeight();
if (dialog.getWidth() > screenSize.getWidth()) {
  width=(int)screenSize.getWidth() * 2 / 3;
  height=height * (panel.getWidth() / width);
  panel.setPreferredSize(new Dimension(width,height));
  dialog=pane.createDialog(MainFrame.this,null);
}
logger.fine("String_Node_Str");
RuntimeUtils.setDocumentModalDialog(dialog);
dialog.setResizable(true);
dialog.pack();
dialog.setVisible(true);
finish(sms);
}
Program: 152115
Project: 152115
Buggy source:
/** 
 * Quit the program 
 */
public void exit(){
  logger.fine("String_Node_Str");
  Runtime.getRuntime().removeShutdownHook(shutdownThread);
  boolean saveOk=saveAll();
  if (!saveOk) {
    JOptionPane.showMessageDialog(this,l10n.getString("String_Node_Str"),null,JOptionPane.WARNING_MESSAGE);
  }
  int returnCode=saveOk ? 0 : 3;
  logger.fine("String_Node_Str" + returnCode);
  System.exit(returnCode);
}

Fixed version (ground truth):
/** 
 * Quit the program 
 */
public void exit(){
  logger.fine("String_Node_Str");
  Runtime.getRuntime().removeShutdownHook(shutdownThread);
  boolean saveOk=saveAll();
  if (!saveOk) {
    JOptionPane.showMessageDialog(this,l10n.getString("String_Node_Str"),null,JOptionPane.WARNING_MESSAGE);
  }
  int returnCode=saveOk ? 0 : 3;
  logger.log(Level.FINE,"String_Node_Str",returnCode);
  System.exit(returnCode);
}
Program: 152116
Project: 152116
Buggy source:
/** 
 * Move SMS in the queue to another position. Queue is always sorted by gateway, therefore SMS may be moved only within section of its gateway.
 * @param sms sms to be moved, not null
 * @param positionDelta direction and amount of movement. Positive number movesto the back of the queue, negative number moves to the front of the queue. The number corresponds to the number of positions to change. If the number is larger than current queue dimensions, the element will simply stop as the first or as the last element.
 */
public void movePosition(SMS sms,int positionDelta){
  Validate.notNull(sms,"String_Node_Str");
  String gateway=sms.getGateway();
synchronized (queue) {
    if (positionDelta == 0 || !queue.containsKey(gateway) || !queue.get(gateway).contains(sms)) {
      return;
    }
    logger.log(Level.FINE,"String_Node_Str",new Object[]{sms,positionDelta});
    List<SMS> list=queue.get(gateway);
    int currentPos=list.indexOf(sms);
    int newPos=currentPos + positionDelta;
    if (newPos < 0) {
      newPos=0;
    }
    if (newPos > list.size() - 1) {
      newPos=list.size() - 1;
    }
    if (currentPos == newPos) {
      return;
    }
    list.remove(currentPos);
    list.add(newPos,sms);
  }
  valuedSupport.fireEventOccured(Events.SMS_POSITION_CHANGED,sms);
  if (sms.getStatus() == SMS.Status.READY) {
    sms.setStatus(SMS.Status.WAITING);
    markAllIfReady();
  }
}

Fixed version (ground truth):
/** 
 * Move SMS in the queue to another position. Queue is always sorted by gateway, therefore SMS may be moved only within section of its gateway.
 * @param sms sms to be moved, not null
 * @param positionDelta direction and amount of movement. Positive number movesto the back of the queue, negative number moves to the front of the queue. The number corresponds to the number of positions to change. If the number is larger than current queue dimensions, the element will simply stop as the first or as the last element.
 */
public void movePosition(SMS sms,int positionDelta){
  Validate.notNull(sms,"String_Node_Str");
  String gateway=sms.getGateway();
synchronized (queue) {
    if (positionDelta == 0 || !queue.containsKey(gateway) || !queue.get(gateway).contains(sms)) {
      return;
    }
    logger.log(Level.FINE,"String_Node_Str",new Object[]{sms,positionDelta});
    List<SMS> list=queue.get(gateway);
    int currentPos=list.indexOf(sms);
    int newPos=currentPos + positionDelta;
    if (newPos < 0) {
      newPos=0;
    }
    if (newPos > list.size() - 1) {
      newPos=list.size() - 1;
    }
    if (currentPos == newPos) {
      return;
    }
    list.remove(currentPos);
    list.add(newPos,sms);
  }
  valuedSupport.fireEventOccured(Events.SMS_POSITION_CHANGED,sms);
  sms.setStatus(SMS.Status.WAITING);
  markAllIfReady();
}
Program: 152117
Project: 152117
Buggy source:
/** 
 * Move SMS in the queue to another position. Queue is always sorted by gateway, therefore SMS may be moved only within section of its gateway.
 * @param sms sms to be moved, not null
 * @param positionDelta direction and amount of movement. Positive number movesto the back of the queue, negative number moves to the front of the queue. The number corresponds to the number of positions to change. If the number is larger than current queue dimensions, the element will simply stop as the first or as the last element.
 */
public void movePosition(SMS sms,int positionDelta){
  Validate.notNull(sms,"String_Node_Str");
  String gateway=sms.getGateway();
synchronized (queue) {
    if (positionDelta == 0 || !queue.containsKey(gateway) || !queue.get(gateway).contains(sms)) {
      return;
    }
    logger.log(Level.FINE,"String_Node_Str",new Object[]{sms,positionDelta});
    List<SMS> list=queue.get(gateway);
    int currentPos=list.indexOf(sms);
    int newPos=currentPos + positionDelta;
    if (newPos < 0) {
      newPos=0;
    }
    if (newPos > list.size() - 1) {
      newPos=list.size() - 1;
    }
    if (currentPos == newPos) {
      return;
    }
    list.remove(currentPos);
    list.add(newPos,sms);
  }
  valuedSupport.fireEventOccured(Events.SMS_POSITION_CHANGED,sms);
  sms.setStatus(SMS.Status.WAITING);
  markAllIfReady();
}

Fixed version (ground truth):
/** 
 * Move SMS in the queue to another position. Queue is always sorted by gateway, therefore SMS may be moved only within section of its gateway.
 * @param sms sms to be moved, not null
 * @param positionDelta direction and amount of movement. Positive number movesto the back of the queue, negative number moves to the front of the queue. The number corresponds to the number of positions to change. If the number is larger than current queue dimensions, the element will simply stop as the first or as the last element.
 */
public void movePosition(SMS sms,int positionDelta){
  Validate.notNull(sms,"String_Node_Str");
  String gateway=sms.getGateway();
synchronized (queue) {
    if (positionDelta == 0 || !queue.containsKey(gateway) || !queue.get(gateway).contains(sms)) {
      return;
    }
    logger.log(Level.FINE,"String_Node_Str",new Object[]{sms,positionDelta});
    List<SMS> list=queue.get(gateway);
    int currentPos=list.indexOf(sms);
    int newPos=currentPos + positionDelta;
    if (newPos < 0) {
      newPos=0;
    }
    if (newPos > list.size() - 1) {
      newPos=list.size() - 1;
    }
    if (currentPos == newPos) {
      return;
    }
    list.remove(currentPos);
    list.add(newPos,sms);
  }
  valuedSupport.fireEventOccured(Events.SMS_POSITION_CHANGED,sms);
  List<SMS> messages=getAll(sms.getGateway());
  for (  SMS message : messages) {
    if (message.getStatus() == SMS.Status.READY) {
      message.setStatus(SMS.Status.WAITING);
    }
  }
  markAllIfReady();
}
Program: 152118
Project: 152118
Buggy source:
/** 
 * Proceed with a backup. Backs up today's configuration (if not backed up already). Preserves last 7 backups, older ones are deleted.
 */
public void backupConfigFiles() throws IOException {
  BackupManager bm=new BackupManager(backupDir);
  File[] list=new File[]{configFile,contactsFile,historyFile,keyringFile,queueFile,logFile};
  boolean backed=bm.backupFiles(Arrays.asList(list),false);
  if (backed) {
    logFile.delete();
  }
  bm.removeOldBackups(7);
}

Fixed version (ground truth):
/** 
 * Proceed with a backup. Backs up today's configuration (if not backed up already). Preserves last 7 backups, older ones are deleted.
 */
public void backupConfigFiles() throws IOException {
  BackupManager bm=new BackupManager(backupDir);
  File[] list=new File[]{configFile,contactsFile,historyFile,keyringFile,queueFile,logFile};
  boolean backed=bm.backupFiles(Arrays.asList(list),false);
  if (backed) {
    logFile.delete();
    File parent=logFile.getParentFile();
    final String logName=logFile.getName();
    File[] oldLogs=parent.listFiles(new FilenameFilter(){
      private final Pattern pattern=Pattern.compile("String_Node_Str" + Pattern.quote(logName) + "String_Node_Str");
      @Override public boolean accept(      File dir,      String name){
        return pattern.matcher(name).matches();
      }
    }
);
    if (oldLogs != null) {
      for (      File oldLog : oldLogs) {
        oldLog.delete();
      }
    }
  }
  bm.removeOldBackups(7);
}
Program: 152119
Project: 152119
Buggy source:
/** 
 * Get set of operators from set of operator URLs
 * @param operatorURLs set of operator URLs (file or jar URLs)
 * @return set of operators
 * @throws java.beans.IntrospectionException When current JRE does not support JavaScript execution
 */
private static TreeSet<Operator> importOperators(Set<URL> operatorURLs) throws IntrospectionException {
  logger.finer("String_Node_Str" + operatorURLs.size() + "String_Node_Str");
  TreeSet<Operator> operators=new TreeSet<Operator>();
  for (  URL operatorURL : operatorURLs) {
    try {
      DefaultOperator operator=new DefaultOperator(operatorURL);
      if (Config.compareProgramVersions(Config.getLatestVersion(),operator.getMinProgramVersion()) >= 0) {
        operators.add(operator);
      }
 else {
        logger.info("String_Node_Str" + operator.getName() + "String_Node_Str"+ operator.getMinProgramVersion()+ "String_Node_Str");
      }
    }
 catch (    IOException ex) {
      logger.log(Level.WARNING,"String_Node_Str" + operatorURL.toExternalForm(),ex);
    }
catch (    IntrospectionException ex) {
      throw ex;
    }
catch (    Exception ex) {
      logger.log(Level.WARNING,"String_Node_Str" + operatorURL.toExternalForm(),ex);
    }
  }
  logger.finer("String_Node_Str" + operators.size() + "String_Node_Str");
  return operators;
}

Fixed version (ground truth):
/** 
 * Get set of operators from set of operator URLs
 * @param operatorURLs set of operator URLs (file or jar URLs)
 * @return set of operators
 * @throws java.beans.IntrospectionException When current JRE does not support JavaScript execution
 */
private static TreeSet<Operator> importOperators(Set<URL> operatorURLs) throws IntrospectionException {
  logger.finer("String_Node_Str" + operatorURLs.size() + "String_Node_Str");
  TreeSet<Operator> operators=new TreeSet<Operator>();
  for (  URL operatorURL : operatorURLs) {
    try {
      DefaultOperator operator=new DefaultOperator(operatorURL);
      if (Config.compareProgramVersions(Config.getLatestVersion(),operator.getMinProgramVersion()) < 0) {
        logger.info("String_Node_Str" + operator.getName() + "String_Node_Str"+ operator.getMinProgramVersion()+ "String_Node_Str");
        continue;
      }
      if (operators.contains(operator)) {
        for (Iterator<Operator> it=operators.iterator(); it.hasNext(); ) {
          Operator op=it.next();
          if (op.equals(operator) && op.getVersion().compareTo(operator.getVersion()) < 0) {
            it.remove();
          }
        }
      }
      operators.add(operator);
    }
 catch (    IOException ex) {
      logger.log(Level.WARNING,"String_Node_Str" + operatorURL.toExternalForm(),ex);
    }
catch (    IntrospectionException ex) {
      throw ex;
    }
catch (    Exception ex) {
      logger.log(Level.WARNING,"String_Node_Str" + operatorURL.toExternalForm(),ex);
    }
  }
  logger.finer("String_Node_Str" + operators.size() + "String_Node_Str");
  return operators;
}
Program: 152121
Project: 152121
Buggy source:
/** 
 * Go through all downloaded update information and only leave those operators which are new or updated compared to current ones. This can be used to reload update info after partial update. Also removes operators requiring more recent program version than available online (stable/unstable depending on config settings).
 */
public void refreshUpdatedOperators(){
  for (Iterator<OperatorUpdateInfo> it=operatorUpdates.iterator(); it.hasNext(); ) {
    OperatorUpdateInfo info=it.next();
    Operator op=Operators.getOperator(info.getName());
    if (op != null && info.getVersion().compareTo(op.getVersion()) <= 0) {
      it.remove();
      continue;
    }
    if (Config.compareProgramVersions(info.getMinProgramVersion(),getLatestProgramVersion()) > 0) {
      it.remove();
      continue;
    }
  }
}

Fixed version (ground truth):
/** 
 * Go through all downloaded update information and only leave those operators which are new or updated compared to current ones. This can be used to reload update info after partial update. Also removes operators requiring more recent program version than available online (stable/unstable depending on config settings) and operators hidden by the user (operator filter).
 */
public void refreshUpdatedOperators(){
  String[] patterns=config.getOperatorFilter().split("String_Node_Str");
  for (Iterator<OperatorUpdateInfo> it=operatorUpdates.iterator(); it.hasNext(); ) {
    OperatorUpdateInfo info=it.next();
    Operator op=Operators.getOperator(info.getName());
    if (op != null && info.getVersion().compareTo(op.getVersion()) <= 0) {
      it.remove();
      continue;
    }
    if (Config.compareProgramVersions(info.getMinProgramVersion(),getLatestProgramVersion()) > 0) {
      it.remove();
      continue;
    }
    boolean filtered=true;
    for (    String pattern : patterns) {
      if (info.getName().contains(pattern)) {
        filtered=false;
        continue;
      }
    }
    if (filtered) {
      it.remove();
      continue;
    }
  }
}
Program: 152125
Project: 152125
Buggy source:
public int compare(Object o1,Object o2){
  if (!(o1 instanceof String) || !(o2 instanceof String)) {
    return 0;
  }
  String s1=(String)o1;
  String s2=(String)o2;
  int thisMarker=0;
  int thisNumericChunk=0;
  int thatMarker=0;
  int thatNumericChunk=0;
  while ((thisMarker < s1.length()) && (thatMarker < s2.length())) {
    char thisCh=s1.charAt(thisMarker);
    char thatCh=s2.charAt(thatMarker);
    StringBuilder thisChunk=new StringBuilder();
    StringBuilder thatChunk=new StringBuilder();
    while ((thisMarker < s1.length()) && inChunk(thisCh,thisChunk.toString())) {
      thisChunk.append(thisCh);
      thisMarker++;
      if (thisMarker < s1.length())       thisCh=s1.charAt(thisMarker);
    }
    while ((thatMarker < s2.length()) && inChunk(thatCh,thatChunk.toString())) {
      thatChunk.append(thatCh);
      thatMarker++;
      if (thatMarker < s2.length())       thatCh=s2.charAt(thatMarker);
    }
    int thisChunkType=isIn(thisChunk.charAt(0),numbers) ? 1 : 0;
    int thatChunkType=isIn(thatChunk.charAt(0),numbers) ? 1 : 0;
    int result=0;
    if ((thisChunkType == 1) && (thatChunkType == 1)) {
      thisNumericChunk=Integer.parseInt(thisChunk.toString());
      thatNumericChunk=Integer.parseInt(thatChunk.toString());
      if (thisNumericChunk < thatNumericChunk)       result=-1;
      if (thisNumericChunk > thatNumericChunk)       result=1;
    }
 else {
      result=thisChunk.toString().compareTo(thatChunk.toString());
    }
    if (result != 0)     return result;
  }
  return 0;
}

Fixed version (ground truth):
public int compare(Object o1,Object o2){
  if (!(o1 instanceof String) || !(o2 instanceof String)) {
    return 0;
  }
  String s1=(String)o1;
  String s2=(String)o2;
  int thisMarker=0;
  int thisNumericChunk=0;
  int thatMarker=0;
  int thatNumericChunk=0;
  while ((thisMarker < s1.length()) && (thatMarker < s2.length())) {
    char thisCh=s1.charAt(thisMarker);
    char thatCh=s2.charAt(thatMarker);
    StringBuilder thisChunk=new StringBuilder();
    StringBuilder thatChunk=new StringBuilder();
    while ((thisMarker < s1.length()) && inChunk(thisCh,thisChunk.toString())) {
      thisChunk.append(thisCh);
      thisMarker++;
      if (thisMarker < s1.length())       thisCh=s1.charAt(thisMarker);
    }
    while ((thatMarker < s2.length()) && inChunk(thatCh,thatChunk.toString())) {
      thatChunk.append(thatCh);
      thatMarker++;
      if (thatMarker < s2.length())       thatCh=s2.charAt(thatMarker);
    }
    int thisChunkType=isIn(thisChunk.charAt(0),numbers) ? 1 : 0;
    int thatChunkType=isIn(thatChunk.charAt(0),numbers) ? 1 : 0;
    int result=0;
    if ((thisChunkType == 1) && (thatChunkType == 1)) {
      thisNumericChunk=Integer.parseInt(thisChunk.toString());
      thatNumericChunk=Integer.parseInt(thatChunk.toString());
      if (thisNumericChunk < thatNumericChunk)       result=-1;
      if (thisNumericChunk > thatNumericChunk)       result=1;
    }
 else {
      result=thisChunk.toString().compareTo(thatChunk.toString());
    }
    if (result != 0)     return result;
  }
  return new Integer(s1.length()).compareTo(s2.length());
}
Program: 152126
Project: 152126
Buggy source:
/** 
 * Creates new instance and install support.
 * @param frame main frame
 */
public UnifiedToolbarSupport(){
  this.frame=MainFrame.getInstance();
  final JToolBar toolbar=frame.getToolbar();
  toolbar.addMouseListener(this);
  toolbar.addMouseMotionListener(this);
  for (  Component c : toolbar.getComponents()) {
    if (c instanceof JButton) {
      JButton button=(JButton)c;
      button.setBorderPainted(false);
    }
  }
  SwingUtilities.invokeLater(new Runnable(){
    @Override public void run(){
      toolbar.setUI(new UnifiedToolbarUI());
      toolbar.invalidate();
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Creates new instance and install support.
 * @param frame main frame
 */
public UnifiedToolbarSupport(){
  this.frame=MainFrame.getInstance();
  frame.addWindowFocusListener(new WindowAdapter(){
    @Override public void windowGainedFocus(    WindowEvent e){
      frame.getToolbar().repaint();
    }
    @Override public void windowLostFocus(    WindowEvent e){
      frame.getToolbar().repaint();
    }
  }
);
  final JToolBar toolbar=frame.getToolbar();
  toolbar.setDoubleBuffered(true);
  toolbar.addMouseListener(this);
  toolbar.addMouseMotionListener(this);
  for (  Component c : toolbar.getComponents()) {
    if (c instanceof JButton) {
      JButton button=(JButton)c;
      button.setBorderPainted(false);
    }
  }
  SwingUtilities.invokeLater(new Runnable(){
    @Override public void run(){
      toolbar.setUI(new UnifiedToolbarUI());
      toolbar.invalidate();
    }
  }
);
}
Program: 152127
Project: 152127
Buggy source:
@Override public void activateGUI(){
  app.setEnabledAboutMenu(true);
  app.setEnabledPreferencesMenu(true);
  app.addApplicationListener(this);
  if (ThemeManager.isAquaCurrentLaF()) {
    MainFrame frame=MainFrame.getInstance();
    JMenuBar bar=frame.getJMenuBar();
    for (    Component menu : bar.getComponents()) {
      JMenu m=(JMenu)menu;
      m.setMnemonic(-1);
      m.setToolTipText(null);
      for (      Component c : m.getPopupMenu().getComponents()) {
        if (c instanceof JMenuItem) {
          JMenuItem i=(JMenuItem)c;
          i.setIcon(null);
          i.setMnemonic(-1);
          i.setToolTipText(null);
        }
 else         if (c instanceof JMenu) {
          JMenu jm=(JMenu)c;
          jm.setIcon(null);
          jm.setMnemonic(-1);
          jm.setToolTipText(null);
        }
      }
    }
    new UnifiedToolbarSupport();
    frame.getSMSPanel().setBackground(LEOPARD_PANEL_COLOR);
    frame.getContactPanel().setBackground(LEOPARD_PANEL_COLOR);
    frame.getQueuePanel().setBackground(LEOPARD_PANEL_COLOR);
    frame.getHorizontalSplitPane().setBackground(LEOPARD_PANEL_COLOR);
    frame.getVerticalSplitPane().setBackground(LEOPARD_PANEL_COLOR);
    frame.getStatusPanel().setBackground(LEOPARD_PANEL_COLOR);
    frame.getContentPane().setBackground(LEOPARD_PANEL_COLOR);
  }
}

Fixed version (ground truth):
@Override public void activateGUI(){
  app.setEnabledAboutMenu(true);
  app.setEnabledPreferencesMenu(true);
  app.addApplicationListener(this);
  if (ThemeManager.isAquaCurrentLaF()) {
    MainFrame frame=MainFrame.getInstance();
    JMenuBar bar=frame.getJMenuBar();
    for (    Component menu : bar.getComponents()) {
      JMenu m=(JMenu)menu;
      m.setMnemonic(-1);
      m.setToolTipText(null);
      for (      Component c : m.getPopupMenu().getComponents()) {
        if (c instanceof JMenuItem) {
          JMenuItem i=(JMenuItem)c;
          i.setIcon(null);
          i.setMnemonic(-1);
          i.setToolTipText(null);
        }
 else         if (c instanceof JMenu) {
          JMenu jm=(JMenu)c;
          jm.setIcon(null);
          jm.setMnemonic(-1);
          jm.setToolTipText(null);
        }
      }
    }
    new UnifiedToolbarSupport();
    frame.getSMSPanel().setBackground(LEOPARD_PANEL_COLOR);
    frame.getContactPanel().setBackground(LEOPARD_PANEL_COLOR);
    frame.getQueuePanel().setBackground(LEOPARD_PANEL_COLOR);
    frame.getHorizontalSplitPane().setBackground(LEOPARD_PANEL_COLOR);
    frame.getVerticalSplitPane().setBackground(LEOPARD_PANEL_COLOR);
    frame.getStatusPanel().setBackground(LEOPARD_PANEL_COLOR);
    frame.getContentPane().setBackground(LEOPARD_PANEL_COLOR);
    frame.getStatusPanel().setBorder(BorderFactory.createEmptyBorder(0,2,4,2));
  }
}
Program: 152128
Project: 152128
Buggy source:
@Override public void windowLostFocus(WindowEvent e){
  frame.getToolbar().repaint();
}

Fixed version (ground truth):
@Override public void windowLostFocus(WindowEvent e){
  frame.getToolbar().setBorder(inactiveBorder);
}
Program: 152129
Project: 152129
Buggy source:
public void paint(Graphics2D graphics2D,Component component,int width,int height){
  boolean focused=MainFrame.getInstance().isFocused();
  Color topColor=focused ? ACTIVE_TOP_GRADIENT_COLOR : INACTIVE_TOP_GRADIENT_COLOR;
  Color bottomColor=focused ? ACTIVE_BOTTOM_GRADIENT_COLOR : INACTIVE_BOTTOM_GRADIENT_COLOR;
  GradientPaint paint=new GradientPaint(0,1,topColor,0,height,bottomColor);
  graphics2D.setPaint(paint);
  graphics2D.fillRect(0,0,width,height);
}

Fixed version (ground truth):
public void paint(Graphics2D graphics2D,int width,int height){
  boolean focused=MainFrame.getInstance().isFocused();
  Color topColor=focused ? ACTIVE_TOP_GRADIENT_COLOR : INACTIVE_TOP_GRADIENT_COLOR;
  Color bottomColor=focused ? ACTIVE_BOTTOM_GRADIENT_COLOR : INACTIVE_BOTTOM_GRADIENT_COLOR;
  GradientPaint paint=new GradientPaint(0,1,topColor,0,height,bottomColor);
  graphics2D.setPaint(paint);
  graphics2D.fillRect(0,0,width,height);
}
Program: 152130
Project: 152130
Buggy source:
/** 
 * Creates new instance and install support.
 * @param frame main frame
 */
public UnifiedToolbarSupport(){
  this.frame=MainFrame.getInstance();
  frame.addWindowFocusListener(new WindowAdapter(){
    @Override public void windowGainedFocus(    WindowEvent e){
      frame.getToolbar().repaint();
    }
    @Override public void windowLostFocus(    WindowEvent e){
      frame.getToolbar().repaint();
    }
  }
);
  final JToolBar toolbar=frame.getToolbar();
  toolbar.setDoubleBuffered(true);
  toolbar.addMouseListener(this);
  toolbar.addMouseMotionListener(this);
  for (  Component c : toolbar.getComponents()) {
    if (c instanceof JButton) {
      JButton button=(JButton)c;
      button.setBorderPainted(false);
    }
  }
  SwingUtilities.invokeLater(new Runnable(){
    @Override public void run(){
      toolbar.setUI(new UnifiedToolbarUI());
      toolbar.invalidate();
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Creates new instance and install support.
 * @param frame main frame
 */
public UnifiedToolbarSupport(){
  this.frame=MainFrame.getInstance();
  frame.addWindowFocusListener(new UnifiedToolbarWindowAdapter());
  final JToolBar toolbar=frame.getToolbar();
  toolbar.setDoubleBuffered(true);
  toolbar.addMouseListener(this);
  toolbar.addMouseMotionListener(this);
  for (  Component c : toolbar.getComponents()) {
    if (c instanceof JButton) {
      JButton button=(JButton)c;
      button.setBorderPainted(false);
    }
  }
  SwingUtilities.invokeLater(new Runnable(){
    @Override public void run(){
      toolbar.setUI(new UnifiedToolbarUI());
      toolbar.invalidate();
    }
  }
);
}