quarkusio/quarkus · error · IllegalStateException

Stored XML element was loaded as null!

Error message

Stored XML element was loaded as null!

What it means

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.

Source

Thrown at integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java:152

        try (final Connection con = ds.getConnection()) {
            deleteXmlSchema(con);
            createXmlSchema(con);
            writeXmlObject(con);
            checkWrittenXmlObject(con);
        }
        return "OK";
    }

    private void checkWrittenXmlObject(Connection con) throws SQLException {
        try (Statement stmt = con.createStatement()) {
            final ResultSet resultSet = stmt.executeQuery("SELECT val FROM xmltest");
            final boolean next = resultSet.next();
            if (!next) {
                throw new IllegalStateException("Stored XML element not found!");
            }
            final String storedValue = resultSet.getString(1);
            if (storedValue == null) {
                throw new IllegalStateException("Stored XML element was loaded as null!");
            }
            String expectedMatch = "<?xml version=\"1.0\" standalone=\"no\"?><root><ele>1</ele><ele>2</ele></root>";
            if (!expectedMatch.equals(storedValue)) {
                throw new IllegalStateException("Stored XML element is not matching expected value of '" + expectedMatch
                        + "', but was '" + storedValue + "'");
            }
        }
    }

    private void writeXmlObject(Connection con) throws SQLException, TransformerException {
        TransformerFactory factory = TransformerFactory.newInstance();
        final String _xmlDocument = "<root><ele>1</ele><ele>2</ele></root>";
        Transformer identityTransformer = factory.newTransformer();
        try (PreparedStatement ps = con.prepareStatement("INSERT INTO xmltest VALUES (?,?)")) {
            SQLXML xml = con.createSQLXML();
            Result result = xml.setResult(DOMResult.class);

            Source source = new StreamSource(new StringReader(_xmlDocument));

View on GitHub (pinned to e1c734241f)

Solutions

  1. Confirm writeXmlObject serializes into the PreparedStatement parameter and commits
  2. Verify the column index (1) matches the 'val' column in the current schema
  3. Add a NOT NULL constraint on xmltest.val so bad writes fail at insert time

Example fix

// before
final String storedValue = resultSet.getString(1);
if (storedValue == null) { throw new IllegalStateException("Stored XML element was loaded as null!"); }
// after
assertNotNull(resultSet.getObject("val"), "val must not be null");
final String storedValue = resultSet.getString("val");
Defensive patterns

Strategy: validation

Validate before calling

if (resultSet.next() && resultSet.getObject("val") == null) {
    throw new IllegalStateException("val is null - write step did not bind XML");
}

Prevention

When it happens

Trigger: resultSet.getString(1) returns null after a row was found - the stored XML was written as NULL, or a different column/index was read.

Common situations: Writing with a Transformer whose output never reached the PreparedStatement (empty/null binding), or reading with the wrong column index after schema changes.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/5c872d7d063878a2. Report an issue: GitHub.