{"record":{"id":"5c872d7d063878a2","repo":"quarkusio/quarkus","slug":"stored-xml-element-was-loaded-as-null","errorCode":null,"errorMessage":"Stored XML element was loaded as null!","messagePattern":"Stored XML element was loaded as null!","errorType":"http","errorClass":"IllegalStateException","httpStatus":500,"severity":"error","filePath":"integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java","lineNumber":152,"sourceCode":"        try (final Connection con = ds.getConnection()) {\n            deleteXmlSchema(con);\n            createXmlSchema(con);\n            writeXmlObject(con);\n            checkWrittenXmlObject(con);\n        }\n        return \"OK\";\n    }\n\n    private void checkWrittenXmlObject(Connection con) throws SQLException {\n        try (Statement stmt = con.createStatement()) {\n            final ResultSet resultSet = stmt.executeQuery(\"SELECT val FROM xmltest\");\n            final boolean next = resultSet.next();\n            if (!next) {\n                throw new IllegalStateException(\"Stored XML element not found!\");\n            }\n            final String storedValue = resultSet.getString(1);\n            if (storedValue == null) {\n                throw new IllegalStateException(\"Stored XML element was loaded as null!\");\n            }\n            String expectedMatch = \"<?xml version=\\\"1.0\\\" standalone=\\\"no\\\"?><root><ele>1</ele><ele>2</ele></root>\";\n            if (!expectedMatch.equals(storedValue)) {\n                throw new IllegalStateException(\"Stored XML element is not matching expected value of '\" + expectedMatch\n                        + \"', but was '\" + storedValue + \"'\");\n            }\n        }\n    }\n\n    private void writeXmlObject(Connection con) throws SQLException, TransformerException {\n        TransformerFactory factory = TransformerFactory.newInstance();\n        final String _xmlDocument = \"<root><ele>1</ele><ele>2</ele></root>\";\n        Transformer identityTransformer = factory.newTransformer();\n        try (PreparedStatement ps = con.prepareStatement(\"INSERT INTO xmltest VALUES (?,?)\")) {\n            SQLXML xml = con.createSQLXML();\n            Result result = xml.setResult(DOMResult.class);\n\n            Source source = new StreamSource(new StringReader(_xmlDocument));","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java#L134-L170","documentation":"An IllegalStateException thrown when the xmltest row exists but its 'val' column reads back as NULL via ResultSet.getString. Since the test expects an actual XML document, this indicates the value written was null or the read targeted the wrong column/type.","triggerScenarios":"resultSet.getString(1) returns null after a row was found - the stored XML was written as NULL, or a different column/index was read.","commonSituations":"Writing with a Transformer whose output never reached the PreparedStatement (empty/null binding), or reading with the wrong column index after schema changes.","solutions":["Confirm writeXmlObject serializes into the PreparedStatement parameter and commits","Verify the column index (1) matches the 'val' column in the current schema","Add a NOT NULL constraint on xmltest.val so bad writes fail at insert time"],"exampleFix":"// before\nfinal String storedValue = resultSet.getString(1);\nif (storedValue == null) { throw new IllegalStateException(\"Stored XML element was loaded as null!\"); }\n// after\nassertNotNull(resultSet.getObject(\"val\"), \"val must not be null\");\nfinal String storedValue = resultSet.getString(\"val\");","handlingStrategy":"validation","validationCode":"if (resultSet.next() && resultSet.getObject(\"val\") == null) {\n    throw new IllegalStateException(\"val is null - write step did not bind XML\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read columns by name, not index, to survive schema edits","Add NOT NULL constraints on columns that must hold data","Assert the parameter binding succeeded in the write step"],"tags":["jdbc","xml","postgresql","null-value"],"backgroundTag":"unexpected-null-column","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}