[Demonstration 1]

[Buggy Method]
List<String> consume() throws IOException {
    List<String> comments = new ArrayList<>();
    int capacity = 32;
    while (!reader.eof() && reader.peek() == commentStart) {
        reader.next();
        StringBuilder comment = new StringBuilder(capacity);
        reader.readLine(comment, limiter);
        capacity = Util.clamp(capacity, comment.length(), 1024);
        comments.add(comment.toString());
        reader.skipLineBreakAndSoftEof();
    }
    if (comments.isEmpty())
        comments = Collections.emptyList();
    return comments;
}

[Buggy Hunk]
capacity = Util.clamp( capacity, comment.length(), 1024 );

[Patch]
capacity = Math.min( Math.max( capacity, comment.length() ), 1024 );

[Demonstration 2]

[Buggy Method]
private String getQuotedString() {
    allowWhiteSpaceAndComments();
    char c = requireQuote();
    int start = i;
    StringBuilder alternative = new StringBuilder();
    int lastStop = i;
    do {
        if (peek('\\')) {
            alternative.append(src.substring(lastStop, i));
            char escapedChar = requireEscapedChar();
            if (escapedChar == 'u') {
                int hexStart = i;
                requireFourHex();
                alternative.append(convertedUnicodeString(src.substring(hexStart, i - 1)));
            } else {
                alternative.append(convertEscapedChar(escapedChar));
            }
            lastStop = i;
        }
    } while (next() != c);
    if (alternative.length() > 0) {
        alternative.append(src.substring(lastStop, i - 1));
        return alternative.toString();
    } else {
        return src.substring(start, i - 1);
    }
}

[Buggy Hunk]
alternative.append(convertedUnicodeString(src.substring(hexStart, i-1)));

[Patch]
alternative.append(convertedUnicodeString(src.substring(hexStart, i)));

[Demonstration 3]

[Buggy Method]
public String readLocationString(XMLStreamReader reader) throws XMLStreamException {
    boolean found = checkElementName(reader, "LocationString");
    if (!found)
        throw new XMLStreamException(ERROR_INVALID_ELT + reader.getName() + errorLocationString(reader));
    return reader.getElementText();
}

[Buggy Hunk]
return reader.getElementText();

[Patch]
return trimStringValue(reader.getElementText());