Details
-
Bug
-
Resolution: Unresolved
-
None
-
1.15.2, 20w16a, 20w17a, 20w18a, 20w20b, 1.16 Pre-release 5, 1.16.1, 1.16.2 Pre-release 1, 1.16.2, 1.16.3, 1.16.4 Pre-release 1, 1.16.4, 20w45a, 20w46a, 20w48a, 20w49a, 20w51a, 21w03a, 1.16.5, 21w05b, 21w08b, 21w10a, 21w13a, 21w15a, 21w16a, 21w19a, 1.17 Pre-release 1, 1.17, 1.17.1, 21w37a, 1.18.1, 22w03a, 22w05a, 1.18.2 Pre-release 1, 1.18.2, 22w11a, 22w12a, 1.19.1, 1.19.2, 22w42a, 1.19.3 Release Candidate 1, 1.19.3 Release Candidate 2, 1.19.3, 23w03a, 23w05a, 1.19.4, 23w18a
-
Confirmed
-
Commands
Description
The bug
If the target tag is a non-compound list and none of its elements matches the pattern, a match element node in an NBT path throws java.lang.UnsupportedOperationException when adding a copy of the pattern to the target tag to create a parent tag.
How to reproduce
/data modify storage mc-179181: list set value [0b]
/data modify storage mc-179181: list[{}].child set value 1b
→
An unexpected error occurred trying to execute that command (Trying to add tag of type 10 to list of 1)
Code analysis
// net.minecraft.commands.arguments.NbtPathArgument.MatchElementNode public void getOrCreateTag(Tag tag, Supplier<Tag> supplier, List<Tag> list) { MutableBoolean anyMatch = new MutableBoolean(); if (tag instanceof ListTag) { ListTag listTag = (ListTag) tag; listTag.stream().filter(this.predicate).forEach(t -> { list.add(t); anyMatch.setTrue(); }); if (anyMatch.isFalse()) { CompoundTag parent = this.pattern.copy(); // If none of the elements of `listTag` matches `this.predicate`, a compound tag `parent` is added to `listTag`. listTag.add(parent); list.add(parent); } } } // net.minecraft.nbt.ListTag public void add(int index, Tag tag) { if (!this.addTag(index, tag)) { // Since `tag` is a compound and this list is not a compound list in this case, `this.addTag(index, tag)` returns false and `UnsupportedOperationException` is thrown. throw new UnsupportedOperationException(String.format("Trying to add tag of type %d to list of %d", tag.getId(), this.type)); } }