Clojure

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

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Triaged

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 ]

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated: