HubSpot / jinjava

Jinja template engine for Java
Apache License 2.0
690 stars 168 forks source link

Use a flag to prevent hashCode recursion in PyList or PyMap #1112

Closed jasmith-hs closed 1 year ago

jasmith-hs commented 1 year ago

Solves the same problem as https://github.com/HubSpot/jinjava/pull/1111. This demonstrates a different approach where a semaphore is used to ensure that a PyList or PyMap cannot have hashCode() called for itself during its own hashCode() call.

jasmith-hs commented 1 year ago

Oh yeah, I could make the semaphore just a boolean. ThreadLocal is to make sure that PyList and PyMap can still have correct hashCode when done async

mattcoley commented 1 year ago

Given these are non-concurrent collections do we need to necessarily guarantee multi-threaded support for this hashcode operation? None of the other operations have any kind of locking guarantee in this case. I guess someone could throw in a concurrent map into a pymap and try to use it across multiple threads but that seems pretty atypical for Jinjava use code.