Prevent adding self in compound tag

This commit is contained in:
Nassim Jahnke 2024-04-22 15:18:18 +02:00
parent 6ca922db67
commit 8149ec3bd0
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 4 additions and 1 deletions

View File

@ -5,7 +5,7 @@
<groupId>com.viaversion</groupId>
<artifactId>nbt</artifactId>
<version>4.4.3</version>
<version>4.4.4</version>
<packaging>jar</packaging>
<name>ViaNBT</name>

View File

@ -330,6 +330,9 @@ public final class CompoundTag extends Tag implements Iterable<Entry<String, Tag
*/
@Nullable
public <T extends Tag> T put(String tagName, T tag) {
if (tag == this) {
throw new IllegalArgumentException("Cannot add a tag to itself");
}
return (T) this.value.put(tagName, tag);
}