Skip to content

Fix gh-11899: Default addLocationInformation to false in Settings and Toolchains XML writers#11984

Open
abhu85 wants to merge 1 commit intoapache:masterfrom
abhu85:gh-11899-fix-settings-location-comments
Open

Fix gh-11899: Default addLocationInformation to false in Settings and Toolchains XML writers#11984
abhu85 wants to merge 1 commit intoapache:masterfrom
abhu85:gh-11899-fix-settings-location-comments

Conversation

@abhu85
Copy link
Copy Markdown

@abhu85 abhu85 commented Apr 24, 2026

Summary

  • Default addLocationInformation to false in DefaultSettingsXmlFactory.write() and DefaultToolchainsXmlFactory.write()
  • Respect inputLocationFormatter from XmlWriterRequest — only emit location comments when explicitly requested
  • Align behavior with DefaultModelXmlFactory.write(), which already handles this correctly

Problem

DefaultSettingsXmlFactory.write() always emits InputLocation comments (e.g. <!-- /path/to/settings.xml:163 -->) because it creates a bare new SettingsStaxWriter() whose addLocationInformation field defaults to true. It also ignores the inputLocationFormatter from the XmlWriterRequest.

This is inconsistent with DefaultModelXmlFactory.write(), which correctly defaults location tracking to false and only enables it when an explicit inputLocationFormatter is provided.

The same issue exists in DefaultToolchainsXmlFactory.write().

Solution

Applied the same pattern from DefaultModelXmlFactory.write() (lines 165-174) to both:

  1. Create the StaxWriter instance
  2. Set addLocationInformation(false) by default
  3. Check request.getInputLocationFormatter() — if provided, enable location information and set the string formatter

Test Plan

  • mvn -pl impl/maven-impl -am test — 461 tests pass, 0 failures
  • mvn spotless:apply — formatting applied
  • git diff --check — no whitespace issues

Compatibility

  • No breaking changes — callers that don't provide inputLocationFormatter now get cleaner XML
  • Callers that explicitly provide inputLocationFormatter will continue to get location comments

Fixes #11899

…gs and Toolchains XML writers

DefaultSettingsXmlFactory.write() and DefaultToolchainsXmlFactory.write()
always emitted InputLocation comments (e.g. <!-- /path/to/settings.xml:163 -->)
because they created bare StaxWriter instances whose addLocationInformation
field defaults to true, and never called setAddLocationInformation(false).

Align both factories with DefaultModelXmlFactory.write(), which correctly
defaults location tracking to false and only enables it when an explicit
inputLocationFormatter is provided via XmlWriterRequest.

Fixes apache#11899
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DefaultSettingsXmlFactory.write() Always Emits Location Comments

1 participant