{"record":{"id":"b3477830c2498b72","repo":"prestodb/presto","slug":"invalid-time-from-server","errorCode":null,"errorMessage":"Invalid time from server: ","messagePattern":"Invalid time from server: ","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":296,"sourceCode":"    {\n        return getTime(columnIndex, sessionTimeZone);\n    }\n\n    private Time getTime(int columnIndex, DateTimeZone localTimeZone)\n            throws SQLException\n    {\n        Object value = column(columnIndex);\n        if (value == null) {\n            return null;\n        }\n\n        ColumnInfo columnInfo = columnInfo(columnIndex);\n        if (columnInfo.getColumnTypeName().equalsIgnoreCase(\"time\")) {\n            try {\n                return new Time(TIME_FORMATTER.withZone(localTimeZone).parseMillis(String.valueOf(value)));\n            }\n            catch (IllegalArgumentException e) {\n                throw new SQLException(\"Invalid time from server: \" + value, e);\n            }\n        }\n\n        if (columnInfo.getColumnTypeName().equalsIgnoreCase(\"time with time zone\")) {\n            try {\n                return new Time(TIME_WITH_TIME_ZONE_FORMATTER.parseMillis(String.valueOf(value)));\n            }\n            catch (IllegalArgumentException e) {\n                throw new SQLException(\"Invalid time from server: \" + value, e);\n            }\n        }\n\n        throw new IllegalArgumentException(\"Expected column to be a time type but is \" + columnInfo.getColumnTypeName());\n    }\n\n    @Override\n    public Timestamp getTimestamp(int columnIndex)\n            throws SQLException","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L278-L314","documentation":"Thrown by PrestoResultSet.getTime when a TIME column value returned by the Presto server cannot be parsed by Joda-Time's ISO time parser. The SQLException wraps the underlying IllegalArgumentException from parseMillis and includes the offending raw value. It indicates the server sent a string that does not match the expected ISO 'HH:mm:ss[.SSS]' time format.","triggerScenarios":"Calling ResultSet.getTime(columnIndex) on a column whose server value is null, empty, or formatted in a non-ISO form (e.g. '24:00:00', trailing garbage, or a locale-formatted string) while the column type name is 'time'.","commonSituations":"Queries through intermediate proxies or non-Presto backends returning differently formatted times; custom connectors emitting non-ISO time strings; driver/server version mismatch changing serialization format.","solutions":["Inspect the offending value embedded in the SQLException message to see what the server actually returned.","Verify the column is truly Presto type 'time' and the value is non-null; handle NULL with wasNull() before calling getTime.","Upgrade the presto-jdbc driver to match the server version so serialization formats agree.","If the value is non-ISO, cast in SQL (e.g. CAST(col AS time) or date_format/parse) to normalize before fetching.","Catch SQLException and fall back to getString plus custom parsing."],"exampleFix":"// before\nTime t = rs.getTime(3);\n// after\nString raw = rs.getString(3);\nTime t = null;\nif (raw != null) {\n    try { t = rs.getTime(3); }\n    catch (SQLException e) {\n        java.time.LocalTime lt = java.time.LocalTime.parse(raw.trim()); // custom fallback parse\n        t = Time.valueOf(lt);\n    }\n}","handlingStrategy":"try-catch","validationCode":"String typeName = rs.getMetaData().getColumnTypeName(idx);\nString raw = rs.getString(idx);\nboolean safe = \"time\".equalsIgnoreCase(typeName) && raw != null && raw.trim().matches(\"\\\\d{1,2}:\\\\d{2}:\\\\d{2}(\\\\.\\\\d{1,9})?\");","typeGuard":"boolean isTimeColumn(ResultSet rs, int idx) throws SQLException {\n    String t = rs.getMetaData().getColumnTypeName(idx);\n    return \"time\".equalsIgnoreCase(t);\n}","tryCatchPattern":"try {\n    Time t = rs.getTime(idx);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid time from server:\")) {\n        String raw = rs.getString(idx);\n        // fallback: parse raw with a custom formatter or log and treat as null\n    } else {\n        throw e;\n    }\n}","preventionTips":["Check wasNull() / getString before calling getTime on nullable columns","Validate column type via ResultSetMetaData before using time getters","Keep presto-jdbc driver version aligned with the Presto server version","Cast non-ISO time columns to TIME in the SQL query itself"],"tags":["jdbc","presto","time-parsing","sql"],"backgroundTag":"invalid-time-format-from-server","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"}