Clojure

NullPointerException possible with seq-zip

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.3
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Approval:
    Triaged

Description

For example:

Clojure 1.3.0
user=> (require '[clojure.zip :as z])
nil
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)))

Activity

Hide
Alex Miller added a comment -

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)
Show
Alex Miller added a comment - 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)
Hide
Christopher Brown added a comment -

4+ years later, I also ran into this.

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

Show
Christopher Brown added a comment - 4+ years later, I also ran into this. Is there a workaround? I.e., is there a way to remove elements from singleton branches?
Hide
Greg Chapman added a comment -

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

Show
Greg Chapman added a comment - Also the docstring for zipper should probably be updated to indicate that the children parameter can be nil.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: