[Demonstration 1]

[Buggy Method]
synchronized private void grow() {
    int newCapacity = size * 2;
    newCapacity = newCapacity > MAX_SIZE ? MAX_SIZE : newCapacity;
    E[] target = (E[]) new Object[newCapacity];
    System.arraycopy(elements, 0, target, 0, size);
    elements = target;
}

[Buggy Hunk]
newCapacity = newCapacity > MAX_SIZE ? MAX_SIZE : newCapacity;

[Patch]
newCapacity = ( newCapacity > MAX_SIZE || newCapacity < size ) ? MAX_SIZE : newCapacity;

[Demonstration 2]

[Buggy Method]
private void ensureCapacity(int capacity) throws IOException {
    if (this.buffer.remaining() < capacity) {
        // Are we even able to satisfy this request?
        if (this.buffer.capacity() < capacity) {
            // 1.) Flush what is still buffered right now:
            this.out.write(this.buffer.array(), 0, this.buffer.position());
            // 2.) Reallocate the buffer:
            int requiredCapacity = this.buffer.array().length;
            while (requiredCapacity < capacity) {
                requiredCapacity *= 2;
            }
            byte[] newArray = new byte[requiredCapacity];
            this.buffer = ByteBuffer.wrap(newArray);
            this.buffer.position(0);
            this.buffer.limit(this.buffer.capacity());
            this.buffer.order(ByteOrder.BIG_ENDIAN);
        } else {
            // Flush out all data so far:
            this.flush();
        }
    }
}

[Buggy Hunk]
this.buffer.order( ByteOrder.BIG_ENDIAN );

[Patch]
this.buffer.order( order );

[Demonstration 3]

[Buggy Method]
public void login(String username, String password) throws FactivaExtractorWebHandlerException {
    try {
        WebElement usernameElement = driver.findElement(By.id("msu-id"));
        WebElement passwordElement = driver.findElement(By.id("password"));
        WebElement loginButton = driver.findElement(By.id("login-submit"));
        usernameElement.sendKeys(username);
        passwordElement.sendKeys(password);
        loginButton.click();
    } catch (ElementNotFoundException | NoSuchElementException ex) {
        throw new FactivaExtractorWebHandlerException("unable to find login fields or button");
    }
    // wait for factiva login page to load (wait a max of 20 seconds)
    boolean pageLoaded = false;
    int waitTime = 0;
    while (!pageLoaded && waitTime < 20000) {
        // wait 2 seconds
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        waitTime += 2000;
        try {
            // look for global nav container
            WebElement globalNavElement = driver.findElement(By.id("gl-navContainer"));
            if (globalNavElement != null && globalNavElement.isDisplayed()) {
                pageLoaded = true;
            }
        } catch (Throwable t) {
        }
    }
    if (!pageLoaded) {
        throw new FactivaExtractorWebHandlerException("timed out waiting for login to complete");
    }
}

[Buggy Hunk]
WebElement loginButton = driver.findElement(By.id("login-submit"));

[Patch]
WebElement loginButton = driver.findElement(By.className("msuit_brand_submit"));