GsonConfigSerializer returns null when config is empty, crashing on load
Fourmisain opened this issue ยท 0 comments
Encountered in Fourmisain/fallingleaves#64
When a config file is empty for whatever reason and deserialized using the GsonConfigSerializer, it'll return null, which will NPE inside ConfigManager.load() here.
I thought of registering a load listener to work around that, but since load() is called from ConfigManager's constructor, it is impossible to call registerLoadListener() before load() - which is arguably another issue.
I think a good fix would be to let GsonConfigSerializer throw a return SerializationExceptioncreateDefault() when Gson returns a null value here, so it automatically resets and re-saves the config.
Relevant quote from the Gson javadoc:
Returns
nullif [Reader] json is atEOF.