You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Erik Godding Boye (JIRA)" <xm...@xml.apache.org> on 2006/03/08 13:37:42 UTC

[jira] Created: (XMLBEANS-252) List returned by generated getFooList() is not sortable

List<Type> returned by generated getFooList() is not sortable
-------------------------------------------------------------

         Key: XMLBEANS-252
         URL: http://issues.apache.org/jira/browse/XMLBEANS-252
     Project: XMLBeans
        Type: Bug
    Versions: Version 2.1    
 Environment: Win XP SP2, JRE 1.5.0_06-b05, XMLBeans 2.1.0
    Reporter: Erik Godding Boye
    Priority: Minor


I am trying to sort the list returned by the generated getFooList() [multiple occurrence method] using java.util.Collections#sort(java.util.List<Type>, java.util.Comparator<Type>). The elements are not sorted, and no exception is thrown. I would expect either, but I do not see any reason for the list to be unmodifiable (and thus throwing exception when trying to sort it). A simple workaround is to create a new list supplying the original list (from the generated method) in the constructor. The new list is sortable without any problems.

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Resolved: (XMLBEANS-252) List returned by generated getFooList() is not sortable

Posted by "Radu Preotiuc-Pietro (JIRA)" <xm...@xml.apache.org>.
     [ https://issues.apache.org/jira/browse/XMLBEANS-252?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Radu Preotiuc-Pietro resolved XMLBEANS-252.
-------------------------------------------

    Resolution: Won't Fix

I am afraid we can't fix this one.

In XMLBeans, an XmlObject can be seen as a pointer to a place in the document. When one does

    List l = parent.getFooList();
    XmlObject o = l.get(1),

the elements in the list are pointers to the XML elements in the document. When one sets the content of the first element to some value, say

    parent.setFooArray(1, o2)

then o will point to an element whose content has now changed (you don't even need an array to observe this). In particular, in the sort case if you have

    XmlObject o1 = l.get(1);
    XmlObject o2 = l.get(2);
    l.set(1, o2);

after these operations, o1 has the same contents as o2 and if one wants a swap, then one needs to do:

    XmlObject o1 = l.get(1).copy();
    XmlObject o2 = l.get(2);
    l.set(1, o2);
    l.set(2, o1);

I know that it is kind of unintuitive, but this is how it always worked. I think between a change in behavior that will potentially cause pain to people who want to upgrade and depend (perhaps unknowkingly) on the existing behavior and a simple workaround for people who need this functionality, I would choose the latter.

So if one needs to sort the array "for read", one can do

List l2 = new ArrayList(l);

If one wants to sort the elements in the document, then one would do

List l2 = new ArrayList(l.size());
for (int i=0; i<l.size(); i++)
    l2.add(l.get(i).copy());
Collections.sort(l2);
parent.setFooArray(l2.toArray());


> List<Type> returned by generated getFooList() is not sortable
> -------------------------------------------------------------
>
>                 Key: XMLBEANS-252
>                 URL: https://issues.apache.org/jira/browse/XMLBEANS-252
>             Project: XMLBeans
>          Issue Type: Bug
>    Affects Versions: Version 2.1
>         Environment: Win XP SP2, JRE 1.5.0_06-b05, XMLBeans 2.1.0
>            Reporter: Erik Godding Boye
>            Priority: Critical
>
> I am trying to sort the list returned by the generated getFooList() [multiple occurrence method] using java.util.Collections#sort(java.util.List<Type>, java.util.Comparator<Type>). The elements are not sorted, and no exception is thrown. I would expect either, but I do not see any reason for the list to be unmodifiable (and thus throwing exception when trying to sort it). A simple workaround is to create a new list supplying the original list (from the generated method) in the constructor. The new list is sortable without any problems.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Updated: (XMLBEANS-252) List returned by generated getFooList() is not sortable

Posted by "Adrian Grealish (JIRA)" <xm...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XMLBEANS-252?page=all ]

Adrian Grealish updated XMLBEANS-252:
-------------------------------------

    Priority: Major  (was: Minor)

> List<Type> returned by generated getFooList() is not sortable
> -------------------------------------------------------------
>
>                 Key: XMLBEANS-252
>                 URL: http://issues.apache.org/jira/browse/XMLBEANS-252
>             Project: XMLBeans
>          Issue Type: Bug
>    Affects Versions: Version 2.1
>         Environment: Win XP SP2, JRE 1.5.0_06-b05, XMLBeans 2.1.0
>            Reporter: Erik Godding Boye
>
> I am trying to sort the list returned by the generated getFooList() [multiple occurrence method] using java.util.Collections#sort(java.util.List<Type>, java.util.Comparator<Type>). The elements are not sorted, and no exception is thrown. I would expect either, but I do not see any reason for the list to be unmodifiable (and thus throwing exception when trying to sort it). A simple workaround is to create a new list supplying the original list (from the generated method) in the constructor. The new list is sortable without any problems.

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

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Updated: (XMLBEANS-252) List returned by generated getFooList() is not sortable

Posted by "Adrian Grealish (JIRA)" <xm...@xml.apache.org>.
     [ http://issues.apache.org/jira/browse/XMLBEANS-252?page=all ]

Adrian Grealish updated XMLBEANS-252:
-------------------------------------

    Priority: Critical  (was: Major)

> List<Type> returned by generated getFooList() is not sortable
> -------------------------------------------------------------
>
>                 Key: XMLBEANS-252
>                 URL: http://issues.apache.org/jira/browse/XMLBEANS-252
>             Project: XMLBeans
>          Issue Type: Bug
>    Affects Versions: Version 2.1
>         Environment: Win XP SP2, JRE 1.5.0_06-b05, XMLBeans 2.1.0
>            Reporter: Erik Godding Boye
>            Priority: Critical
>
> I am trying to sort the list returned by the generated getFooList() [multiple occurrence method] using java.util.Collections#sort(java.util.List<Type>, java.util.Comparator<Type>). The elements are not sorted, and no exception is thrown. I would expect either, but I do not see any reason for the list to be unmodifiable (and thus throwing exception when trying to sort it). A simple workaround is to create a new list supplying the original list (from the generated method) in the constructor. The new list is sortable without any problems.

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

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Commented: (XMLBEANS-252) List returned by generated getFooList() is not sortable

Posted by "Adrian Grealish (JIRA)" <xm...@xml.apache.org>.
    [ http://issues.apache.org/jira/browse/XMLBEANS-252?page=comments#action_12431326 ] 
            
Adrian Grealish commented on XMLBEANS-252:
------------------------------------------

I am seeing a similar issue except duplicates in the list after sorting.

When I sort a list returned from getFooList() using Collections.sort I am getting a duplicate in the list and teh collection size does not change.

If I try to sort list "aPLugin", "bPlugin", "cPLugin"

List<Plugin> pluginsList = xmlPlugins.getPluginList());
Collections.sort(pluginsList , new Comparator<Plugin>() {
                   public int compare(Plugin o1, Plugin o2) {
                           return o1.getName().compareTo(o2.getName());
                   }});


I get back plugins "aPLugin", "bPlugin", "aPLugin".

Plugins.getPluginList() (actually PluginsImpl.getPluginList()) returns a PluginList, which extends AbstractList<com.bea.usagetrack.protocol.v100.Plugin>. PluginList's get() and set() methods do some twisty stuff that looks like it should work for sort(), but obviously doesn't. Looks like some indirection in PluginsImpl is biting us for the sort().

If I create a new ArrayList first then it works

List<Plugin> newList = new ArrayList<Plugin>(xmlPlugins.getPluginList());
Collections.sort(newList, new Comparator<Plugin>() {
                      public int compare(Plugin o1, Plugin o2) {
                                 return o1.getName().compareTo(o2.getName());
                      }});




> List<Type> returned by generated getFooList() is not sortable
> -------------------------------------------------------------
>
>                 Key: XMLBEANS-252
>                 URL: http://issues.apache.org/jira/browse/XMLBEANS-252
>             Project: XMLBeans
>          Issue Type: Bug
>    Affects Versions: Version 2.1
>         Environment: Win XP SP2, JRE 1.5.0_06-b05, XMLBeans 2.1.0
>            Reporter: Erik Godding Boye
>            Priority: Minor
>
> I am trying to sort the list returned by the generated getFooList() [multiple occurrence method] using java.util.Collections#sort(java.util.List<Type>, java.util.Comparator<Type>). The elements are not sorted, and no exception is thrown. I would expect either, but I do not see any reason for the list to be unmodifiable (and thus throwing exception when trying to sort it). A simple workaround is to create a new list supplying the original list (from the generated method) in the constructor. The new list is sortable without any problems.

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

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[jira] Commented: (XMLBEANS-252) List returned by generated getFooList() is not sortable

Posted by "Radu Preotiuc-Pietro (JIRA)" <xm...@xml.apache.org>.
    [ https://issues.apache.org/jira/browse/XMLBEANS-252?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12585328#action_12585328 ] 

Radu Preotiuc-Pietro commented on XMLBEANS-252:
-----------------------------------------------

I am able to reproduce this on my box; looking into it to see if I can fix.

> List<Type> returned by generated getFooList() is not sortable
> -------------------------------------------------------------
>
>                 Key: XMLBEANS-252
>                 URL: https://issues.apache.org/jira/browse/XMLBEANS-252
>             Project: XMLBeans
>          Issue Type: Bug
>    Affects Versions: Version 2.1
>         Environment: Win XP SP2, JRE 1.5.0_06-b05, XMLBeans 2.1.0
>            Reporter: Erik Godding Boye
>            Priority: Critical
>
> I am trying to sort the list returned by the generated getFooList() [multiple occurrence method] using java.util.Collections#sort(java.util.List<Type>, java.util.Comparator<Type>). The elements are not sorted, and no exception is thrown. I would expect either, but I do not see any reason for the list to be unmodifiable (and thus throwing exception when trying to sort it). A simple workaround is to create a new list supplying the original list (from the generated method) in the constructor. The new list is sortable without any problems.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org