Clojure 1.2.0-master-SNAPSHOT
user=> (defprotocol Greeter (greet [this]))
Greeter
user=> (satisfies? Greeter nil)
false
user=> (satisfies? Greeter "")
false
user=> (satisfies? Greeter (Object.))
java.lang.NullPointerException (NO_SOURCE_FILE:0)
Narrowed it down to this function:
;; core_deftype.clj
(defn find-protocol-impl [protocol x]
(if (instance? (:on-interface protocol) x)
x
(let [c (class x)
impl #(get (:impls protocol) %)]
(or (impl c)
(and c (or (first (remove nil? (map impl (butlast (super-chain c)))))
(when-let [t (reduce pref (filter impl (disj
(supers c) Object)))]
(impl t))
(impl Object)))))))
More specifically, here:
(disj (supers c) Object)
Since in this case, `c` is java.lang.Object, supers returns nil which
disj doesn't seem to like. Shouldn't disj handle nil gracefully?
Thanks,
Allen
On May 27, 1:10 am, Allen Johnson <akjohnso...@gmail.com> wrote:
> Hey everyone. I was playing around with the protocols/deftype stuff
> and ran into a weird NullPointerException when calling the satisfies?
> function. Seems to only happen with a java.lang.Object instance.
>
> Clojure 1.2.0-master-SNAPSHOT
> user=> (defprotocol Greeter (greet [this]))
> Greeter
> user=> (satisfies? Greeter nil)
> false
> user=> (satisfies? Greeter "")
> false
> user=> (satisfies? Greeter (Object.))
> java.lang.NullPointerException (NO_SOURCE_FILE:0)
>
> Narrowed it down to this function:
>
> ;; core_deftype.clj
> (defn find-protocol-impl [protocolx]
> (if (instance? (:on-interfaceprotocol) x)
> x
> (let [c (class x)
> impl #(get (:implsprotocol) %)]
> (or (impl c)
> (and c (or (first (remove nil? (map impl (butlast (super-chain c)))))
> (when-let [t (reduce pref (filter impl (disj
> (supers c) Object)))]
> (impl t))
> (impl Object)))))))
>
> More specifically, here:
>
> (disj (supers c) Object)
>
> Since in this case, `c` is java.lang.Object, supers returns nil which
> disj doesn't seem to like. Shouldn't disj handle nil gracefully?
>
Yes, could you please enter a ticket for this?
Thanks,
Rich
https://www.assembla.com/spaces/clojure/support/tickets/360-nullpointerexception-on-disj
Thanks.