Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GsonConfigSerializer returns null when config is empty, crashing on load #256

Open
Fourmisain opened this issue May 5, 2024 · 0 comments

Comments

@Fourmisain
Copy link

Fourmisain commented May 5, 2024

Encountered in RandomMcSomethin/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 SerializationException return createDefault() when Gson returns a null value here, so it automatically resets and re-saves the config.


Relevant quote from the Gson javadoc:

Returns null if [Reader] json is at EOF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant