{"record":{"id":"43bb03daced78068","repo":"prestodb/presto","slug":"max-field-size-must-be-positive","errorCode":null,"errorMessage":"Max field size must be positive","messagePattern":"Max field size must be positive","errorType":"validation","errorClass":"SQLException","httpStatus":null,"severity":"warning","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java","lineNumber":107,"sourceCode":"        connection.set(null);\n        closeResultSet();\n    }\n\n    @Override\n    public int getMaxFieldSize()\n            throws SQLException\n    {\n        checkOpen();\n        return 0;\n    }\n\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","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java#L89-L125","documentation":"JDBC's setMaxFieldSize limits the maximum bytes returned per field. Presto's driver always returns full values (the limit is ignored), but still validates the argument: a negative max is rejected with this SQLException before the no-op comment.","triggerScenarios":"Calling PrestoStatement.setMaxFieldSize with a negative integer, e.g. -1 used as a sentinel for 'unlimited'.","commonSituations":"Using -1 as an 'unbounded' sentinel (in this driver 0 is the correct unlimited value); uninitialized/default-negative int variables; porting code from drivers that tolerated negatives.","solutions":["Pass 0 (or a positive value) — in JDBC, 0 means no limit","Fix sentinel logic that uses -1 for unlimited","Check the value computed before passing it to setMaxFieldSize"],"exampleFix":"// before\nstmt.setMaxFieldSize(-1); // unlimited?\n// after\nstmt.setMaxFieldSize(0); // 0 = no limit","handlingStrategy":"validation","validationCode":"if (maxFieldSize < 0) {\n    throw new IllegalArgumentException(\"maxFieldSize must be >= 0 (0 = no limit), got \" + maxFieldSize);\n}\nstmt.setMaxFieldSize(maxFieldSize);","typeGuard":null,"tryCatchPattern":"try {\n    stmt.setMaxFieldSize(n);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Max field size must be positive\")) {\n        stmt.setMaxFieldSize(0); // fall back to unlimited\n    } else { throw e; }\n}","preventionTips":["Use 0, not -1, for 'unlimited' in JDBC setters","Never pass raw user input or uninitialized ints as field-size limits","Note Presto ignores this setting anyway — avoid relying on it for truncation"],"tags":["jdbc","statement","validation"],"backgroundTag":"jdbc-invalid-parameter","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"}