SpongePowered/Configurate

IllegalArgumentException when trying to use @Commet on a field

ParadauxIO opened this issue · 1 comments

Having an issue regarding the @comment annotation when trying to save a CommentedConfigurationNode

Using configurate-hocon 4.1.1

Exception in thread "main" org.spongepowered.configurate.serialize.SerializationException: [bot-token] of type java.lang.String: null
	at org.spongepowered.configurate.objectmapping.ObjectMapperImpl.saveSingle(ObjectMapperImpl.java:136)
	at org.spongepowered.configurate.objectmapping.ObjectMapperImpl.save(ObjectMapperImpl.java:114)
	at org.spongepowered.configurate.objectmapping.ObjectMapperFactoryImpl.serialize(ObjectMapperFactoryImpl.java:251)
	at org.spongepowered.configurate.ScopedConfigurationNode.set(ScopedConfigurationNode.java:110)
	at io.paradaux.friendlybot.config.FConfigurationLoader.saveConfig(FConfigurationLoader.java:42)
	at io.paradaux.friendlybot.FBApplication.main(FBApplication.java:29)
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field io.paradaux.friendlybot.config.FConfiguration.botToken to org.spongepowered.configurate.CommentedConfigurationNodeImpl
	at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
	at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
	at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
	at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
	at java.base/java.lang.reflect.Field.get(Field.java:418)
	at org.spongepowered.configurate.objectmapping.ObjectMapperImpl.saveSingle(ObjectMapperImpl.java:132)
	... 5 more

Related files from the project:

FConfiguration.java - The Configuration Object
FConfigurationLoader.java - Configuration Loader/Util class

If I can be of any more assistance with this let me know!

https://github.com/ParadauxIO/FriendlyBot/blob/c414a1d83554543e58d77be670fc3f68c52f296d/src/main/java/io/paradaux/friendlybot/config/FConfigurationLoader.java#L42

It looks like you are passing the wrong variable to the set() method here, and the java compiler has chosen to call the Type overload of the method, rather than the type-checked Class<V> overload. For 4.1.2 I'll add a more helpful error message to validate that the appropriate value type is provided.