[Demonstration 1]

[Buggy Method]
private Association createStandardAssociation(SnpAssociationForm snpAssociationForm) throws DataIntegrityException {
    Association association = new Association();
    // Set simple string and float association attributes
    association.setRiskFrequency(snpAssociationForm.getRiskFrequency());
    association.setPvalueText(snpAssociationForm.getPvalueText());
    association.setOrPerCopyNum(snpAssociationForm.getOrPerCopyNum());
    association.setOrType(snpAssociationForm.getOrType());
    association.setSnpType(snpAssociationForm.getSnpType());
    association.setMultiSnpHaplotype(snpAssociationForm.getMultiSnpHaplotype());
    association.setSnpInteraction(snpAssociationForm.getSnpInteraction());
    association.setPvalueMantissa(snpAssociationForm.getPvalueMantissa());
    association.setPvalueExponent(snpAssociationForm.getPvalueExponent());
    association.setOrPerCopyRecip(snpAssociationForm.getOrPerCopyRecip());
    association.setOrPerCopyStdError(snpAssociationForm.getOrPerCopyStdError());
    association.setOrPerCopyRange(snpAssociationForm.getOrPerCopyRange());
    association.setOrPerCopyUnitDescr(snpAssociationForm.getOrPerCopyUnitDescr());
    // Add collection of EFO traits
    association.setEfoTraits(snpAssociationForm.getEfoTraits());
    // Calculate float
    Integer pvalueMantissa = snpAssociationForm.getPvalueMantissa();
    Integer pvalueExponent = snpAssociationForm.getPvalueExponent();
    if (pvalueMantissa != null && pvalueExponent != null) {
        association.setPvalueFloat(associationCalculationService.calculatePvalueFloat(pvalueMantissa, pvalueExponent));
    }
    Collection<Locus> loci = new ArrayList<>();
    // Add loci to association or if we are editing an existing one find it
    // For multi-snp and standard snps we assume their is only one locus
    Locus locus = new Locus();
    if (association.getLoci() != null) {
        Association associationUserIsEditing = associationRepository.findOne(snpAssociationForm.getAssociationId());
        Collection<Locus> associationLoci = associationUserIsEditing.getLoci();
        for (Locus associationLocus : associationLoci) {
            locus = associationLocus;
        }
    }
    // Set locus description and haplotype count
    // Set this number to the number of rows entered by curator
    Integer numberOfRows = snpAssociationForm.getSnpFormRows().size();
    if (numberOfRows > 1) {
        locus.setHaplotypeSnpCount(numberOfRows);
        locus.setDescription(numberOfRows + "-SNP Haplotype");
    }
    // Create gene from each string entered, may sure to check pre-existence
    Collection<String> authorReportedGenes = snpAssociationForm.getAuthorReportedGenes();
    Collection<Gene> locusGenes = createGenes(authorReportedGenes);
    // Set locus attribute
    locus.setAuthorReportedGenes(locusGenes);
    // Handle rows entered for haplotype by curator
    Collection<SnpFormRow> rows = snpAssociationForm.getSnpFormRows();
    Collection<RiskAllele> locusRiskAlleles = new ArrayList<>();
    for (SnpFormRow row : rows) {
        // Create snps from row information
        String curatorEnteredSNP = row.getSnp();
        SingleNucleotidePolymorphism snp = createSnp(curatorEnteredSNP);
        // Get the curator entered risk allele
        String curatorEnteredRiskAllele = row.getStrongestRiskAllele();
        RiskAllele riskAllele = createRiskAllele(curatorEnteredRiskAllele);
        // For allele assign SNP if one isn't already present
        if (riskAllele.getSnp() == null) {
            riskAllele.setSnp(snp);
        } else {
            if (!riskAllele.getSnp().equals(snp)) {
                throw new DataIntegrityException("Risk allele: " + riskAllele.getRiskAlleleName() + " has SNP " + riskAllele.getSnp().getRsId() + " attached in database, cannot also add " + snp.getRsId());
            }
        }
        // Save changes to risk allele
        riskAlleleRepository.save(riskAllele);
        locusRiskAlleles.add(riskAllele);
    }
    // Assign all created risk alleles to locus
    locus.setStrongestRiskAlleles(locusRiskAlleles);
    // Save our newly created locus
    locusRepository.save(locus);
    // Add locus to collection and link to our repository
    loci.add(locus);
    association.setLoci(loci);
    return association;
}

[Buggy Hunk]
if(association.getLoci() != null){

[Patch]
if(!association.getLoci().isEmpty()){

[Demonstration 2]

[Buggy Method]
public int getId() {
    try {
        return (int) this.getClass().getField(FIELD_ID).get(this);
    } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
        throw new IllegalAccessError();
    }
}

[Buggy Hunk]
return (int) this.getClass().getField(FIELD_ID).get(this);

[Patch]
return (int) this.getClass().getDeclaredField(FIELD_ID).get(this);

[Demonstration 3]

[Buggy Method]
private List<Association> findLinkableAssociations(PersistentEntity persistentEntity) {
    final List<Association> result = newArrayList();
    persistentEntity.doWithAssociations(new SimpleAssociationHandler() {

        @Override
        public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
            if (associationLinks.isLinkableAssociation(association.getInverse())) {
                result.add(association);
            }
        }
    });
    return result;
}

[Buggy Hunk]
if (associationLinks.isLinkableAssociation(association.getInverse())) {

[Patch]
if (DynamicPersistentEntityResourceProcessor.this.association.isLinkableAssociation(association.getInverse())) {