[#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. <anything>)) => 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!
This commit is contained in:
Peter Taoussanis 2022-06-23 12:23:49 +02:00
parent ba8827708e
commit 8909a32bdd
2 changed files with 3 additions and 1 deletions

View file

@ -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))

View file

@ -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))