falkreon/Jankson

The default value of the config is written to the file multiple times, one for each time I start my mod

Closed this issue · 5 comments

The default value of the config is written to the file multiple times, one for each time I start my mod
Here's my config system: https://gist.github.com/TechPro424/aac4a8f988b13ab0381c1e6295d5fbad

The JsonOperations.loadConfigFromFile(); is called twice, once in my mod's onInitialize() method in the main entrypoint, and in the Config class itself
It's called in the mod's onInitialize() method so that any problems/errors with serializing the config can be identified on launch, rather than waiting for the mod's functionality to kick in, and once more in the Config class to store the serialized config in the instance

I don't think this should cause issues, but just in case

Real world example of problem:

{
	"globalBlacklist": [
		"mod_id:item_id",
		"mod_id:item2_id",
		"mod_id:item_id",
		"mod_id:item2_id",
		"mod_id:item_id",
		"mod_id:item2_id",
		"mod_id:item_id",
		"mod_id:item2_id",
		"mod_id:item_id",
		"mod_id:item2_id",
		"minecraft:warped_planks",
		"minecraft:hi",
		"minecraft:b",
		"minecraft:cat"
	],
	"overworldBlacklist": [],
	"netherBlacklist": [],
	"endBlacklist": []
}

the

"mod_id:item_id",
"mod_id:item2_id"

is added once for each time I start the mod

Interesting! This looks like a bug that's been here for a very long time, but that no one has noticed.

I peeked at the actual Item-Blacklist repository and it looks like you're using 1.2.2 straight off of maven central, which is 👍, that's the newest 1.2.x.

I think the surgical solution for me here is to clear the collection here - https://github.com/falkreon/Jankson/blob/java8/src/main/java/blue/endless/jankson/impl/POJODeserializer.java#L233-L242

I just need to give that some thought and make sure there won't be any unusual side effects.

Could you give me a build with this change made so that I can include it in my mod and test it out?

I'm glad I sat on this - the same issue was present for maps, so I've fixed both! I'll push a GitHub release momentarily that'll work with jitpack. MavenCentral takes longer to replicate, but when it's available it will show up as 1.2.3.

Hey @falkreon
Tried out 1.2.3

Now what happens is that the default value is duplicated when I follow the following steps

  1. Start the game with my mod
  2. Open a world
  3. Add something to the blacklist

adding more items to the blacklist subsequently does not cause this, but when I close the game and repeat the above steps, it occurs again