SimpleFeatureTypeImpl has inconsistent iteration order, broken equals/hashCode
------------------------------------------------------------------------------

                 Key: GEOT-2338
                 URL: http://jira.codehaus.org/browse/GEOT-2338
             Project: GeoTools
          Issue Type: Bug
          Components: core main
    Affects Versions: 2.6-M2
            Reporter: Ben Caradoc-Davies
            Assignee: Jody Garnett
         Attachments: SimpleFeatureTypeImpl.patch

SimpleFeatureTypeImpl returns its internal property descriptor list via 
getAttributeDescriptors(), but when accessed via the FeatureType API 
getDescriptors(), will return its property descriptors in a different order. 
ComplexTypeImpl (grandparent of SimpleFeatureTypeImpl) uses a HashMap to store 
descriptors, so getDescriptors(), which iterates over this Map, will return 
descriptors in a random order. This is *A Bad Thing*, because descriptor order 
is *very* significant for simple feature types. Furthermore, ComplexTypeImpl 
uses Map semantics for equals/hashCode, which is guaranteed to be order 
independent. This means that two SimpleFeatureTypeImpl instances with the same 
properties in a different order must be equal. This is also *A Very Bad Thing*.

Changing ComplexTypeImpl to use LinkedHashMap to fix the the iteration order 
will not fix the equals/hashCode problem. It is more straightforward and likely 
faster to override getDescriptors() to return the descriptors list. Likewise, 
equals and hashCode are easily fixed.

The attached patch:
(1) Fixes iteration order by ensuring getAttributeDescriptors() and 
getAttributeDescriptors() return the same immutable object.
(2) Makes these methods final to preserve the contract.
(3) Ensures the descriptors member is immutable by making it an unmodifiable 
copy.
(4) Adds unit tests for iteration order and equality.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to