Language: Java
Label: safe
CWE: CWE-89 \u2014 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.

Code:
    public void applyOffsetLimit(
            StringBuilder sql, @Nullable Integer offset, @Nullable Integer limit) {
        // some db's require limit to be present of offset is
        if (offset != null && limit == null) {
            limit = Integer.MAX_VALUE; // ensure we don't wrap around
        }
        if (limit != null && offset == null) {
            offset = 0;
            limit += 1; // not zero-based
        }
        if (offset != null && limit != null) {
            sql.insert(
                    0,
                    "SELECT * FROM (SELECT query.*, rownum rnum FROM ("
                            + (isDebugMode() ? "\n" : ""));
            sql.append(") query");
            appendIfDebug(sql, "\n", " ");
            if (limit != Integer.MAX_VALUE) {
                limit = offset + limit;
            }
            sql.append("WHERE rownum <= ").append(limit).append(")");
            appendIfDebug(sql, "\n", " ");
            sql.append("WHERE rnum > ").append(offset);
        }
    }