yazz.com
yazz.com

Reputation: 58786

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

I'm having trouble reproducing a bug where I get a null pointer exception when I call first 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

Upvotes: 0

Views: 724

Answers (2)

Arthur Ulfeldt
Arthur Ulfeldt

Reputation: 91554

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.

Upvotes: 2

amalloy
amalloy

Reputation: 92012

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)

Upvotes: 1

Related Questions