-
Notifications
You must be signed in to change notification settings - Fork 32
preserveInsertionOrder doesn't work if autoreload applied #188
Copy link
Copy link
Open
Labels
Description
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import java.nio.file.Path;
import java.nio.file.Paths;
public class ConfigBugRep {
private static final Path CONFIG_PATH = Paths.get("config/crash_assistant/config.toml");
private static final CommentedFileConfig config;
static {
CONFIG_PATH.getParent().toFile().mkdirs();
config = CommentedFileConfig.builder(CONFIG_PATH).preserveInsertionOrder().autosave().autoreload().build();
setupDefaultValues();
}
private static void setupDefaultValues() {
config.setComment("general", "General comment.");
addOption("general.opt2",
"Opt2 comment.",
"2");
addOption("general.opt1",
"Opt1 comment.",
"1");
}
private static <T> void addOption(String path, String comment, T defaultValue) {
config.set(path, defaultValue);
config.setComment(path, comment);
}
public static void main(String[] args) {
config.close();
}
}Generated config:
#General comment.
[general]
#Opt1 comment.
opt1 = "1"
#Opt2 comment.
opt2 = "2"Version: 3.6.4
We add opt2 earlier than opt1. and preserveInsertionOrder() is applied to builder. But opt1 is earlier than opt2 in generated config.
Reactions are currently unavailable