The code being fixed in this commit does not use proper syntax to specify :pre conditions. As a result, when any of the predicate functions are provided with the response parameter that is not a map, instead of throwing an assertion error, execution reaches (:status response) whereupon it produces NullPointerException.
This might cause confusion as to the origin of the error because the developer might not know or remember the proper syntax of the :pre conditions, and upon seeing that some code is present in the :pre header of the predicate functions they are using, they discard the possibility that it might be the response parameter they are providing to these functions that causes an error, assuming that the predicate functions take care of validating the proper type of the response parameter.
Judging from the way :pre condition gets added to the function definition, current implementation uses the syntax which doesn't fail to operate only because the assert function returns nil upon receiving a reference to a function and upon receiving the instance of the data type by itself, but the code does fail to fulfill its purpose, it doesn't really "work" as is.
;; part of code used to add pre to the body of the function:
(if pre
(concat (map (fn* [c] `(assert ~c)) pre)
body)
body)
;; testing `map` function above with invalid and valid :pre conditions:
;; - invalid:
(map (fn* [c]
(do
(println "this is c" c)
`(assert ~c))) '(map? "not-map"))
; this is c map?
; this is c not-map
((clojure.core/assert map?) ;; => nil
(clojure.core/assert "not-map") ;; = nil
)
;; - valid:
(map (fn* [c]
(do
(println "this is c" c)
`(assert ~c))) '[(map? "not-map")])
; this is c (map? not-map)
((clojure.core/assert (map? "not-map")
;; \\> Execution error (AssertionError) ... Assert failed: (map? "not-map")
))
The code being fixed in this commit does not use proper syntax to specify :pre conditions. As a result, when any of the predicate functions are provided with the
response
parameter that is not a map, instead of throwing an assertion error, execution reaches(:status response)
whereupon it producesNullPointerException
.This might cause confusion as to the origin of the error because the developer might not know or remember the proper syntax of the :pre conditions, and upon seeing that some code is present in the
:pre
header of the predicate functions they are using, they discard the possibility that it might be theresponse
parameter they are providing to these functions that causes an error, assuming that the predicate functions take care of validating the proper type of theresponse
parameter.Judging from the way
:pre
condition gets added to the function definition, current implementation uses the syntax which doesn't fail to operate only because theassert
function returnsnil
upon receiving a reference to a function and upon receiving the instance of the data type by itself, but the code does fail to fulfill its purpose, it doesn't really "work" as is.