apache/maven · error · XmlWriterException

Unable to write settings: {}

Error message

Unable to write settings: {}

What it means

Wrapper thrown by DefaultSettingsXmlFactory.write when serializing a Settings document fails: STaX writer errors, IOException on the target stream, or failures thrown by the configured InputLocationFormatter. The cause is preserved and its message appended.

Source

Thrown at impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSettingsXmlFactory.java:100

        }
        try {
            SettingsStaxWriter xmlWriter = new SettingsStaxWriter();
            xmlWriter.setAddLocationInformation(false);

            Function<Object, String> formatter = request.getInputLocationFormatter();
            if (formatter != null) {
                xmlWriter.setAddLocationInformation(true);
                Function<InputLocation, String> adapter = formatter::apply;
                xmlWriter.setStringFormatter(adapter);
            }

            if (writer != null) {
                xmlWriter.write(writer, content);
            } else {
                xmlWriter.write(outputStream, content);
            }
        } catch (Exception e) {
            throw new XmlWriterException("Unable to write settings: " + getMessage(e), getLocation(e), e);
        }
    }

    static <T> T nonNull(T t, String name) {
        if (t == null) {
            throw new IllegalArgumentException(name + " cannot be null");
        }
        return t;
    }
}

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Unwrap getCause() to identify the stream/IO versus formatter versus STaX failure
  2. Verify the stream is open and writable before the call
  3. Test the InputLocationFormatter separately if one is configured

Example fix

// before
try {
    settingsXmlFactory.write(req);
} catch (XmlWriterException e) {
    throw new RuntimeException(e); // real cause hidden
}

// after
try {
    settingsXmlFactory.write(req);
} catch (XmlWriterException e) {
    log.error("settings write failed: {}", e.getCause().getMessage(), e.getCause());
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
    settingsXmlFactory.write(req);
} catch (XmlWriterException e) {
    Throwable cause = e.getCause();
    // distinguish stream failure vs formatter failure before deciding to retry
    log.error("settings write failed", cause);
}

Prevention

When it happens

Trigger: Output stream already closed or read-only; an InputLocationFormatter that throws on null locations; STaX implementation failures during write.

Common situations: Writing settings back to a read-only file; custom location formatters used for round-tripping settings with comments.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/d954c05ba7611ef0. Report an issue: GitHub.