Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-5123

Order of search results mixed up by NodeUtil

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • 4.5.10, 5.0.1
    • 4.5.8
    • core, templating
    • None

      The NodeUtil.getCollectionFromNodeIterator(NodeIterator iterator) converts the NodeIterator object to a Collection of Node objects. Unfortunately it uses a java.util.HashSet() for this, which totally mixes up the order of elements (see http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html). Quote:

      "It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time."

      If you use an ArrayList instead of a HashSet, everything's fine.

      Steps to reproduce the bug:

      1. Create some more "Contact" records in the Data module
      2. Create a new stkContacts component with this template:

      [#assign contacts = cmsfn.search("data", "/jcr:root/contacts//element(*,Contact)", "xpath", "Contact")! /]
      <ul>
        [#list contacts as contact]
        [#assign contactMap = cmsfn.asContentMap(contact) /]
        <li>${contact}</li>
        [/#list]
      </ul>
      

      3. Add the component to a page and reload the page a few times. Each time you reload, the order of the nodes will change.

        Acceptance criteria

              mdivilek Milan Divilek
              will Will Scheidegger
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD

                    Estimated:
                    Original Estimate - 0.5h
                    0.5h
                    Remaining:
                    Remaining Estimate - 0.5h
                    0.5h
                    Logged:
                    Time Spent - Not Specified
                    Not Specified