-
Bug
-
Resolution: Fixed
-
1.16.5, 21w11a, 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 Release Candidate 2, 1.19, 1.19.1, 1.19.2
-
Confirmed
-
Commands
The bug
While all elements of a list tag are being inserted into all elements of the same list tag, the source list tag is modified.
How to reproduce
data modify storage mc-221421: list set value [[], []]
data modify storage mc-221421: list[] append from storage mc-221421: list[]
data get storage mc-221421: list
Expected behavior
Storage mc-221421: has the following contents: [[[], []], [[], []]]
- The tags [], [] are inserted into each tag.
Actual behavior
Storage mc-221421: has the following contents: [[[], []], [[[], []], [[[], []]]]]
- The tags [], [] are inserted into the first tag.
- The modified first tag is inserted into the second tag.
- The modified second tag is inserted into the second tag.
Code analysis
net.minecraft.server.commands.data.DataCommands.java
private static int insertAtIndex(int index, CompoundTag tag, NbtPath path, List<Tag> sources) throws CommandSyntaxException { var targets = path.getOrCreate(tag, ListTag::new); var result = 0; for (var target : targets) { if (!(target instanceof CollectionTag)) { throw ERROR_EXPECTED_LIST.create(target); } var success = false; var collection = (CollectionTag<?>) target; var cursor = index < 0 ? collection.size() + index + 1 : index; for (var source : sources) { try { if (collection.addTag(cursor, source.copy() /* Copying should be done in batches outside of the sources iteration. */)) { ++cursor; success = true; } } catch (IndexOutOfBoundsException e) { throw ERROR_INVALID_INDEX.create(cursor); } } result += success ? 1 : 0; } return result; }
- relates to
-
MC-225425 "/data modify" inserts source elements into target collection one by one
- Open