The title is misleading - there's no NPE here, only class cast exception.
There is a stack trace (notice how I used *e
in my REPL to print the latest exception):
Clojure 1.11.1
user=> (filter zero? [:hi])
Error printing return value (ClassCastException) at clojure.lang.Numbers/isZero (Numbers.java:119).
class clojure.lang.Keyword cannot be cast to class java.lang.Number (clojure.lang.Keyword is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')
(user=>
user=> *e
#error {
:cause "class clojure.lang.Keyword cannot be cast to class java.lang.Number (clojure.lang.Keyword is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')"
:via
[{:type clojure.lang.ExceptionInfo
:message nil
:data #:clojure.error{:phase :print-eval-result}
:at [clojure.main$repl$read_eval_print__9206 invoke "main.clj" 442]}
{:type java.lang.ClassCastException
:message "class clojure.lang.Keyword cannot be cast to class java.lang.Number (clojure.lang.Keyword is in unnamed module of loader 'app'; java.lang.Number is in module java.base of loader 'bootstrap')"
:at [clojure.lang.Numbers isZero "Numbers.java" 119]}]
:trace
[[clojure.lang.Numbers isZero "Numbers.java" 119]
[clojure.core$zero_QMARK_ invokeStatic "core.clj" 874]
[clojure.core$zero_QMARK_ invoke "core.clj" 869]
[clojure.core$filter$fn__5962 invoke "core.clj" 2834]
[clojure.lang.LazySeq sval "LazySeq.java" 42]
[clojure.lang.LazySeq seq "LazySeq.java" 51]
[clojure.lang.RT seq "RT.java" 535]
[clojure.core$seq__5467 invokeStatic "core.clj" 139]
[clojure.core$print_sequential invokeStatic "core_print.clj" 53]
[...]
So it seems that either the tools that you're using with Clojure hide it from you for some reason (in which case knowing the exact steps you perform to not get a stacktrace would be helpful) or you didn't look in the right place.
And in case you mean that the stacktrace seems to be pointing away from where you call filter
- that's because filter
doesn't actually filter anything, it creates a lazy seq that filters things out when it's being iterated over. So the stacktrace will might not include where filter
is called but will include where the resulting lazy seq is being realized.