{"record":{"id":"b5dae4a0f1d3d07d","repo":"prestodb/presto","slug":"max-rows-exceeds-limit-of-2147483647","errorCode":null,"errorMessage":"Max rows exceeds limit of 2147483647","messagePattern":"Max rows exceeds limit of 2147483647","errorType":"validation","errorClass":"SQLException","httpStatus":null,"severity":"warning","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java","lineNumber":118,"sourceCode":"\n    @Override\n    public void setMaxFieldSize(int max)\n            throws SQLException\n    {\n        checkOpen();\n        if (max < 0) {\n            throw new SQLException(\"Max field size must be positive\");\n        }\n        // ignore: full values are always returned\n    }\n\n    @Override\n    public int getMaxRows()\n            throws SQLException\n    {\n        long result = getLargeMaxRows();\n        if (result > Integer.MAX_VALUE) {\n            throw new SQLException(\"Max rows exceeds limit of 2147483647\");\n        }\n        return toIntExact(result);\n    }\n\n    @Override\n    public long getLargeMaxRows()\n            throws SQLException\n    {\n        checkOpen();\n        return maxRows.get();\n    }\n\n    @Override\n    public void setMaxRows(int max)\n            throws SQLException\n    {\n        setLargeMaxRows(max);\n    }","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java#L100-L136","documentation":"getMaxRows() (the legacy int API) delegates to getLargeMaxRows() (a long) and throws this SQLException if the configured max-rows limit exceeds Integer.MAX_VALUE (2147483647), since it cannot be represented as an int. The large-rows JDBC 4.2 API has no such limit.","triggerScenarios":"Calling getMaxRows() after setLargeMaxRows was given a value > Integer.MAX_VALUE (e.g. Long.MAX_VALUE used to mean 'no limit'), or any code path that sets an oversized long limit then reads via the int API.","commonSituations":"Mixing JDBC 4.1 setMaxRows with JDBC 4.2 setLargeMaxRows; using Long.MAX_VALUE as an unbounded sentinel then calling the int getter; legacy framework code reading getMaxRows().","solutions":["Use getLargeMaxRows()/setLargeMaxRows() for limits above 2147483647","Keep max rows <= Integer.MAX_VALUE if the int API must be used","Avoid Long.MAX_VALUE as an 'unlimited' sentinel; use 0 if the driver supports it, or track 'unlimited' in your own code"],"exampleFix":"// before\nstmt.setLargeMaxRows(Long.MAX_VALUE);\nint m = stmt.getMaxRows(); // throws\n// after\nstmt.setLargeMaxRows(Long.MAX_VALUE);\nlong m = stmt.getLargeMaxRows();","handlingStrategy":"validation","validationCode":"long limit = stmt.getLargeMaxRows();\nif (limit > Integer.MAX_VALUE) {\n    // do not call the int API\n}\nint maxRows = (limit > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) limit;","typeGuard":"boolean fitsInt = (limit >= 0) && (limit <= (long) Integer.MAX_VALUE);","tryCatchPattern":"try {\n    int m = stmt.getMaxRows();\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Max rows exceeds limit\")) {\n        long m = stmt.getLargeMaxRows(); // use the long API\n    } else { throw e; }\n}","preventionTips":["Use the Large (JDBC 4.2) variants getLargeMaxRows/setLargeMaxRows consistently","Never set limits above Integer.MAX_VALUE if legacy int APIs are in use","Avoid Long.MAX_VALUE as an unbounded sentinel when mixing int/long APIs"],"tags":["jdbc","statement","overflow"],"backgroundTag":"integer-overflow","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}