[Demonstration 1]

[Buggy Method]
public boolean isActive(String username) {
    try {
        PreparedStatement stmt = con.prepareStatement(GET_USER_QUERY);
        stmt.setString(1, username);
        ResultSet rs = stmt.executeQuery();
        if (rs.next()) {
            return rs.getBoolean(ACTIVE);
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    return false;
}

[Buggy Hunk]
PreparedStatement stmt = con.prepareStatement(GET_USER_QUERY);

[Patch]
PreparedStatement stmt = con.prepareStatement(GET_USER_ACTIVE_QUERY);

[Demonstration 2]

[Buggy Method]
public void initNewGame() {
    Game game = new Game();
    Server server = new Server(4000, 3);
    ServerEventHandler serverEventHandler = new GameServerEventHandler(game);
    server.setServerEventHandler(serverEventHandler);
    server.start();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.submit(() -> {
        while (!Thread.interrupted()) {
            try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
                ObjectOutput out = new ObjectOutputStream(bos)) {
                out.writeInt(game.getPlayers().size());
                for (Player player : game.getPlayers()) {
                    out.writeObject(player);
                }
                out.flush();
                byte[] data = bos.toByteArray();
                server.sendDataToClients(data);
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
}

[Buggy Hunk]
ExecutorService executor = Executors.newSingleThreadExecutor();

[Patch]
ExecutorService executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory());

[Demonstration 3]

[Buggy Method]
public AConta Login(String Utilizador, String Password) {
    int i = 0;
    AConta res = null;
    Connection con = null;
    String Morador = null;
    String Senhorio = null;
    try {
        con = Connector.connect();
        PreparedStatement ps = con.prepareStatement("select Morador,Senhorio from conta where Username=? and Password=?");
        ps.setString(1, Utilizador);
        ps.setString(2, Password);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            Morador = rs.getString(1);
            Senhorio = rs.getString(2);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    try {
        if (Morador != null || Senhorio != null) {
            if (Morador != null) {
                PreparedStatement ps = con.prepareStatement("select Data,Removido from Morador where Nome=?");
                ps.setString(1, Morador);
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                    if (rs.getBoolean(2)) {
                        Date t = rs.getDate(1);
                        res = new SMorador(Utilizador, Password, t, Morador);
                    }
                }
            } else {
                PreparedStatement ps = con.prepareStatement("select Endereco from Senhorio where Nome=?");
                ps.setString(1, Senhorio);
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                    String endereco = rs.getString(1);
                    res = new SSenhorio(Utilizador, Password, endereco, Senhorio);
                }
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return res;
}

[Buggy Hunk]
if(rs.getBoolean(2))

[Patch]
if(!rs.getBoolean(2))