From 8909a32bdd654a136da385e0e09c9cc44416f964 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Thu, 23 Jun 2022 12:23:49 +0200 Subject: [PATCH] [#89 #150] [Fix] Boxed Booleans incorrectly freezing to primitive `true` (@RolT) Before this commit: (freeze true) => froze as primitive `true` (freeze false) => froze as primitive `false` (freeze (Boolean. )) => froze as primitive `true` After this commit: Boxed Booleans are first unboxed to correct primitive value before freezing This was a long-standing bug, though thankfully unlikely to have affected most users since boxed Booleans are rarely used in Clojure. Cases with Java interop are the most likely to have been affected. A big thanks to Roland Thiolliere (@RolT) for this fix! --- README.md | 1 + src/taoensso/nippy.clj | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7660cd..ac82760 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ nippy/stress-data :nil nil :true true :false false + :False (Boolean. false) :char \ಬ :str-short "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ" :str-long (apply str (range 1000)) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 38ebb69..9210358 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -1151,7 +1151,7 @@ (.writeLong out (.getMostSignificantBits x)) (.writeLong out (.getLeastSignificantBits x))) -(freezer Boolean (if x (write-id out id-true) (write-id out id-false))) +(freezer Boolean (if (boolean x) (write-id out id-true) (write-id out id-false))) (freezer (Class/forName "[B") (write-bytes out x)) (freezer (Class/forName "[Ljava.lang.Object;") (write-objects out x)) (freezer String (write-str out x)) @@ -2020,6 +2020,7 @@ :nil nil :true true :false false + :False (Boolean. false) :char \ಬ :str-short "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ" :str-long (apply str (range 1000))