{"record":{"id":"2d92278479e8e240","repo":"prestodb/presto","slug":"timeout-is-negative","errorCode":null,"errorMessage":"Timeout is negative","messagePattern":"Timeout is negative","errorType":"validation","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoConnection.java","lineNumber":534,"sourceCode":"    public NClob createNClob()\n            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"createNClob\");\n    }\n\n    @Override\n    public SQLXML createSQLXML()\n            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"createSQLXML\");\n    }\n\n    @Override\n    public boolean isValid(int timeout)\n            throws SQLException\n    {\n        if (timeout < 0) {\n            throw new SQLException(\"Timeout is negative\");\n        }\n        return !isClosed();\n    }\n\n    @Override\n    public void setClientInfo(String name, String value)\n            throws SQLClientInfoException\n    {\n        requireNonNull(name, \"name is null\");\n        if (value != null) {\n            clientInfo.put(name, value);\n        }\n        else {\n            clientInfo.remove(name);\n        }\n    }\n\n    @Override","sourceCodeStart":516,"sourceCodeEnd":552,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoConnection.java#L516-L552","documentation":"isValid(int) throws SQLException(\"Timeout is negative\") when the timeout argument is below zero. This matches the JDBC specification, where 0 means no timeout and negative values are invalid. The check runs before any connection-state inspection, so no network I/O occurs.","triggerScenarios":"Calling connection.isValid(-1); passing user/config-supplied values without validation; computing a remaining timeout from a deadline that has already expired (deadline - now < 0).","commonSituations":"Connection pools configured with negative validation timeouts; watchdog code that subtracts timestamps and forwards the result directly to isValid.","solutions":["Pass a timeout >= 0; use 0 to skip the timeout","Clamp with Math.max(0, timeout) before calling","Treat an already-expired deadline as a failed validation instead of calling isValid with the negative remainder"],"exampleFix":"// before\nboolean ok = connection.isValid(timeout);\n// after\nboolean ok = connection.isValid(Math.max(0, timeout));","handlingStrategy":"validation","validationCode":"if (timeout < 0) {\n    throw new IllegalArgumentException(\"timeout must be >= 0, got \" + timeout);\n}\nboolean ok = connection.isValid(timeout);","typeGuard":"static boolean nonNegativeTimeout(int timeout) {\n    return timeout >= 0;\n}","tryCatchPattern":null,"preventionTips":["Clamp computed timeouts with Math.max(0, timeout) before isValid","Validate pool 'connectionTestQuery/timeout' config values at startup","Treat expired deadlines as an immediate failure instead of passing the negative remainder"],"tags":["jdbc","presto","validation","invalid-argument"],"backgroundTag":"negative-timeout-argument","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"}