Skip to content

Fix comments lost when load() auto-saves new fields#1

Open
lt-name wants to merge 1 commit intoWaterdogPE:masterfrom
lt-name:patch/patch-1
Open

Fix comments lost when load() auto-saves new fields#1
lt-name wants to merge 1 commit intoWaterdogPE:masterfrom
lt-name:patch/patch-1

Conversation

@lt-name
Copy link
Copy Markdown

@lt-name lt-name commented Feb 19, 2026

Summary

  • When load() or reload() detects new fields not present in the YAML file, it calls saveToYaml() directly to persist them. At that point the comments map is empty, causing the rewritten file to lose all @Comment/@Comments annotation-based comments.
  • Extracted comment collection logic from internalSave() into a reusable collectComments(Class) method, and invoke it before every saveToYaml() call in internalLoad().
  • Also fixed save(boolean): always clearComments() first, then conditionally collectComments(). This corrects two side issues: save(false) previously still wrote comments (because internalSave re-added them after clear), and repeated save() calls accumulated duplicate comments.

Changes

  • YamlConfig.java
    • New private method collectComments(Class) — recursively walks fields, resolves path (CONFIG_MODE + @path), and populates the comments map from @Comment/@Comments annotations.
    • internalSave() — removed inline comment collection (now handled by collectComments).
    • internalLoad() — added clearComments() + collectComments(getClass()) before saveToYaml().
    • save(boolean withComments) — changed to clearComments() unconditionally, then collectComments() only when withComments=true.

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.

1 participant