开发者

In clojure get "null pointer exception" when doing (first)

开发者 https://www.devze.com 2023-02-19 06:14 出处:网络
I\'m having trouble reproducing a bug where I get a null pointer exception when I call firs开发者_StackOverflow社区t on a PersistentArrayMap. If I copy and paste the map and call first it works, but w

I'm having trouble reproducing a bug where I get a null pointer exception when I call firs开发者_StackOverflow社区t on a PersistentArrayMap. If I copy and paste the map and call first it works, but when the map is in a ref it doesn't work. Is this some weird behaviour related to laziness (not my own) ?

Update: I cannot produce an example that fails every time, so I am forcing evaluation of everything now and it seems to work


my general game plan when i suspect that i may have been bitten by the lazy bug is to

put doseq around everything until the point of failure starts changing.

ps: pasting a stack trace would help give better answers.


Calling first can never cause an NPE, so the problem is elsewhere. My guess is you tried to deref a ref which was nil:

user=> (first @nil)
java.lang.NullPointerException (NO_SOURCE_FILE:0)
0

精彩评论

暂无评论...
验证码 换一张
取 消