dom-top icon indicating copy to clipboard operation
dom-top copied to clipboard

Nullpointer exception in particular configuration

Open jeroenvandijk opened this issue 2 years ago • 0 comments

I found a scenario where I'm getting a Nullpointer exception for a certain configuration.

The following works:

(let [deps0 [{:provides #{:a}}
             {}]]
  (loopr [deps {}]
         [current-dep deps0
          k (:provides current-dep)]
         (recur (assoc deps k current-dep)))) ;=> {:a {:provides #{:a}}}

Adapting the above with one extra accumulator arg2 now throws.

(let [deps0 [{:provides #{:a}}
             {}]]
  (loopr [deps {}
          arg2 {}]
         [current-dep deps0
          k (:provides current-dep)]
         (recur (assoc deps k current-dep) arg2))) ;=> throws NullPointerException

Adding a default value [] works around this issue:

(let [deps0 [{:provides #{:a}}
             {}]]
  (loopr [deps {}
          arg2 {}]
         [current-dep deps0
          k (:provides current-dep [])]
         (recur (assoc deps k current-dep) arg2)))  ;=> [{:a {:provides #{:a}}} {}]

jeroenvandijk avatar Feb 13 '23 15:02 jeroenvandijk