sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hans-Peter Stoerr (Jira)" <>
Subject [jira] [Created] (SLING-9312) Bug in LazyBindings.entrySet: hashCode of binding values is calculated
Date Tue, 31 Mar 2020 09:38:00 GMT
Hans-Peter Stoerr created SLING-9312:

             Summary: Bug in LazyBindings.entrySet: hashCode of binding values is calculated
                 Key: SLING-9312
             Project: Sling
          Issue Type: Bug
          Components: API
    Affects Versions: API 2.21.0, API 2.22.2
            Reporter: Hans-Peter Stoerr

The method entrySet in currently has a bug that
forces the hashCode of the entry values in Bindings are calculated in each HTL request, when
it should only be the hashCode of the keys - if at all. This can be a performance problem
if the value is e.g. a large map, in our (complicated) case this even got us a StackOverflowError.

The problematic code is:
    public Set<Entry<String, Object>> entrySet() {
        HashSet<Entry<String, Object>> entrySet = new HashSet<>(super.entrySet());
        for (Map.Entry supplierEntry : suppliers.entrySet()) {
        return Collections.unmodifiableSet(entrySet);
    } {code}
Since the entries are put together in a HashSet, each add will calculate the hashCode of the
entry - which sums the hashCode of the key *and the value* of each binding entry. I suggest
to replace this with a HashMap and return it's entrySet.

In case you are wondering, this is called in every HTL request like this:
         at java.base/java.util.HashSet.add(
          at java.base/java.util.AbstractCollection.addAll(
          at java.base/java.util.HashSet.<init>(
          at []
          at []
[] {code}


This message was sent by Atlassian Jira

View raw message