Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-179181

Match element nodes in NBT paths throw an unexpected UnsupportedOperationException against non-compound lists

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: 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
    • Fix Version/s: None
    • Labels:
    • Confirmation Status:
      Confirmed
    • Category:
      (Unassigned)

      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

      1. /data modify storage mc-179181: list set value [0b]
      2. /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));
          }
      }

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            intsuc intsuc
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              CHK: