[MAGNOLIA-5123] Order of search results mixed up by NodeUtil Created: 19/Jun/13  Updated: 25/Jul/13  Resolved: 24/Jul/13

Status: Closed
Project: Magnolia
Component/s: core, templating
Affects Version/s: 4.5.8
Fix Version/s: 4.5.10, 5.0.1

Type: Bug Priority: Critical
Reporter: Will Scheidegger Assignee: Milan Divilek
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 0.5h
Time Spent: Not Specified
Original Estimate: 0.5h

Attachments: Text File NodeUtil.patch    
Issue Links:
relation
is related to MAGNOLIA-5198 Deprecated obsolete NodeUtil.getSorte... Closed
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

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.



 Comments   
Comment by Jaroslav Simak [ 24/Jul/13 ]

Reopened: IMHO getSortedCollectionFromNodeIterator should be marked as deprecated because it is really not sorting elements.

Comment by Milan Divilek [ 24/Jul/13 ]

getSortedCollectionFromNodeIterator will be deprecated at MAGNOLIA-5198.

Generated at Mon Feb 12 04:02:12 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.