From 835829105e63ada95a2d7ce76a06a46345035f47 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Thu, 24 Apr 2014 16:43:05 -0700 Subject: [PATCH] Ignore invalid list tag type if the ID is 0; this is written when the list is empty. --- .../org/spacehq/opennbt/tag/builtin/ListTag.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/spacehq/opennbt/tag/builtin/ListTag.java b/src/main/java/org/spacehq/opennbt/tag/builtin/ListTag.java index 2613879..8d17519 100644 --- a/src/main/java/org/spacehq/opennbt/tag/builtin/ListTag.java +++ b/src/main/java/org/spacehq/opennbt/tag/builtin/ListTag.java @@ -147,7 +147,7 @@ public class ListTag extends Tag implements Iterable { int id = in.readUnsignedByte(); this.type = TagRegistry.getClassFor(id); this.value = new ArrayList(); - if(this.type == null) { + if(id != 0 && this.type == null) { throw new IOException("Unknown tag ID in ListTag: " + id); } @@ -167,12 +167,17 @@ public class ListTag extends Tag implements Iterable { @Override public void write(DataOutputStream out) throws IOException { - int id = TagRegistry.getIdFor(this.type); - if(id == -1) { - throw new IOException("ListTag contains unregistered tag class."); + if(this.value.isEmpty()) { + out.writeByte(0); + } else { + int id = TagRegistry.getIdFor(this.type); + if(id == -1) { + throw new IOException("ListTag contains unregistered tag class."); + } + + out.writeByte(id); } - out.writeByte(id); out.writeInt(this.value.size()); for(Tag tag : this.value) { tag.write(out);