Clojure

check that argument to keys/vals is a Map

Details

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

Description

Current behavior:

  • If you call keys or vals on something that is not a Map, you do not get a ClassCastException until the KeySeq or ValSeq is consumed
  • Calling keys or vals on an empty collection of any type, even non-Map types, returns nil

The attached patch:

  • checks the type of the argument to keys and vals and throws IllegalArgumentException if it is neither java.util.Map nor null
  • changes tests for keys and vals to check that those functions throw IllegalArgumentException on empty collections that are not maps

Activity

Hide
Rich Hickey added a comment -

Please don't test for specific exception types - thanks

Show
Rich Hickey added a comment - Please don't test for specific exception types - thanks
Hide
Stuart Sierra added a comment -

keys-vals-type-2.patch replaces previous. Tests check for Exception instead of IllegalArgumentException

Show
Stuart Sierra added a comment - keys-vals-type-2.patch replaces previous. Tests check for Exception instead of IllegalArgumentException

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: