<< Back to previous view

[CLJ-941] NullPointerException possible with seq-zip Created: 26/Feb/12  Updated: 19/Jun/17

Status: Open
Project: Clojure
Component/s: None
Affects Version/s: Release 1.3
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Greg Chapman Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: zip

Approval: Triaged


For example:

Clojure 1.3.0
user=> (require '[clojure.zip :as z])
user=> (-> (z/seq-zip (list 1)) z/down z/remove)
NullPointerException clojure.core/with-meta (core.clj:211)

Possibly the make-node function for seq-zip should be:

(fn [node children] (with-meta (or children ()) (meta node)))

Comment by Greg Chapman [ 26/Feb/12 5:54 PM ]

Also the docstring for zipper should probably be updated to indicate that the children parameter can be nil.

Comment by Christopher Brown [ 19/Jun/17 8:43 PM ]

4+ years later, I also ran into this.

Is there a workaround? I.e., is there a way to remove elements from singleton branches?

Comment by Alex Miller [ 19/Jun/17 9:35 PM ]

Would be happy to see a patch (although it also needs to backfill some tests too).

One workaround would be something like:

(-> (z/seq-zip (list 1)) (z/edit #(drop 1 %)) z/node)

Or you could use another zipper library like hara.zip which doesn't have remove, but works with delete-right:

(-> (z/seq-zip (list 1)) z/down z/delete-right z/up z/node)
Generated at Fri Jan 19 04:16:31 CST 2018 using JIRA 4.4#649-r158309.