Datamanipulator implementing problem

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

java.lang.NullPointerException: null
    at org.spongepowered.common.data.MemoryDataView.set(MemoryDataView.java:266) ~[MemoryDataView.class:1.12.2-7.0.0-BETA-369]
    at org.spongepowered.common.data.MemoryDataView.setMap(MemoryDataView.java:401) ~[MemoryDataView.class:1.12.2-7.0.0-BETA-369]
    at org.spongepowered.common.data.MemoryDataView.set(MemoryDataView.java:280) ~[MemoryDataView.class:1.12.2-7.0.0-BETA-369]
    at org.spongepowered.common.data.MemoryDataView.set(MemoryDataView.java:256) ~[MemoryDataView.class:1.12.2-7.0.0-BETA-369]
    at org.spongepowered.common.data.MemoryDataContainer.set(MemoryDataContainer.java:77) ~[MemoryDataContainer.class:1.12.2-7.0.0-BETA-369]
    at org.spongepowered.common.data.MemoryDataContainer.set(MemoryDataContainer.java:82) ~[MemoryDataContainer.class:1.12.2-7.0.0-BETA-369]
    at cz.neumimto.rpg.inventory.data.manipulators.EffectsData.toContainer(EffectsData.java:103) ~[EffectsData.class:1.0.10]
    at org.spongepowered.common.data.util.DataUtil.getSerializedManipulatorList(DataUtil.java:141) ~[DataUtil.class:1.12.2-7.0.0-BETA-369]
    at org.spongepowered.common.data.util.DataUtil.getSerializedManipulatorList(DataUtil.java:127) ~[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 org.spongepowered.api.data.value.mutable.CompositeValueStore.offer(CompositeValueStore.java:270) ~[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.

    @Override
public DataContainer toContainer() {
    DataContainer dataContainer = super.toContainer();
    dataContainer.set(NKeys.ITEM_EFFECTS,effects);
    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
org.spongepowered.api.data.persistence.InvalidDataException: Could not deserialize nt-rpg:item_effects!

updated from deprecated keyfactory to key.builder

	ITEM_EFFECTS = Key.builder()
			.type(new TypeToken<MapValue<String, EffectParams>>() {})
			.name("ItemEffects")
			.query(DataQuery.of("itemeffects"))
			.id("item_effects")
			.build();

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.