[Demonstration 1]

[Buggy Method]
public List<JCRNodeWrapper> getAllPermissions() throws RepositoryException {
    if (allPermissions != null) {
        return allPermissions;
    }
    allPermissions = new ArrayList<JCRNodeWrapper>();
    JCRSessionWrapper currentUserSession = getSession();
    QueryManager qm = currentUserSession.getWorkspace().getQueryManager();
    String statement = "select * from [jnt:permission]";
    Query q = qm.createQuery(statement, Query.JCR_SQL2);
    NodeIterator ni = q.execute().getNodes();
    while (ni.hasNext()) {
        JCRNodeWrapper next = (JCRNodeWrapper) ni.next();
        int depth = 2;
        if (((JCRNodeWrapper) next.getAncestor(1)).isNodeType("jnt:modules")) {
            depth = 5;
            JahiaTemplatesPackage pack = templateManagerService.getTemplatePackageById(next.getAncestor(2).getName());
            if (pack == null || !pack.getVersion().toString().equals(next.getAncestor(3).getName())) {
                continue;
            }
        }
        if (next.getDepth() >= depth) {
            allPermissions.add(next);
        }
    }
    Collections.sort(allPermissions, new Comparator<JCRNodeWrapper>() {

        @Override
        public int compare(JCRNodeWrapper o1, JCRNodeWrapper o2) {
            if (getPermissionPath(o1).equals(getPermissionPath(o2))) {
                return -o1.getPath().compareTo(o2.getPath());
            }
            return getPermissionPath(o1).compareTo(getPermissionPath(o2));
        }
    });
    return allPermissions;
}

[Buggy Hunk]
return -o1.getPath().compareTo(o2.getPath());

[Patch]
return o2.getPath().compareTo(o1.getPath());

[Demonstration 2]

[Buggy Method]
public static final I18N getI18n(Class callerClass, String bundlePath) {
    return getI18n(callerClass, Locale.getDefault(), "i18n");
}

[Buggy Hunk]
return getI18n(callerClass, Locale.getDefault(), "i18n");

[Patch]
return getI18n(callerClass, Locale.getDefault(), bundlePath);

[Demonstration 3]

[Buggy Method]
private void importSaves() throws SQLException {
    Statement s = sConn.createStatement();
    ResultSet rs = s.executeQuery("SELECT name From sqlite_master WHERE type='table' AND name = 'BuildList'");
    boolean load = false;
    if (!rs.next()) {
        load = true;
    }
    s.close();
    if (load) {
        System.out.println("BuildList not found in save database, creating it");
        s = sConn.createStatement();
        s.execute("CREATE TABLE 'BuildList' ('weaponId' INTEGER, PRIMARY KEY(weaponId))");
        File saveFile = new File("save.txt");
        if (saveFile.exists()) {
            try {
                System.out.println("importing legacy save file into database");
                String sql = "SELECT Weapon.id, Weapon.local_name FROM Weapon WHERE ";
                boolean first = true;
                BufferedReader br = new BufferedReader(new FileReader(saveFile));
                while (br.ready()) {
                    String tmp = br.readLine();
                    if (tmp.equals(""))
                        continue;
                    if (first)
                        first = false;
                    else
                        sql += " OR ";
                    sql += "Weapon.local_name = '" + tmp + "'";
                }
                br.close();
                if (!first) {
                    System.out.println(sql);
                    Statement search = dConn.createStatement();
                    ResultSet searchResult = search.executeQuery(sql);
                    sql = "";
                    PreparedStatement ps = sConn.prepareStatement("INSERT INTO BuildList (weaponId) VALUES (?)");
                    while (searchResult.next()) {
                        ps.setInt(1, searchResult.getInt(1));
                        ps.executeUpdate();
                        //sql += "INSERT INTO BuildList (weaponId) VALUES (" + searchResult.getInt(1) + ");";
                    }
                    search.close();
                    ps.close();
                    //System.out.println(sql);
                    //s = sConn.createStatement();
                    //s.execute(sql);
                    s.close();
                }
                System.out.println("successfully converted save file");
            } catch (IOException e) {
                System.out.println("reading save file failed");
            }
        }
    }
}

[Buggy Hunk]
sql += "Weapon.local_name = '" + tmp + "'";

[Patch]
sql += "Weapon.local_name = '" + tmp.replace("'", "''") + "'";