Clojure

calling hashCode on clojure.lang.LazyTransformer causes a StackOverflowError

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.7
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
  • Environment:
    OS X 10.10.1, Macbook Pro,, Java 1.8.0_11, Clojure 1.7.0-alpha4
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

Calling .hashCode on a an instance of clojure.lang.LazyTransformer causes a StackOverflowError:

user> (.hashCode (sequence (map identity) ["s"]))
StackOverflowError   clojure.lang.Util.hash (Util.java:161)

The trace is

Util.java:  161  clojure.lang.Util/hash
          LazyTransformer.java:  216  clojure.lang.LazyTransformer/hashCode
                     Util.java:  161  clojure.lang.Util/hash
          LazyTransformer.java:  216  clojure.lang.LazyTransformer/hashCode
                     Util.java:  161  clojure.lang.Util/hash
          LazyTransformer.java:  216  clojure.lang.LazyTransformer/hashCode
                     Util.java:  161  clojure.lang.Util/hash
          LazyTransformer.java:  216  clojure.lang.LazyTransformer/hashCode

Relevant lines:

https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazyTransformer.java#L212
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Util.java#L161

Cause: Looks like "seq" returns "this":

https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LazyTransformer.java#L55

This does NOT occur on an empty sequence, as clojure.core/sequence short-circuits.

Proposal: compute and cache hash and hasheq using same algorithm used in other seqs

Patch: CLJ-1600-2.patch

Screened by: Alex Miller

  1. CLJ-1600.patch
    25/Nov/14 1:18 AM
    2 kB
    Ghadi Shayban
  2. CLJ-1600-2.patch
    25/Nov/14 1:24 PM
    2 kB
    Ghadi Shayban

Activity

Hide
Ghadi Shayban added a comment - - edited

Patch with hashcode calculation and caching similar to ASeq. Might be worthwhile hoisting that into its own hashSeq method.

Show
Ghadi Shayban added a comment - - edited Patch with hashcode calculation and caching similar to ASeq. Might be worthwhile hoisting that into its own hashSeq method.
Hide
Alex Miller added a comment -

What's here looks good. Can we hook into existing tests that verify equals/hashcode and equiv/hasheq equivalence?

Show
Alex Miller added a comment - What's here looks good. Can we hook into existing tests that verify equals/hashcode and equiv/hasheq equivalence?
Hide
Ghadi Shayban added a comment -

Test case added. Verified case was failing with SO prior to patch.

Show
Ghadi Shayban added a comment - Test case added. Verified case was failing with SO prior to patch.

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: