Clojure

equality bug on records created with nested calls to map->record

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.6
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

Depending on the type of the map passed to a record map constructor, records will not correctly compare for equality:

user> (defrecord a []) 
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2)  ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2)  ;; expected => {:a 1}
#user.a{:a 1}

Cause: The type of the map passed into the map constructor leaks into the __extmap, affecting equality comparison of the record. This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

Approach: Clean the extmap before putting it into the record constructor.

Patch: CLJ-1388-record-equality-and-map-record-factory.patch

Screened by: Alex Miller

  1. 0001-FIX-CLJ-1388.patch
    18/Mar/14 8:44 PM
    2 kB
    Nicola Mometto
  2. CLJ-1388.patch
    29/Apr/14 1:52 PM
    6 kB
    Nicola Mometto
  3. CLJ-1388-record-equality-and-map-record-factory.patch
    29/Apr/14 10:17 AM
    5 kB
    Steve Miner
  4. CLJ-1388v2.patch
    30/Apr/14 3:57 PM
    5 kB
    Nicola Mometto

Activity

Nicola Mometto made changes -
Field Original Value New Value
Attachment 0001-FIX-CLJ-1388.patch [ 12886 ]
Nicola Mometto made changes -
Patch Code and Test [ 10002 ]
Affects Version/s Release 1.6 [ 10157 ]
Nicola Mometto made changes -
Attachment 0001-FIX-CLJ-1388.patch [ 12886 ]
Nicola Mometto made changes -
Attachment 0001-FIX-CLJ-1388.patch [ 12887 ]
Alex Miller made changes -
Approval Triaged [ 10120 ]
Description This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

{code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2)
#user.a{:a 1}
{code}

This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:* 0001-FIX-CLJ-1388.patch

*Screened by:*
Labels defrecord
Rich Hickey made changes -
Fix Version/s Release 1.7 [ 10250 ]
Approval Triaged [ 10120 ] Vetted [ 10003 ]
Alex Miller made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Description {code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2)
#user.a{:a 1}
{code}

This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:* 0001-FIX-CLJ-1388.patch

*Screened by:*
{code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2) ;; expected => {:a 1}
#user.a{:a 1}
{code}

This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:* 0001-FIX-CLJ-1388.patch

*Screened by:* Alex Miller
Steve Miner made changes -
Attachment CLJ-1388-equality-bug-with-degenerate-records.patch [ 12964 ]
Alex Miller made changes -
Approval Screened [ 10004 ] Vetted [ 10003 ]
Steve Miner made changes -
Attachment CLJ-1388-equality-bug-with-degenerate-records.patch [ 12964 ]
Steve Miner made changes -
Comment [ Attached a new patch that applies fix only to the problem case. Added tests that show the actual problem and confirm the fix. ]
Steve Miner made changes -
Nicola Mometto made changes -
Attachment CLJ-1388.patch [ 12967 ]
Alex Miller made changes -
Description {code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2) ;; expected => {:a 1}
#user.a{:a 1}
{code}

This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:* 0001-FIX-CLJ-1388.patch

*Screened by:* Alex Miller
{code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2) ;; expected => {:a 1}
#user.a{:a 1}
{code}

This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:* CLJ-1388.patch

*Screened by:*
Alex Miller made changes -
Approval Vetted [ 10003 ] Incomplete [ 10006 ]
Nicola Mometto made changes -
Attachment CLJ-1388v2.patch [ 12971 ]
Alex Miller made changes -
Description {code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2) ;; expected => {:a 1}
#user.a{:a 1}
{code}

This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:* CLJ-1388.patch

*Screened by:*
Depending on the type of the map passed to a record map constructor, records will not correctly compare for equality:

{code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2) ;; expected => {:a 1}
#user.a{:a 1}
{code}

*Cause:* The type of the map passed into the map constructor leaks into the __extmap, affecting equality comparison of the record. This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:*

*Screened by:*
Alex Miller made changes -
Description Depending on the type of the map passed to a record map constructor, records will not correctly compare for equality:

{code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2) ;; expected => {:a 1}
#user.a{:a 1}
{code}

*Cause:* The type of the map passed into the map constructor leaks into the __extmap, affecting equality comparison of the record. This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:*

*Screened by:*
Depending on the type of the map passed to a record map constructor, records will not correctly compare for equality:

{code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2) ;; expected => {:a 1}
#user.a{:a 1}
{code}

*Cause:* The type of the map passed into the map constructor leaks into the __extmap, affecting equality comparison of the record. This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:* CLJ-1388-record-equality-and-map-record-factory.patch

*Screened by:*
Alex Miller made changes -
Approval Incomplete [ 10006 ] Screened [ 10004 ]
Description Depending on the type of the map passed to a record map constructor, records will not correctly compare for equality:

{code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2) ;; expected => {:a 1}
#user.a{:a 1}
{code}

*Cause:* The type of the map passed into the map constructor leaks into the __extmap, affecting equality comparison of the record. This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:* CLJ-1388-record-equality-and-map-record-factory.patch

*Screened by:*
Depending on the type of the map passed to a record map constructor, records will not correctly compare for equality:

{code}
user> (defrecord a [])
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2) ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2) ;; expected => {:a 1}
#user.a{:a 1}
{code}

*Cause:* The type of the map passed into the map constructor leaks into the __extmap, affecting equality comparison of the record. This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

*Approach:* Clean the extmap before putting it into the record constructor.

*Patch:* CLJ-1388-record-equality-and-map-record-factory.patch

*Screened by:* Alex Miller
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: