NPE while creating schematic files of regions containing mob spawners
LadyCailinBot opened this issue ยท 6 comments
WORLDEDIT-2793 - Reported by robbzkupper
java.lang.NullPointerException
at java.util.Collections$UnmodifiableMap.(Unknown Source)
at java.util.Collections.unmodifiableMap(Unknown Source)
at com.sk89q.jnbt.CompoundTag.(CompoundTag.java:63)
at com.sk89q.worldedit.blocks.MobSpawnerBlock.getNbtData(MobSpawnerBlock.java:150)
at com.sk89q.worldedit.schematic.MCEditSchematicFormat.save(MCEditSchematicFormat.java:256)
While the row numbes don't match, I'm convinced it's caused by this line:
values.put("SpawnData", new CompoundTag("SpawnData", spawnData == null ? null : spawnData.getValue()));
This can call the CompundTag constructor with null, and the constructor forwards the null without further check to:
Collections.unmodifiableMap(value);
which then throws the NPE.
Possible fix would be to change the CompundTag constructor from:
public CompoundTag(String name, Map<String, Tag> value) {
super(name);
this.value = Collections.unmodifiableMap(value);
}
to:
public CompoundTag(String name, Map<String, Tag> value) {
super(name);
this.value = value != null ? Collections.unmodifiableMap(value) : Collections.EMPTY_MAP;
}
Comment by wizjany
How are you even getting this error? WE shouldn't use MobSpawnerBlock...
Comment by robbzkupper
Well, it does.
public void saveRegion(CuboidRegion region, File file) throws IOException, DataException {
final Vector min = region.getMinimumPoint(), max = region.getMaximumPoint();
try (OutputStream os = new FileOutputStream(file)) {
EntityMCEditSchematicFormat.save(region.getWorld(), os, max.subtract(min).add(new Vector(1, 1, 1)), min, min);
}
}