[SPIGOT-6949] Can no longer save lists of config sections to yaml files Created: 28/Feb/22 Updated: 22/Apr/22 Resolved: 22/Apr/22 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Nathan Wolf | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | 1.18.1, 1.18.2 | ||
| Environment: |
Ubuntu, mac OS |
||
| Attachments: |
|
| Version: | CraftBukkit version 3445-Spigot-fb0dd5f-05a38da (MC: 1.18.2) (Implementing API version 1.18.2-R0.1-SNAPSHOT) |
| Guidelines Read: | Yes |
| Description |
|
I use lists of config sections to save simple data files. This would previously serialize as a list of maps. As of 1.18.2 this does not serialize properly:
list:
- !!org.bukkit.configuration.MemoryConfiguration
defaults: null
Test plugin: https://github.com/NathanWolf/Bukkit-Unit-Tests/releases/tag/config-lists Code: YamlConfiguration newConfig = new YamlConfiguration(); List<ConfigurationSection> configList = new ArrayList<>(); MemoryConfiguration newSection = new MemoryConfiguration(); newSection.set("something", "value"); configList.add(newSection); newConfig.set("list", configList); try { File outputFile = new File(getDataFolder(), "data.yml"); newConfig.save(outputFile); getLogger().info("Wrote to: " + outputFile.getAbsolutePath()); } catch (IOException ex) { getLogger().severe("Could not save file: " + ex.getMessage()); } This is going to cause a lot of data loss for my users with flatfile storage when they update. I have not narrowed down the specific change, though I see a few suspects. As far as I know things have been working fine since the "save comments" re-work, so I think it's a more recent change. |
| Comments |
| Comment by blablubbabc [ 18/Apr/22 ] |
|
Can confirm (just encountered this issue myself in one of my plugins): The new serialization no longer accounts for configuration sections that are nested in other types of objects (lists, maps). |
| Comment by Nathan Wolf [ 01/Mar/22 ] |
|
Minor update as I try to implement a work-around in my plugin, it seems like serialization just does not descend into lists. If I convert all the top-level config sections in the list to maps, serialization still fails if there are sections nested in those maps. Example: list: - !!org.bukkit.configuration.MemoryConfiguration defaults: null - scalar: 10 string: something section: !!org.bukkit.configuration.MemoryConfiguration defaults: null Code: YamlConfiguration newConfig = new YamlConfiguration(); List<Object> configList = new ArrayList<>(); MemoryConfiguration newSection = new MemoryConfiguration(); newSection.set("something", "value"); configList.add(newSection); Map<String, Object> configMap = new HashMap<>(); configMap.put("scalar", 10); configMap.put("string", "something"); newSection = new MemoryConfiguration(); newSection.set("embedded", "value"); configMap.put("section", newSection); configList.add(configMap); newConfig.set("list", configList); |
| Comment by Nathan Wolf [ 28/Feb/22 ] |
|
Apologies, it does seem like this was caused by I reset back one commit at a time until I found that going back to `ffd8b289` (prior to `3e2dd2bc`, the commit for |
| Comment by Nathan Wolf [ 28/Feb/22 ] |
|
I can confirm the issue persists in a fresh 1.18.1 build, but 1.17.1 is ok: list: - something: value That leaves quite a few commits, though I do think this was working for me after updating to the big change to save comments: SPIGOT-6886: Restore previous behaviour of loading unusual config keys blablubbabc* 1/8/22, 3:04 PM Fix saving configs which are only a header md_5 1/7/22, 2:39 PM Add workaround for SnakeYAML 100 comment limit md_5 1/3/22, 2:25 PM #703: Fix/test yaml anchors and merge Wolf2323* 1/2/22, 12:08 PM #702: fromNodeTree is now private, this does not belong to the API Wolf2323* 12/28/21, 12:52 PM #701: Option to configure the max width of a line in the config Wolf2323* 12/26/21, 2:47 PM SPIGOT-6866: Fixed spaces a between comment indicator and actual comment Wolf2323* 12/23/21, 2:07 PM Restore protected members to YamlConfiguration md_5 12/22/21, 4:33 PM SPIGOT-3247: Comment support for YAML files Wolf2323* 12/20/21, 1:35 PM None of these really seem suspicious though. Unfortunately I'm not sure how to target a specific commit in BuildTools so it will be difficult for me to narrow this down further. |
| Comment by Nathan Wolf [ 28/Feb/22 ] |
|
I am sure that it is a problem with the 1.18.2 spigot I just build from BuildTools, but I can not say when it started to be a problem. I don't see this issue on my live servers but I haven't updated them in a while, and they run Paper anyway. I am trying to narrow it down to the last Spigot version that correctly saved lists of config sections. I don't even see anything in git within the past month that looks config-related, so I am confused too. |
| Comment by md_5 [ 28/Feb/22 ] |
|
Are you sure? There were no 1.18.2 config changes: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/d8a3c3b55674a931391e2905cad4d54acfd15d11 |