Program: 30015
Project: 30015
Buggy source:
private void handleAfterEvent(InstanceEvent event,InstanceEvent.EventType eventType){
  Wrapper wrapper=event.getWrapper();
  Context context=(Context)wrapper.getParent();
  if (!(context instanceof WebModule)) {
    return;
  }
  WebModule wm=(WebModule)context;
  Object instance;
  if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT) {
    instance=event.getFilter();
  }
 else {
    instance=event.getServlet();
  }
  if (instance == null) {
    return;
  }
  if (instance instanceof Servlet) {
    if (eventType == InstanceEvent.EventType.AFTER_INIT_EVENT) {
      wm.servletInitializedEvent(wrapper.getName());
    }
 else     if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
      wm.servletDestroyedEvent(wrapper.getName());
    }
  }
  try {
    if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT && !DefaultServlet.class.equals(instance.getClass()) && !JspServlet.class.equals(instance.getClass())) {
      injectionMgr.destroyManagedObject(instance,false);
    }
  }
 catch (  InjectionException ie) {
    String msg=_rb.getString("String_Node_Str");
    msg=MessageFormat.format(msg,new Object[]{eventType,wm});
    _logger.log(Level.SEVERE,msg,ie);
  }
  ComponentInvocation inv=new WebComponentInvocation(wm,instance);
  try {
    im.postInvoke(inv);
  }
 catch (  Exception ex) {
    String msg=_rb.getString("String_Node_Str");
    msg=MessageFormat.format(msg,new Object[]{eventType,wm});
    throw new RuntimeException(msg,ex);
  }
 finally {
    if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
      tm.componentDestroyed(instance,inv);
    }
 else     if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT || eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
      if (eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
        ServletResponse response=event.getResponse();
        int status=-1;
        if (response != null && response instanceof HttpServletResponse) {
          status=((HttpServletResponse)response).getStatus();
        }
        wm.afterServiceEvent(wrapper.getName(),status);
      }
      if (im.getCurrentInvocation() == null) {
        try {
          Realm ra=context.getRealm();
          if (ra != null && (ra instanceof RealmInitializer)) {
            ((RealmInitializer)ra).logout();
          }
        }
 catch (        Exception ex) {
          String msg=_rb.getString("String_Node_Str");
          msg=MessageFormat.format(msg,new Object[]{eventType,wm});
          _logger.log(Level.SEVERE,msg,ex);
        }
        try {
          if (tm.getTransaction() != null) {
            tm.rollback();
          }
          tm.cleanTxnTimeout();
        }
 catch (        Exception ex) {
        }
      }
      tm.componentDestroyed(instance,inv);
    }
  }
}

Fixed version (ground truth):
private void handleAfterEvent(InstanceEvent event,InstanceEvent.EventType eventType){
  Wrapper wrapper=event.getWrapper();
  Context context=(Context)wrapper.getParent();
  if (!(context instanceof WebModule)) {
    return;
  }
  WebModule wm=(WebModule)context;
  Object instance;
  if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT) {
    instance=event.getFilter();
  }
 else {
    instance=event.getServlet();
  }
  if (instance == null) {
    return;
  }
  if (instance instanceof Servlet) {
    if (eventType == InstanceEvent.EventType.AFTER_INIT_EVENT) {
      wm.servletInitializedEvent(wrapper.getName());
    }
 else     if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
      wm.servletDestroyedEvent(wrapper.getName());
    }
  }
  try {
    if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT && !DefaultServlet.class.equals(instance.getClass()) && !JspServlet.class.equals(instance.getClass())) {
      injectionMgr.destroyManagedObject(instance,false);
    }
  }
 catch (  InjectionException ie) {
    String msg=_rb.getString("String_Node_Str");
    msg=MessageFormat.format(msg,new Object[]{eventType,wm});
    _logger.log(Level.SEVERE,msg,ie);
  }
  ComponentInvocation inv=new WebComponentInvocation(wm,instance);
  try {
    im.postInvoke(inv);
  }
 catch (  Exception ex) {
    String msg=_rb.getString("String_Node_Str");
    msg=MessageFormat.format(msg,new Object[]{eventType,wm});
    throw new RuntimeException(msg,ex);
  }
 finally {
    if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
      if (tm != null) {
        tm.componentDestroyed(instance,inv);
      }
    }
 else     if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT || eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
      if (eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
        ServletResponse response=event.getResponse();
        int status=-1;
        if (response != null && response instanceof HttpServletResponse) {
          status=((HttpServletResponse)response).getStatus();
        }
        wm.afterServiceEvent(wrapper.getName(),status);
      }
      if (im.getCurrentInvocation() == null) {
        try {
          Realm ra=context.getRealm();
          if (ra != null && (ra instanceof RealmInitializer)) {
            ((RealmInitializer)ra).logout();
          }
        }
 catch (        Exception ex) {
          String msg=_rb.getString("String_Node_Str");
          msg=MessageFormat.format(msg,new Object[]{eventType,wm});
          _logger.log(Level.SEVERE,msg,ex);
        }
        if (tm != null) {
          try {
            if (tm.getTransaction() != null) {
              tm.rollback();
            }
            tm.cleanTxnTimeout();
          }
 catch (          Exception ex) {
          }
        }
      }
      if (tm != null) {
        tm.componentDestroyed(instance,inv);
      }
    }
  }
}