Completed
Details
Assignee
UnassignedUnassignedReporter
Tomasz NurkiewiczTomasz NurkiewiczLabels
Approval
OkPatch
Code and TestPriority
MinorAffects versions
Fix versions
Details
Details
Assignee
Unassigned
UnassignedReporter
Tomasz Nurkiewicz
Tomasz NurkiewiczLabels
Approval
Ok
Patch
Code and Test
Priority
Affects versions
Fix versions
Created April 19, 2014 at 10:52 AM
Updated October 7, 2014 at 6:32 PM
Resolved October 7, 2014 at 6:32 PM
_str
field inKeyword
andSymbol
classes lazily caches result oftoString()
. Because this field is nottransient
, serializing (using Java serialization) any keyword or symbol before and after callingtoString()
for the first time yields different results:(import (java.io ByteArrayOutputStream ObjectOutputStream ByteArrayInputStream ObjectInputStream)) (defn- serialize [obj] (with-open [bos (ByteArrayOutputStream.) stream (ObjectOutputStream. bos)] (.writeObject stream obj) (-> bos .toByteArray seq))) ;; keyword example (def k1 (serialize :k)) (println :k) (def k2 (serialize :k)) (= k1 k2) ;;=> false ;; symbol example (def sym 'a) (def s1 (serialize sym)) (println sym) (def s2 (serialize sym)) (= s1 s2) ;;=> false
This issue came up when I was trying to use keywords as key in [Hazelcast](https://github.com/hazelcast/hazelcast) map. Hazelcast uses serialized keys in various scenarios, thus if I first put something to map under key
:k
and then print:k
, I can no longer find such key.Approach: Add
transient
keyword to_str
field inKeyword
andSymbol
classesPatch: CLJ-1408-3.patch
Screened by: Brenton Ashworth