File tree Expand file tree Collapse file tree
main/java/org/msgpack/value/impl
test/scala/org/msgpack/value Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package org .msgpack .value .impl ;
22
33import org .msgpack .core .MessagePacker ;
4+ import org .msgpack .core .MessageStringCodingException ;
45import org .msgpack .value .ValueType ;
56import org .msgpack .value .*;
67
@@ -54,12 +55,16 @@ public boolean equals(Object o) {
5455 if (!v .isString ()) {
5556 return false ;
5657 }
57- StringValue sv = v .asString ();
58- return sv .toByteBuffer ().equals (byteBuffer );
58+ try {
59+ return toString ().equals (v .asString ().toString ());
60+ } catch (MessageStringCodingException ex ) {
61+ return false ;
62+ }
63+
5964 }
6065
6166 @ Override
6267 public int hashCode () {
63- return byteBuffer .hashCode ();
68+ return toString () .hashCode ();
6469 }
6570}
Original file line number Diff line number Diff line change @@ -50,4 +50,17 @@ class ValueFactoryTest extends MessagePackSpec {
5050 }
5151
5252 }
53+
54+ " StringValue" should {
55+ " return the same hash code if they are equal" in {
56+ val str = " a"
57+ val a1 = ValueFactory .newRawString(str.getBytes(" UTF-8" ))
58+ val a2 = ValueFactory .newString(str)
59+
60+ a1.shouldEqual(a2)
61+ a1.hashCode.shouldEqual(a2.hashCode)
62+ a2.shouldEqual(a1)
63+ a2.hashCode.shouldEqual(a1.hashCode)
64+ }
65+ }
5366}
You can’t perform that action at this time.
0 commit comments