You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Michael Pradel (Created) (JIRA)" <ji...@apache.org> on 2012/02/29 15:49:57 UTC

[jira] [Created] (COLLECTIONS-394) FastTreeMap is not compatible with TreeMap

FastTreeMap is not compatible with TreeMap
------------------------------------------

                 Key: COLLECTIONS-394
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-394
             Project: Commons Collections
          Issue Type: Bug
          Components: Map
    Affects Versions: 3.2.1
         Environment: all
            Reporter: Michael Pradel


FastTreeMap extends TreeMap in a way that doesn't preserve the superclass behavior. For example, the following code prints 'null', but I would expect it to print '1=1', which is what TreeMap does:

TreeMap map = new FastTreeMap();
//TreeMap map = new TreeMap();

map.put(1, "1");
map.put(3, "3");
		
Entry e = map.floorEntry(2);
System.out.println(e);

This behavior is surprising and can hit you every time a reference of type TreeMap refers to an instance of FastTreeMap. A subclass instance used through a superclass interface shouldn't change the visible behavior of its superclass.

The reason for this problem seems to be that FastTreeMap both extends TreeMap and delegates to a TreeMap via the 'map' field. I.e., there are  two map instances for a single FastTreeMap instance.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (COLLECTIONS-394) FastTreeMap is not compatible with TreeMap

Posted by "Michael Pradel (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COLLECTIONS-394?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13220946#comment-13220946 ] 

Michael Pradel commented on COLLECTIONS-394:
--------------------------------------------

It seems the problem affects several other methods in FastTreeMap, specifically methods that have been added to TreeMap in Java 1.6. E.g. TreeMap.headMap(K) existed before Java 1.6 and is overridden by FastTreeMap, while TreeMap.headMap(K, boolean) got added in Java 1.6. and is not overridden by FastTreeMap. All inherited methods do not refer to the 'map' field, and therefore use the wrong map.

One way to fix these problems is to override all public methods from TreeMap in FastTreeMap. Since I'm not familiar with FastTreeMap's implementation, I'll leave this task to someone more experienced with the Commons Collections.
                
> FastTreeMap is not compatible with TreeMap
> ------------------------------------------
>
>                 Key: COLLECTIONS-394
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-394
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Map
>    Affects Versions: 3.2.1
>         Environment: all
>            Reporter: Michael Pradel
>
> FastTreeMap extends TreeMap in a way that doesn't preserve the superclass behavior. For example, the following code prints 'null', but I would expect it to print '1=1', which is what TreeMap does:
> TreeMap map = new FastTreeMap();
> //TreeMap map = new TreeMap();
> map.put(1, "1");
> map.put(3, "3");
> 		
> Entry e = map.floorEntry(2);
> System.out.println(e);
> This behavior is surprising and can hit you every time a reference of type TreeMap refers to an instance of FastTreeMap. A subclass instance used through a superclass interface shouldn't change the visible behavior of its superclass.
> The reason for this problem seems to be that FastTreeMap both extends TreeMap and delegates to a TreeMap via the 'map' field. I.e., there are  two map instances for a single FastTreeMap instance.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (COLLECTIONS-394) FastTreeMap is not compatible with TreeMap

Posted by "Thomas Neidhart (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COLLECTIONS-394?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Neidhart resolved COLLECTIONS-394.
-----------------------------------------

       Resolution: Won't Fix
    Fix Version/s: 4.0

The FastTreeMap class has been removed from trunk.

There is no drop-in replacement, but one can use a ConcurrentHashMap from the java.util.concurrent package or a synchronized TreeMap.

Please open new issue if you would like to have an equivalent class in collections 4.0.
                
> FastTreeMap is not compatible with TreeMap
> ------------------------------------------
>
>                 Key: COLLECTIONS-394
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-394
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Map
>    Affects Versions: 3.2.1
>         Environment: all
>            Reporter: Michael Pradel
>             Fix For: 4.0
>
>
> FastTreeMap extends TreeMap in a way that doesn't preserve the superclass behavior. For example, the following code prints 'null', but I would expect it to print '1=1', which is what TreeMap does:
> TreeMap map = new FastTreeMap();
> //TreeMap map = new TreeMap();
> map.put(1, "1");
> map.put(3, "3");
> 		
> Entry e = map.floorEntry(2);
> System.out.println(e);
> This behavior is surprising and can hit you every time a reference of type TreeMap refers to an instance of FastTreeMap. A subclass instance used through a superclass interface shouldn't change the visible behavior of its superclass.
> The reason for this problem seems to be that FastTreeMap both extends TreeMap and delegates to a TreeMap via the 'map' field. I.e., there are  two map instances for a single FastTreeMap instance.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (COLLECTIONS-394) FastTreeMap is not compatible with TreeMap

Posted by "Gary D. Gregory (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COLLECTIONS-394?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13219256#comment-13219256 ] 

Gary D. Gregory commented on COLLECTIONS-394:
---------------------------------------------

Would you be willing to provide a patch for unit test and code?

Thank you.
                
> FastTreeMap is not compatible with TreeMap
> ------------------------------------------
>
>                 Key: COLLECTIONS-394
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-394
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Map
>    Affects Versions: 3.2.1
>         Environment: all
>            Reporter: Michael Pradel
>
> FastTreeMap extends TreeMap in a way that doesn't preserve the superclass behavior. For example, the following code prints 'null', but I would expect it to print '1=1', which is what TreeMap does:
> TreeMap map = new FastTreeMap();
> //TreeMap map = new TreeMap();
> map.put(1, "1");
> map.put(3, "3");
> 		
> Entry e = map.floorEntry(2);
> System.out.println(e);
> This behavior is surprising and can hit you every time a reference of type TreeMap refers to an instance of FastTreeMap. A subclass instance used through a superclass interface shouldn't change the visible behavior of its superclass.
> The reason for this problem seems to be that FastTreeMap both extends TreeMap and delegates to a TreeMap via the 'map' field. I.e., there are  two map instances for a single FastTreeMap instance.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira