[Demonstration 1]

[Buggy Method]
private void restoreFromLocalCopy(String fileName, VagvalAgentProcessingLog processingLog) {
    PersistentCache pc = null;
    InputStream is = null;
    final File file = new File(fileName);
    try {
        if (file.exists()) {
            logger.info("Restore virtualizations and permissions from local TAK copy: {}", fileName);
            is = new FileInputStream(file);
            pc = (PersistentCache) JAXB.unmarshal(is);
            processingLog.addLog("Succesfully restored virtualizations and permissions from local TAK copy: " + fileName);
        } else {
            logger.error("Failed to find following file containing local TAK copy: {}", fileName);
            processingLog.addLog("Failed to find following file containing local TAK copy: " + fileName);
        }
    } catch (Exception e) {
        logger.error("Failed to restore virtualizations and permissions from local TAK copy: {}", fileName, e);
        processingLog.addLog("Failed to restore virtualizations and permissions from local TAK copy: " + fileName);
        processingLog.addLog("Reason for failure: " + e.getMessage());
        // remove erroneous file.
        if (is != null) {
            file.delete();
        }
    } finally {
        close(is);
    }
    if (pc != null && pc.anropsBehorighetsInfo != null && pc.virtualiseringsInfo != null) {
        setState(pc.virtualiseringsInfo, pc.anropsBehorighetsInfo);
    }
}

[Buggy Hunk]
setState(pc.virtualiseringsInfo, pc.anropsBehorighetsInfo);

[Patch]
updateTakCache(pc.virtualiseringsInfo, pc.anropsBehorighetsInfo);

[Demonstration 2]

[Buggy Method]
public synchronized void addWork(String playerName, Workload workload) {
    log.info("Work is being added...");
    if (!userWorkMap.containsKey(playerName)) {
        userWorkMap.put(playerName, nextIndex);
        workList.add(new Workload());
        workArchive.put(playerName, new Stack<Workload>());
        nextIndex++;
    }
    int index = userWorkMap.get(playerName);
    workList.get(index).addAll(workload);
    workArchive.get(playerName).add((new Workload(workload)).setAsUndoWork());
    this.notifyAll();
}

[Buggy Hunk]
log.info("Work is being added...");

[Patch]
log.debug("Work is being added...");

[Demonstration 3]

[Buggy Method]
public synchronized Connection getConnection() {
    Connection conn = null;
    // 判断：目前连接池中是否还有空闲的连接数
    if (freeConnections != null && freeConnections.size() > 0) {
        // 获取到第一个元素，并删除
        conn = freeConnections.remove();
        // 判断：链接是否可用
        try {
            if (conn.isClosed()) {
                System.out.println("移除了一个不可用的链接");
                // 获取下一个链接
                avtive_num--;
                conn = getConnection();
            }
        } catch (SQLException e) {
            // e.printStackTrace();
            System.out.println("移除了一个不可用的链接");
            // 获取下一个链接
            avtive_num--;
            conn = getConnection();
        }
        free_num--;
        avtive_num++;
    } else /*
		 * 判断：目前连接池中已经没有空闲的链接 当前正忙的连接数是否已经达到数据库连接池的最大值，如果没有达到最大值
		 * 1）、可以初始化一批链接，放到连接池中 2）、可以初始化一个链接，放到连接池中--
		 */
    if (avtive_num < MAX_CONN) {
        // 获取一个新链接，存放到连接池
        conn = newConnection();
        avtive_num++;
    } else // 当前正忙的连接数已经超过了 连接池的最大容量
    {
        //
        System.out.println("目前已经达到最大连接数，请等待....");
    }
    return conn;
}

[Buggy Hunk]
if (conn.isClosed()) {

[Patch]
if (conn.isClosed() || !conn.isValid(0) ) {