Skip to content

Commit 430b1e7

Browse files
committed
Merge branch 'v07-develop' of github.com:msgpack/msgpack-java into v07-develop
2 parents 4588239 + 92b2e42 commit 430b1e7

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

msgpack-core/src/main/java/org/msgpack/value/impl/RawValueImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ private synchronized void decodeString() {
6262
if (decodedStringCache != null) {
6363
return;
6464
}
65+
ByteBuffer readOnlyBuffer = byteBuffer.asReadOnlyBuffer();
6566
try {
6667
CharsetDecoder reportDecoder = Charset.forName("UTF-8").newDecoder()
6768
.onMalformedInput(CodingErrorAction.REPLACE)
6869
.onUnmappableCharacter(CodingErrorAction.REPLACE);
69-
decodedStringCache = reportDecoder.decode(byteBuffer.asReadOnlyBuffer()).toString();
70+
readOnlyBuffer.position(0);
71+
decodedStringCache = reportDecoder.decode(readOnlyBuffer).toString();
7072
} catch (UnsupportedCharsetException neverThrown) {
7173
throw new AssertionError(neverThrown);
7274
} catch (CharacterCodingException ex) {
@@ -75,7 +77,8 @@ private synchronized void decodeString() {
7577
CharsetDecoder replaceDecoder = Charset.forName("UTF-8").newDecoder()
7678
.onMalformedInput(CodingErrorAction.REPLACE)
7779
.onUnmappableCharacter(CodingErrorAction.REPLACE);
78-
decodedStringCache = replaceDecoder.decode(byteBuffer.asReadOnlyBuffer()).toString();
80+
readOnlyBuffer.position(0);
81+
decodedStringCache = replaceDecoder.decode(readOnlyBuffer).toString();
7982
} catch (UnsupportedCharsetException neverThrown) {
8083
throw new AssertionError(neverThrown);
8184
} catch (CharacterCodingException neverThrown) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.msgpack.value
2+
3+
import scala.util.Random
4+
import org.msgpack.core.MessagePack.Code
5+
import org.msgpack.core.{MessagePack, MessageFormat, MessageFormatException, MessagePackSpec}
6+
import org.msgpack.core.MessagePack.Code._
7+
import java.io.ByteArrayOutputStream
8+
9+
10+
class RawValueImplTest extends MessagePackSpec {
11+
12+
"RawValueImple" should {
13+
"toString shouldn't return empty value" in {
14+
val str = "aaa"
15+
def newRawStr() = ValueFactory.newRawString(str.getBytes("UTF-8"))
16+
17+
def pack(v: Value): Array[Byte] = {
18+
val out = new ByteArrayOutputStream()
19+
val packer = MessagePack.newDefaultPacker(out)
20+
packer.packValue(v)
21+
packer.close()
22+
out.toByteArray
23+
}
24+
25+
{
26+
val rawStr = newRawStr()
27+
pack(rawStr)
28+
rawStr.toString() shouldBe str
29+
}
30+
31+
{
32+
val rawStr = newRawStr()
33+
pack(rawStr)
34+
rawStr.asString().toString shouldBe str
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)