Program: 30369
Project: 30369
Buggy source:
public void writeSessions(OutputStream os,boolean doExpire) throws IOException {
  ObjectOutputStream oos=null;
  try {
    if (container != null) {
      oos=((StandardContext)container).createObjectOutputStream(new BufferedOutputStream(os));
    }
 else {
      oos=new ObjectOutputStream(new BufferedOutputStream(os));
    }
  }
 catch (  IOException e) {
    log.log(Level.SEVERE,sm.getString("String_Node_Str",e),e);
    if (oos != null) {
      try {
        oos.close();
      }
 catch (      IOException f) {
      }
      oos=null;
    }
    throw e;
  }
  ArrayList<StandardSession> list=new ArrayList<StandardSession>();
synchronized (sessions) {
    if (log.isLoggable(Level.FINE))     log.fine("String_Node_Str" + sessions.size() + "String_Node_Str");
    try {
      Session actSessions[]=findSessions();
      if (actSessions != null) {
        for (        Session actSession : actSessions) {
          StandardSession session=(StandardSession)actSession;
          session.passivate();
        }
      }
      oos.writeObject(Integer.valueOf(sessions.size()));
      for (      Session o : sessions.values()) {
        StandardSession session=(StandardSession)o;
        list.add(session);
        oos.writeObject(session);
      }
    }
 catch (    IOException e) {
      log.log(Level.SEVERE,sm.getString("String_Node_Str",e),e);
      if (oos != null) {
        try {
          oos.close();
        }
 catch (        IOException f) {
        }
        oos=null;
      }
      throw e;
    }
  }
  try {
    oos.flush();
  }
 catch (  IOException e) {
    if (oos != null) {
      try {
        oos.close();
      }
 catch (      IOException f) {
      }
      oos=null;
    }
    throw e;
  }
 finally {
    try {
      if (oos != null) {
        oos.close();
      }
    }
 catch (    IOException f) {
    }
  }
  if (doExpire) {
    if (log.isLoggable(Level.FINE))     log.fine("String_Node_Str" + list.size() + "String_Node_Str");
    Iterator<StandardSession> expires=list.iterator();
    while (expires.hasNext()) {
      StandardSession session=(StandardSession)expires.next();
      try {
        session.expire(false);
      }
 catch (      Throwable t) {
      }
    }
  }
}

Fixed version (ground truth):
public void writeSessions(OutputStream os,boolean doExpire) throws IOException {
  ObjectOutputStream oos=null;
  try {
    if (container != null) {
      oos=((StandardContext)container).createObjectOutputStream(new BufferedOutputStream(os));
    }
 else {
      oos=new ObjectOutputStream(new BufferedOutputStream(os));
    }
  }
 catch (  IOException e) {
    log.log(Level.SEVERE,sm.getString("String_Node_Str",e),e);
    if (oos != null) {
      try {
        oos.close();
      }
 catch (      IOException f) {
      }
      oos=null;
    }
    throw e;
  }
  StandardSession[] currentStandardSessions=null;
synchronized (sessions) {
    if (log.isLoggable(Level.FINE))     log.fine("String_Node_Str" + sessions.size() + "String_Node_Str");
    try {
      for (      Session actSession : findSessions()) {
        StandardSession session=(StandardSession)actSession;
        session.passivate();
      }
      Session[] currentSessions=findSessions();
      int size=currentSessions.length;
      currentStandardSessions=new StandardSession[size];
      oos.writeObject(Integer.valueOf(size));
      for (int i=0; i < size; i++) {
        StandardSession session=(StandardSession)currentSessions[i];
        currentStandardSessions[i]=session;
        oos.writeObject(session);
      }
    }
 catch (    IOException e) {
      log.log(Level.SEVERE,sm.getString("String_Node_Str",e),e);
      if (oos != null) {
        try {
          oos.close();
        }
 catch (        IOException f) {
        }
        oos=null;
      }
      throw e;
    }
  }
  try {
    oos.flush();
  }
 catch (  IOException e) {
    if (oos != null) {
      try {
        oos.close();
      }
 catch (      IOException f) {
      }
      oos=null;
    }
    throw e;
  }
 finally {
    try {
      if (oos != null) {
        oos.close();
      }
    }
 catch (    IOException f) {
    }
  }
  if (doExpire) {
    if (log.isLoggable(Level.FINE))     log.fine("String_Node_Str" + currentStandardSessions.length + "String_Node_Str");
    for (    StandardSession session : currentStandardSessions) {
      try {
        session.expire(false);
      }
 catch (      Throwable t) {
      }
    }
  }
}