[Demonstration 1]

[Buggy Method]
public static String getContactPath(int contact_id) {
    return ONE_CONTACT_NO_ID + contact_id + "/";
}

[Buggy Hunk]
return ONE_CONTACT_NO_ID+contact_id+"/";

[Patch]
return ONE_CONTACT.replace(":contact_id", new Integer(contact_id).toString());

[Demonstration 2]

[Buggy Method]
private void _runTest(final int NUM_ITEMS, final long pContentLength, final MockHttpServletRequest request) throws FileUploadException, IOException {
    final ServletFileUpload upload = new ServletFileUpload(null);
    final ProgressListenerImpl listener = new ProgressListenerImpl(pContentLength, NUM_ITEMS);
    upload.setProgressListener(listener);
    final IFileItemIterator iter = upload.getItemIterator(request);
    for (int i = 0; i < NUM_ITEMS; i++) {
        final IFileItemStream stream = iter.next();
        final InputStream istream = stream.openStream();
        for (int j = 0; j < 16384 + i; j++) {
            /**
             * This used to be assertEquals((byte) j, (byte) istream.read()); but
             * this seems to trigger a bug in JRockit, so we express the same like
             * this:
             */
            final byte b1 = (byte) j;
            final byte b2 = (byte) istream.read();
            if (b1 != b2) {
                fail("Expected " + b1 + ", got " + b2);
            }
        }
        assertEquals(-1, istream.read());
    }
    assertFalse(iter.hasNext());
    listener._checkFinished();
}

[Buggy Hunk]
final ServletFileUpload upload = new ServletFileUpload (null);

[Patch]
final ServletFileUpload upload = new ServletFileUpload (new DiskFileItemFactory (CGlobal.BYTES_PER_MEGABYTE, null));

[Demonstration 3]

[Buggy Method]
@When("^I query for the role \"(.+)\" in scope (\\d+)$")
public void queryForRoleInScope(String name, Integer scope) throws KapuaException {
    KapuaId tmpId = null;
    assertNotNull(scope);
    tmpId = new KapuaEid(BigInteger.valueOf(scope));
    assertNotNull(tmpId);
    assertNotNull(name);
    assertNotEquals(0, name.length());
    final RoleQuery tmpQuery = roleFactory.newQuery(tmpId);
    tmpQuery.setPredicate(new AttributePredicate<String>(RolePredicates.ROLE_NAME, name));
    KapuaSecurityUtils.doPrivileged(() -> {
        roleList = roleService.query(tmpQuery);
        return null;
    });
    assertNotNull(roleList);
    if (roleList.getSize() > 1) {
        fail("Query returned too many results!");
    }
    if (!roleList.isEmpty()) {
        roleFound = roleList.getFirstItem();
    }
    this.count = roleList.getSize();
}

[Buggy Hunk]
tmpQuery.setPredicate(new AttributePredicate<String>(RolePredicates.ROLE_NAME, name));

[Patch]
tmpQuery.setPredicate(new AttributePredicate<String>(RolePredicates.NAME, name));