{"record":{"id":"aac2c74c4eb5157c","repo":"quarkusio/quarkus","slug":"object-not-in-state","errorCode":"OBJECT_NOT_IN_STATE","errorMessage":"This SQLXML object has already been freed.","messagePattern":"This SQLXML object has already been freed\\.","errorType":"error_code","errorClass":"PSQLException","httpStatus":null,"severity":"error","filePath":"extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/graal/PgSQLXML.java","lineNumber":281,"sourceCode":"            }\n        }\n\n        throw new PSQLException(GT.tr(\"Unknown XML Result class: {0}\", resultClass),\n                PSQLState.INVALID_PARAMETER_TYPE);\n    }\n\n    @Substitute\n    @Override\n    public synchronized void setString(String value) throws SQLException {\n        checkFreed();\n        initialize();\n        data = value;\n    }\n\n    @Substitute\n    private void checkFreed() throws SQLException {\n        if (freed) {\n            throw new PSQLException(GT.tr(\"This SQLXML object has already been freed.\"),\n                    PSQLState.OBJECT_NOT_IN_STATE);\n        }\n    }\n\n    @Substitute\n    private void ensureInitialized() throws SQLException {\n        if (!initialized) {\n            throw new PSQLException(\n                    GT.tr(\n                            \"This SQLXML object has not been initialized, so you cannot retrieve data from it.\"),\n                    PSQLState.OBJECT_NOT_IN_STATE);\n        }\n\n        // Is anyone loading data into us at the moment?\n        if (!active) {\n            return;\n        }\n","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/jdbc/jdbc-postgresql/runtime/src/main/java/io/quarkus/jdbc/postgresql/runtime/graal/PgSQLXML.java#L263-L299","documentation":"SQLXML objects are one-shot: after free() is called, JDBC requires every other method to fail. PgSQLXML.checkFreed() enforces this by throwing PSQLException with SQLState OBJECT_NOT_IN_STATE whenever freed == true. It means you are using an SQLXML instance whose lifecycle has already been explicitly closed.","triggerScenarios":"Calling any of getBinaryStream, getCharacterStream, getSource, getString, setBinaryStream, setCharacterStream, setResult, setString after sqlxml.free() has been invoked; or reusing a cached SQLXML object across iterations after freeing it.","commonSituations":"Keeping SQLXML references in long-lived collections or DTOs and reading them after cleanup code ran; calling free() in a finally block then reading the value again for logging; caching row data with SQLXML fields beyond the ResultSet scope.","solutions":["Read/extract the XML content (e.g. via getString()) before calling free()","Never store SQLXML objects beyond the statement/transaction in which they were produced","Remove duplicate free() calls, or restructure code so cleanup happens after all reads","If you need the data later, copy it into a String/byte[]/DOM first"],"exampleFix":"// before\nSQLXML xml = rs.getSQLXML(\"data\");\nxml.free();\nString s = xml.getString(); // throws\n// after\nSQLXML xml = rs.getSQLXML(\"data\");\nString s = xml.getString();\nxml.free();","handlingStrategy":"validation","validationCode":"// Track lifecycle manually; JDBC has no isFreed accessor, so guard ownership yourself:\nSQLXML xml = rs.getSQLXML(\"data\");\nString content = xml.getString(); // extract BEFORE any free()\nxml.free();","typeGuard":"boolean usable(SQLXML xml) { try { xml.getString(); return true; } catch (SQLException e) { return false; } } // only in tests","tryCatchPattern":"try {\n    String s = sqlxml.getString();\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"already been freed\")) {\n        throw new IllegalStateException(\"SQLXML read after free()\");\n    }\n    throw e;\n}","preventionTips":["Extract content to String/byte[] before calling free()","Never cache SQLXML objects beyond the ResultSet/transaction scope","Call free() exactly once, as the last operation","Use try-with-resources on SQLXML where supported to centralize cleanup"],"tags":["jdbc","postgresql","sqlxml","lifecycle"],"backgroundTag":"sqlxml-object-freed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}