OkaeriPoland / okaeri-configs

Simple Java/POJO config library written with love and Lombok
MIT License
77 stars 11 forks source link

OkaeriConfig.save method will clear file of content if errors to simplify any object #46

Open Paradis4432 opened 4 months ago

Paradis4432 commented 4 months ago

using implementation 'eu.okaeri:okaeri-configs-yaml-bukkit:5.0.0-beta.5' implementation 'eu.okaeri:okaeri-configs-serdes-bukkit:5.0.0-beta.5' bukkit severity: medium

Describe the bug i have https://paste.md-5.net/ihowenijat.java as you can see theres a few values and a NPCManager, ConifgNPC, those have no ObjectSerializer registered

im using https://paste.md-5.net/ecawikikat.cs for testing of file loading

the method it.load is not the issue, it.save is what clears the file

the method eu.okaeri.configs.configurer.Configurer;simplify() will throw new OkaeriException("cannot simplify type " + serializerType + " (" + genericType + "): '" + value + "' [" + value.getClass() + "]"); if no serializer is found for the object, but this will brake the for loop https://paste.md-5.net/quyunoxucu.coffeescript found in the save method

im not sure why in the return this.save(new PrintStream(new FileOutputStream(file, false), true, StandardCharsets.UTF_8.name())); the autoFlush is not flushing the first few values

To Reproduce create class with no objectSerializer and let it run call load then save, or it.load(true)

Expected behavior avoid value or add all but that one whatever happens, not clearing the entire config file would be great otherwise theres a need for constant backups

Library version implementation 'eu.okaeri:okaeri-configs-yaml-bukkit:5.0.0-beta.5' implementation 'eu.okaeri:okaeri-configs-serdes-bukkit:5.0.0-beta.5' i only use bukkit

Config classes and setup routine already added

fix: as seen in the video if instead of throwing we return null the value is ignored, the error is printed to console and the file doesnt get reset https://vimeo.com/936353158?share=copy

other: here are a few notes iv made while debugging this https://paste.md-5.net/zaxukusono.cs

if you need more info feel free to dm me in discord .paradis

Screenshot_27 Screenshot_26 Screenshot_28

Paradis4432 commented 4 months ago

it would be better to instead of returning null have some kind of validator in the OkaeriConfig class to warn on compile when a class added does not have an ObjectSerializer registered