keyword/symbol constructor behavior with nil is pretty inconsistent:
(keyword nil)
=> nil
(symbol nil)
Execution error (IllegalArgumentException) at user/eval7552 user.clj:1).
no conversion to symbol
(keyword nil nil)
Execution error (NullPointerException) at java.util.concurrent.ConcurrentHashMap/get (ConcurrentHashMap.java:936).
Cannot invoke "String.hashCode()" because "this.name" is null
(symbol nil nil)
=> null
1. should (keyword nil nil) have a better error message? The current one is pretty internal.
2. (symbol nil nil) generates null?! It should behave like keyword and throw.
3. (symbol nil) should return nil, as (keyword nil) ?!
In case of "please open an ask question", should it be 1 single question? or split in 3?I think all of this falls into the zone of “don’t do that, it is undefined”
Adding guards here affects construction of every keyword and symbol so these are not free
I guess I am wondering if there is something that happened where you encountered this, then I’m more interested in what that was
all this started with an empty stacktrace.
then I added -XX:-OmitStackTraceInFastThrow, got this NullPointerException, after look the stacktrace, i found the root cause (keyword "a" nil)
And how you ended up with that is the more interesting question
Inside a function defn add-kw-suffix [kw suffix]
(if (qualified-ident? k)
(keyword (namespace k)
(str (name k)
(when suffix
(str "-" suffix))))
(keyword
(str (name k)
(when suffix
(str "-" suffix)))))
But I wrote it wrong:
(keyword (namespace k)
(when suffix
(str "-" suffix)))
and then you got an NPE I assume
seems like the desired behavior to me
The symbol case is super funky here though, because
user=> (symbol "hello" nil)
hello/nullObviously this is a case of Should Not Happen™, but definitely an edge case to be aware of.