Datamanipulator implementing problem

I want to offer persistant data to an itemstack, but getting npe from some sponge internal.

java.lang.NullPointerException: null
    at ~[MemoryDataView.class:1.12.2-7.0.0-BETA-369]
    at ~[MemoryDataView.class:1.12.2-7.0.0-BETA-369]
    at ~[MemoryDataView.class:1.12.2-7.0.0-BETA-369]
    at ~[MemoryDataView.class:1.12.2-7.0.0-BETA-369]
    at ~[MemoryDataContainer.class:1.12.2-7.0.0-BETA-369]
    at ~[MemoryDataContainer.class:1.12.2-7.0.0-BETA-369]
    at ~[EffectsData.class:1.0.10]
    at ~[DataUtil.class:1.12.2-7.0.0-BETA-369]
    at ~[DataUtil.class:1.12.2-7.0.0-BETA-369]
    at net.minecraft.item.ItemStack.resyncCustomToTag(SourceFile:2388) ~[aip.class:?]
    at net.minecraft.item.ItemStack.offerCustom(SourceFile:2357) ~[aip.class:?]
    at net.minecraft.item.ItemStack.offer(SourceFile:1194) ~[aip.class:?]
    at net.minecraft.item.ItemStack.offer(SourceFile:1065) ~[aip.class:?]
    at ~[CompositeValueStore.class:1.12.2-7.0.0-BETA-369]

All relevant code -

Could anyone point out why am i getting this npe?
Please do not link that datamanipulator generator tool, thats not a feedback i want to see, nor its relevant to my question.

1 Like

I have the same problem. I have no idea how to solve it

May or may not be related but your constructor doesn’t defend against a null argument.
Just change it to this.effects = checkNotNull(effects, "effects");

Also, it probably makes more sense here to use AbstractMappedData since your data is a mapping.

Not related, im not offering null.

Looked through the stack trace, I suspect that EffectParams#toContainer is returning null.

public DataContainer toContainer() {
    DataContainer dataContainer = super.toContainer();
    return dataContainer;

Implementation of toContainer method - Its not possible that this would ever return null.

Could you post the EffectParams class?

Thats nothing more than

public class EffectParams extends HashMap<String, String> {}

Oh hmm, from the stack trace it looked like it was a DataSerializable class.
I’m wondering whether it could be the data query DataQuery.of(".", "ntrpg:itemeffects"),
maybe just make that DataQuery.of("ItemEffects"), instead

I updated my datamanipulator which now inherits from AbstractMappedData+ your’s suggested changes remove the first parameter from dataquery#of

still getting an error which is not really helpful

Sponge found an unregistered DataRegistration id. Don't worry though!Sponge will
attempt to persist the failed data for future attempts, unlessthe id is added in
'data-to-purge' in the sponge/custom-data.cnf

Unregistered Id : nt-rpg:item_effects Could not deserialize nt-rpg:item_effects!

updated from deprecated keyfactory to key.builder

	ITEM_EFFECTS = Key.builder()
			.type(new TypeToken<MapValue<String, EffectParams>>() {})

still getting that very helpful stacktrace Unregistered Id : nt-rpg:item_effects

That’ll be because you renamed the key, you’ll want to purge the data as suggested or just create a new world.