Program: 29423
Project: 29423
Buggy source:
/** 
 * Bind the specified value with the specified context attribute name, replacing any existing value for that name.
 * @param name Attribute name to be bound
 * @param value New attribute value to be bound
 */
@Override public void setAttribute(String name,Object value){
  if (name == null)   throw new IllegalArgumentException(sm.getString("String_Node_Str"));
  if (value == null) {
    removeAttribute(name);
    return;
  }
  Object oldValue=null;
  boolean replaced=false;
synchronized (attributes) {
    if (readOnlyAttributes.containsKey(name))     return;
    oldValue=attributes.get(name);
    if (oldValue != null)     replaced=true;
    attributes.put(name,value);
  }
  if (name.equals(Globals.CLASS_PATH_ATTR) || name.equals(Globals.JSP_TLD_URI_TO_LOCATION_MAP)) {
    setAttributeReadOnly(name);
  }
  List<EventListener> listeners=context.getApplicationEventListeners();
  if (listeners.isEmpty()) {
    return;
  }
  ServletContextAttributeEvent event=null;
  if (replaced) {
    event=new ServletContextAttributeEvent(context.getServletContext(),name,oldValue);
  }
 else {
    event=new ServletContextAttributeEvent(context.getServletContext(),name,value);
  }
  Iterator<EventListener> iter=listeners.iterator();
  while (iter.hasNext()) {
    EventListener eventListener=iter.next();
    if (!(eventListener instanceof ServletContextAttributeListener)) {
      continue;
    }
    ServletContextAttributeListener listener=(ServletContextAttributeListener)eventListener;
    try {
      if (replaced) {
        context.fireContainerEvent(ContainerEvent.BEFORE_CONTEXT_ATTRIBUTE_REPLACED,listener);
        listener.attributeReplaced(event);
        context.fireContainerEvent(ContainerEvent.AFTER_CONTEXT_ATTRIBUTE_REPLACED,listener);
      }
 else {
        context.fireContainerEvent(ContainerEvent.BEFORE_CONTEXT_ATTRIBUTE_ADDED,listener);
        listener.attributeAdded(event);
        context.fireContainerEvent(ContainerEvent.AFTER_CONTEXT_ATTRIBUTE_ADDED,listener);
      }
    }
 catch (    Throwable t) {
      if (replaced) {
        context.fireContainerEvent(ContainerEvent.AFTER_CONTEXT_ATTRIBUTE_REPLACED,listener);
      }
 else {
        context.fireContainerEvent(ContainerEvent.AFTER_CONTEXT_ATTRIBUTE_ADDED,listener);
      }
      log(sm.getString("String_Node_Str"),t);
    }
  }
}

Fixed version (ground truth):
/** 
 * Bind the specified value with the specified context attribute name, replacing any existing value for that name.
 * @param name Attribute name to be bound
 * @param value New attribute value to be bound
 */
@Override public void setAttribute(String name,Object value){
  if (name == null)   throw new IllegalArgumentException(sm.getString("String_Node_Str"));
  if (value == null) {
    removeAttribute(name);
    return;
  }
  Object oldValue=null;
  boolean replaced=false;
synchronized (attributesLock) {
    if (readOnlyAttributes.containsKey(name))     return;
    oldValue=attributes.get(name);
    if (oldValue != null)     replaced=true;
    attributes.put(name,value);
  }
  if (name.equals(Globals.CLASS_PATH_ATTR) || name.equals(Globals.JSP_TLD_URI_TO_LOCATION_MAP)) {
    setAttributeReadOnly(name);
  }
  List<EventListener> listeners=context.getApplicationEventListeners();
  if (listeners.isEmpty()) {
    return;
  }
  ServletContextAttributeEvent event=null;
  if (replaced) {
    event=new ServletContextAttributeEvent(context.getServletContext(),name,oldValue);
  }
 else {
    event=new ServletContextAttributeEvent(context.getServletContext(),name,value);
  }
  Iterator<EventListener> iter=listeners.iterator();
  while (iter.hasNext()) {
    EventListener eventListener=iter.next();
    if (!(eventListener instanceof ServletContextAttributeListener)) {
      continue;
    }
    ServletContextAttributeListener listener=(ServletContextAttributeListener)eventListener;
    try {
      if (replaced) {
        context.fireContainerEvent(ContainerEvent.BEFORE_CONTEXT_ATTRIBUTE_REPLACED,listener);
        listener.attributeReplaced(event);
        context.fireContainerEvent(ContainerEvent.AFTER_CONTEXT_ATTRIBUTE_REPLACED,listener);
      }
 else {
        context.fireContainerEvent(ContainerEvent.BEFORE_CONTEXT_ATTRIBUTE_ADDED,listener);
        listener.attributeAdded(event);
        context.fireContainerEvent(ContainerEvent.AFTER_CONTEXT_ATTRIBUTE_ADDED,listener);
      }
    }
 catch (    Throwable t) {
      if (replaced) {
        context.fireContainerEvent(ContainerEvent.AFTER_CONTEXT_ATTRIBUTE_REPLACED,listener);
      }
 else {
        context.fireContainerEvent(ContainerEvent.AFTER_CONTEXT_ATTRIBUTE_ADDED,listener);
      }
      log(sm.getString("String_Node_Str"),t);
    }
  }
}