[Demonstration 1]

[Buggy Method]
public static String cleanupDeviceBrandName(String deviceBrand, String deviceName) {
    String lowerDeviceBrand = deviceBrand.toLowerCase(Locale.ENGLISH);
    deviceName = deviceName.replaceAll("_", " ");
    deviceName = deviceName.replaceAll("- +", "-");
    deviceName = deviceName.replaceAll(" +-", "-");
    deviceName = deviceName.replaceAll(" +", " ");
    String lowerDeviceName = deviceName.toLowerCase(Locale.ENGLISH);
    // In some cases it does start with the brand but without a separator following the brand
    if (lowerDeviceName.startsWith(lowerDeviceBrand)) {
        deviceName = deviceName.replaceAll("_", " ");
        // (?i) means: case insensitive
        deviceName = deviceName.replaceAll("(?i)^" + Pattern.quote(deviceBrand) + "([^ ].*)$", deviceBrand + " $1");
        deviceName = deviceName.replaceAll("( -| )+", " ");
    } else {
        deviceName = deviceBrand + ' ' + deviceName;
    }
    String result = Normalize.brand(deviceName);
    if (result.contains("I")) {
        result = result.replace("Ipad", "iPad").replace("Ipod", "iPod").replace("Iphone", "iPhone").replace("IOS ", "iOS ");
    }
    return result;
}

[Buggy Hunk]
deviceName = deviceName.replaceAll("(?i)^" + Pattern.quote(deviceBrand) + "([^ ].*)$", deviceBrand+" $1");

[Patch]
deviceName = deviceName.replaceAll("(?i)^" + Pattern.quote(deviceBrand) + "([^ ].*)$", Matcher.quoteReplacement(deviceBrand)+" $1");

[Demonstration 2]

[Buggy Method]
@Override
public void runTool(CommandLine line) throws Exception {
    startSpring();
    logger.info("Starting app audit");
    // TODO TN use row iterator to fix this!
    Map<String, UUID> apps = emf.getApplications();
    // OrgRepo repo = new OrgRepo();
    Set<String> allOrgs = new HashSet<String>();
    // Set<String> foundApps = new HashSet<String>();
    for (Entry<String, UUID> entry : apps.entrySet()) {
        logger.info("Name: {}, Id: {}", entry.getKey(), entry.getValue());
        // repo.putData(entry.getKey(), entry.getValue());
        String[] parts = entry.getKey().split("/");
        allOrgs.add(parts[0]);
        // foundApps.add(entry.getKey());
    }
    Set<String> collectionOrgs = new HashSet<String>(allOrgs);
    Set<String> aliasedOrgs = new HashSet<String>(allOrgs);
    EntityManager em = emf.getEntityManager(emf.getManagementAppId());
    // search for all orgs
    EntityRef rootAppRef = new SimpleEntityRef("application", emf.getManagementAppId());
    Query query = new Query();
    query.setLimit(PAGE_SIZE);
    Results r = null;
    do {
        r = em.searchCollection(rootAppRef, "groups", query);
        for (Entity entity : r.getEntities()) {
            collectionOrgs.remove(entity.getProperty("path"));
        }
        query.setCursor(r.getCursor());
    } while (r != null && r.size() == PAGE_SIZE);
    for (String orgName : allOrgs) {
        EntityRef group = em.getAlias("group", orgName);
        if (group != null) {
            aliasedOrgs.remove(orgName);
        }
    }
    // now dump what we couldn't find!
    for (String orgName : collectionOrgs) {
        logger.info("Cound not find in collection groups.  Org : {}", orgName);
    }
    for (String orgName : aliasedOrgs) {
        logger.info("Cound not find in alias.  Org : {}", orgName);
    }
}

[Buggy Hunk]
collectionOrgs.remove( entity.getProperty( "path" ) );

[Patch]
collectionOrgs.remove( entity.getProperty( "path" ).toString() );

[Demonstration 3]

[Buggy Method]
private static String format(String format) {
    return I18n.format(format);
}

[Buggy Hunk]
private static String format(String format)

[Patch]
private String format(String format)