[Demonstration 1]

[Buggy Method]
@Test(expected = IllegalArgumentException.class)
public void negativeTry() {
    assertNull(new RetryOptions(-1));
}

[Buggy Hunk]
assertNull(new RetryOptions(-1));

[Patch]
assertNull(new LoopRetryOptions(-1));

[Demonstration 2]

[Buggy Method]
protected List<Holding> uriPathToHoldings(String path, boolean mustBeAvailable) {
    List<Holding> holdings = new ArrayList<Holding>();
    String[] tuples = getPidsFromURL(path);
    for (String tuple : tuples) {
        String[] elements = tuple.split(properties.getProperty("prop_holdingSeparator", ":"));
        Record r = records.getRecordByPid(elements[0]);
        if (r == null) {
            // Try creating the record.
            try {
                r = records.createRecordByPid(elements[0]);
                records.addRecord(r);
            } catch (NoSuchPidException e) {
                return null;
            }
        } else {
            records.updateExternalInfo(r, false);
            records.saveRecord(r);
        }
        if (elements.length == 1) {
            Holding h = records.getHoldingForRecord(r, mustBeAvailable);
            if (h == null) {
                return null;
            }
            holdings.add(h);
        } else {
            for (int i = 1; i < elements.length; i++) {
                boolean has = false;
                for (Holding h : r.getHoldings()) {
                    if (h.getSignature().equals(elements[i])) {
                        holdings.add(h);
                        has = true;
                    }
                }
                if (!has) {
                    return null;
                }
            }
        }
    }
    return holdings;
}

[Buggy Hunk]
String[] elements = tuple.split(properties.getProperty("prop_holdingSeparator", ":"));

[Patch]
String[] elements = tuple.split(Pattern.quote(properties.getProperty("prop_holdingSeparator", ":")));

[Demonstration 3]

[Buggy Method]
@Test
public void whenSelectingACategoryNoMatterItsLinkableStatusThenReturnGoodResults() throws Exception {
    givenConfig(RMConfigs.LINKABLE_CATEGORY_MUST_NOT_BE_ROOT, true);
    givenConfig(RMConfigs.LINKABLE_CATEGORY_MUST_HAVE_APPROVED_RULES, true);
    waitForBatchProcess();
    Transaction tx = new Transaction();
    tx.add(rm.newCategoryWithId("rootCategoryWithoutChild").setCode("rootCategoryWithoutChild").setTitle("rootCategoryWithoutChild"));
    tx.add(rm.newCategoryWithId("rootCategoryWithChild").setCode("rootCategoryWithChild").setTitle("rootCategoryWithChild"));
    tx.add(rm.newCategoryWithId("childCategory").setCode("childCategory").setTitle("childCategory").setParent("rootCategoryWithChild"));
    tx.add(rm.newCategoryWithId("childChildCategory").setCode("childChildCategory").setTitle("childChildCategory").setParent("childCategory"));
    recordServices.execute(tx);
    TaxonomiesSearchOptions options = new TaxonomiesSearchOptions().setAlwaysReturnTaxonomyConceptsWithReadAccess(true);
    assertThatRootWhenSelectingACategoryUsingPlanTaxonomy(options).has(numFoundAndListSize(4)).has(unlinkable(records.categoryId_X, records.categoryId_Z)).has(resultsInOrder("rootCategoryWithChild", "rootCategoryWithoutChild", records.categoryId_X, records.categoryId_Z)).has(itemsWithChildren("rootCategoryWithChild", records.categoryId_X, records.categoryId_Z));
    assertThatChildWhenSelectingACategoryUsingPlanTaxonomy("rootCategoryWithChild", options).has(numFoundAndListSize(1)).has(resultsInOrder("childCategory")).has(itemsWithChildren("childCategory")).has(linkable("childCategory"));
    assertThatChildWhenSelectingACategoryUsingPlanTaxonomy("childCategory", options).has(numFoundAndListSize(1)).has(resultsInOrder("childChildCategory")).has(noItemsWithChildren()).has(linkable("childChildCategory"));
    assertThatChildWhenSelectingACategoryUsingPlanTaxonomy(records.categoryId_Z, options).has(numFoundAndListSize(4)).has(resultsInOrder(records.categoryId_Z100, records.categoryId_Z200, records.categoryId_Z999, records.categoryId_ZE42)).has(itemsWithChildren(records.categoryId_Z100)).has(linkable(records.categoryId_Z100, records.categoryId_Z200, records.categoryId_Z999, records.categoryId_ZE42));
    assertThatChildWhenSelectingACategoryUsingPlanTaxonomy(records.categoryId_Z100, options).has(resultsInOrder(records.categoryId_Z110, records.categoryId_Z120)).has(itemsWithChildren(records.categoryId_Z110)).has(numFoundAndListSize(2)).has(linkable(records.categoryId_Z110));
    assertThatChildWhenSelectingACategoryUsingPlanTaxonomy(records.categoryId_Z112, options).is(empty());
}

[Buggy Hunk]
.has(unlinkable(records.categoryId_X, records.categoryId_Z))

[Patch]
.has(linkable("rootCategoryWithChild", "rootCategoryWithoutChild", records.categoryId_X, records.categoryId_Z))