diff --git a/.classpath b/.classpath index 7c5308359..333c64934 100644 --- a/.classpath +++ b/.classpath @@ -4,8 +4,8 @@ - - - + + + diff --git a/build/minlog-1.2.jar b/build/minlog-1.2.jar new file mode 100644 index 000000000..7cc55acf7 Binary files /dev/null and b/build/minlog-1.2.jar differ diff --git a/build/minlog-none-1.2.jar b/build/minlog-none-1.2.jar new file mode 100644 index 000000000..50bd8d2cd Binary files /dev/null and b/build/minlog-none-1.2.jar differ diff --git a/lib/asm-3.3.1.jar b/lib/optional/asm-3.3.1.jar similarity index 100% rename from lib/asm-3.3.1.jar rename to lib/optional/asm-3.3.1.jar diff --git a/lib/reflectasm-1.01.jar b/lib/optional/reflectasm-1.01.jar similarity index 100% rename from lib/reflectasm-1.01.jar rename to lib/optional/reflectasm-1.01.jar diff --git a/project.yaml b/project.yaml index 8ce946bb8..6da5efea1 100644 --- a/project.yaml +++ b/project.yaml @@ -1,7 +1,4 @@ -version: 2.01 -dependencies: -- ../reflectasm -- ../minlog +version: 2.02 --- Build.build(project); -Build.oneJAR(project); +Build.oneJAR(project); \ No newline at end of file diff --git a/src/com/esotericsoftware/kryo/io/Input.java b/src/com/esotericsoftware/kryo/io/Input.java index 4b5bbec54..f646ee28b 100644 --- a/src/com/esotericsoftware/kryo/io/Input.java +++ b/src/com/esotericsoftware/kryo/io/Input.java @@ -344,7 +344,13 @@ public boolean canReadInt () throws KryoException { /** Reads the length and string of 8 bit characters. */ public String readChars () throws KryoException { int charCount = readInt(true); - if (charCount == 0) return ""; + switch (charCount) { + case 0: + return null; + case 1: + return ""; + } + charCount--; if (chars.length < charCount) chars = new char[charCount]; if (charCount > require(1, charCount)) return readChars_slow(charCount); char[] chars = this.chars; @@ -368,7 +374,13 @@ private String readChars_slow (int charCount) { /** Reads the length and string of UTF8 characters. */ public String readString () throws KryoException { int charCount = readInt(true); - if (charCount == 0) return ""; + switch (charCount) { + case 0: + return null; + case 1: + return ""; + } + charCount--; if (chars.length < charCount) chars = new char[charCount]; char[] chars = this.chars; byte[] buffer = this.buffer; diff --git a/src/com/esotericsoftware/kryo/io/Output.java b/src/com/esotericsoftware/kryo/io/Output.java index 5b1e812e5..e7ba5ac97 100644 --- a/src/com/esotericsoftware/kryo/io/Output.java +++ b/src/com/esotericsoftware/kryo/io/Output.java @@ -232,9 +232,12 @@ else if ((value >>> 21 & ~0x7F) == 0) /** Writes the length and string using 1 byte per character. */ public void writeChars (String value) throws KryoException { - if (value == null) throw new IllegalArgumentException("value cannot be null."); + if (value == null) { + writeByte(0); + return; + } int charCount = value.length(); - writeInt(charCount, true); + writeInt(charCount + 1, true); if (capacity < charCount) writeChars_slow(value, charCount); else { @@ -257,11 +260,15 @@ private void writeChars_slow (String value, int charCount) throws KryoException } } - /** Writes the length and string using UTF8. */ + /** Writes the length and string using UTF8, or null. + * @param value May be null. */ public void writeString (String value) throws KryoException { - if (value == null) throw new IllegalArgumentException("value cannot be null."); + if (value == null) { + writeByte(0); + return; + } int charCount = value.length(); - writeInt(charCount, true); + writeInt(charCount + 1, true); int charIndex = 0; if (capacity >= charCount) { // Try to write 8 bit chars. diff --git a/test/com/esotericsoftware/kryo/InputOutputTest.java b/test/com/esotericsoftware/kryo/InputOutputTest.java index 465ac05e4..2b32ccb05 100644 --- a/test/com/esotericsoftware/kryo/InputOutputTest.java +++ b/test/com/esotericsoftware/kryo/InputOutputTest.java @@ -87,22 +87,26 @@ public void runUTFTest (Output write) throws IOException { write.writeString("uno"); write.writeString("dos"); write.writeString("tres"); + write.writeString(null); write.writeString(value1); write.writeString(value2); write.writeChars("uno"); write.writeChars("dos"); write.writeChars("tres"); + write.writeChars(null); write.writeChars(value1); Input read = new Input(write.toBytes()); assertEquals("uno", read.readString()); assertEquals("dos", read.readString()); assertEquals("tres", read.readString()); + assertEquals(null, read.readString()); assertEquals(value1, read.readString()); assertEquals(value2, read.readString()); assertEquals("uno", read.readChars()); assertEquals("dos", read.readChars()); assertEquals("tres", read.readChars()); + assertEquals(null, read.readChars()); assertEquals(value1, read.readChars()); }