Clojure

array-map fails lazily if passed an odd number of arguments

Details

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

Description

If called with an odd number of arguments, array-map does not throw an exception until the map is realized, when it throws the confusing ArrayIndexOutOfBoundsException.

Example, in 1.5.1 and 1.6.0-alpha3:

user=> (def m (hash-map :a 1 :b))
IllegalArgumentException No value supplied for key: :b  clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)

user=> (def m (array-map :a 1 :b))
#'user/m
user=> (prn m)
ArrayIndexOutOfBoundsException 3
  clojure.lang.PersistentArrayMap$Seq.first
  (PersistentArrayMap.java:313)

Approach: Catch on construction and throw same error as hash-map.

user=> (def m (array-map :a 1 :b))
IllegalArgumentException No value supplied for key: :b  clojure.lang.PersistentArrayMap.createAsIfByAssoc (PersistentArrayMap.java:78)

Patch: 0002-CLJ-1319-Throw-on-odd-arguments-to-PersistentArrayMa.patch
Screened by: Alex Miller

Activity

Jason Felice made changes -
Field Original Value New Value
Attachment 0001-CLJ-1319-Throw-on-odd-arguments-to-PersistentArrayMa.patch [ 12724 ]
Andy Fingerhut made changes -
Patch Code and Test [ 10002 ]
Alex Miller made changes -
Approval Triaged [ 10120 ]
OHTA Shogo made changes -
Alex Miller made changes -
Description If called with an odd number of arguments, {{array-map}} does not throw an exception until the map is realized, when it throws the confusing {{ArrayIndexOutOfBoundsException}}.

Example, in 1.5.1 and 1.6.0-alpha3:

{code}
user=> (def m (array-map :a 1 :b))
#'user/m

user=> (prn m)
ArrayIndexOutOfBoundsException 3
  clojure.lang.PersistentArrayMap$Seq.first
  (PersistentArrayMap.java:313)
{code}
If called with an odd number of arguments, {{array-map}} does not throw an exception until the map is realized, when it throws the confusing {{ArrayIndexOutOfBoundsException}}.

Example, in 1.5.1 and 1.6.0-alpha3:

{code}
user=> (def m (hash-map :a 1 :b))
IllegalArgumentException No value supplied for key: :b clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)

user=> (def m (array-map :a 1 :b))
#'user/m
user=> (prn m)
ArrayIndexOutOfBoundsException 3
  clojure.lang.PersistentArrayMap$Seq.first
  (PersistentArrayMap.java:313)
{code}

*Approach:* Catch on construction and throw same error as hash-map.

{code}
user=> (def m (array-map :a 1 :b))
IllegalArgumentException No value supplied for key: :b clojure.lang.PersistentArrayMap.createAsIfByAssoc (PersistentArrayMap.java:78)
{code}

*Patch:* 0002-CLJ-1319-Throw-on-odd-arguments-to-PersistentArrayMa.patch
*Screened by:* Alex Miller
Labels errormsgs errormsgs ft
Alex Miller made changes -
Issue Type Enhancement [ 4 ] Defect [ 1 ]
Rich Hickey made changes -
Approval Triaged [ 10120 ] Vetted [ 10003 ]
Fix Version/s Release 1.8 [ 10254 ]
Alex Miller made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: