[Demonstration 1]

[Buggy Method]
@Override
public AppCatalogResource get(Object identifier) throws AppCatalogException {
    HashMap<String, String> ids;
    if (identifier instanceof Map) {
        ids = (HashMap<String, String>) identifier;
    } else {
        logger.error("Identifier should be a map with the field name and it's value");
        throw new AppCatalogException("Identifier should be a map with the field name and it's value");
    }
    EntityManager em = null;
    try {
        em = AppCatalogJPAUtils.getEntityManager();
        em.getTransaction().begin();
        AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(DATA_MOVEMENT_INTERFACE);
        generator.setParameter(StorageInterfaceConstants.STORAGE_RESOURCE_ID, ids.get(StorageInterfaceConstants.STORAGE_RESOURCE_ID));
        generator.setParameter(StorageInterfaceConstants.DATA_MOVEMENT_ID, ids.get(StorageInterfaceConstants.DATA_MOVEMENT_ID));
        Query q = generator.selectQuery(em);
        StorageInterface storageInterface = (StorageInterface) q.getSingleResult();
        StorageInterfaceResource storageInterfaceResource = (StorageInterfaceResource) AppCatalogJPAUtils.getResource(AppCatalogResourceType.STORAGE_INTERFACE, storageInterface);
        em.getTransaction().commit();
        if (em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
        return storageInterfaceResource;
    } catch (ApplicationSettingsException e) {
        logger.error(e.getMessage(), e);
        throw new AppCatalogException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}

[Buggy Hunk]
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(DATA_MOVEMENT_INTERFACE);

[Patch]
AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(STORAGE_INTERFACE);

[Demonstration 2]

[Buggy Method]
private InternetAddress toNormalizedAddress(String address) throws UnsupportedEncodingException {
    if (address == null) {
        return null;
    }
    // if not a valid address (i.e. no '@'), then try adding suffix
    if (!address.contains("@")) {
        if (defaultSuffix != null && defaultSuffix.contains("@")) {
            address += defaultSuffix;
        } else {
            return null;
        }
    }
    try {
        return Mailer.StringToAddress(address, charset);
    } catch (AddressException e) {
        // report bad address, but try to send to other addresses
        logError("Unable to send to address: " + address, e);
        return null;
    }
}

[Buggy Hunk]
return Mailer.StringToAddress(address, charset);

[Patch]
return Mailer.stringToAddress(address, charset);

[Demonstration 3]

[Buggy Method]
@Test
public void shouldCompleteSuccessfully() throws Exception {
    PlatformTransactionManager transactionManager = createNonFailingTransactionManager("single");
    setupTransactionManagers(transactionManager);
    createAndCommitTransaction();
    assertThat(transactionManager, isCommitted());
}

[Buggy Hunk]
public void shouldCompleteSuccessfully() throws Exception {

[Patch]
public void shouldCompleteSuccessfully() {