You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Julien Aymé (JIRA)" <ji...@apache.org> on 2011/03/11 20:03:59 UTC

[jira] Commented: (COLLECTIONS-323) Behavior of constructors CaseInsensitiveMap inconsistent with standard Java HashMap

    [ https://issues.apache.org/jira/browse/COLLECTIONS-323?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13005786#comment-13005786 ] 

Julien Aymé commented on COLLECTIONS-323:
-----------------------------------------

Why not for the LRUMap?
If I use the map like this:

{code}
List<Bean> list = ...; // Load list from db
Map<String, Bean> map = new LRUMap(list.size());
for (Bean bean : list) {
    map.put(bean.getUserKey(), bean);
}
{code}
I wouldn't want this code to throw an IAE if the list is empty.
The initial capacity is a hint, not the real initial capacity for the map (see HashMap constructor doc comment).


> Behavior of constructors CaseInsensitiveMap inconsistent with standard Java HashMap
> -----------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-323
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-323
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Map
>    Affects Versions: 3.2
>         Environment: Any
>            Reporter: Maarten Brak
>            Assignee: Jochen Wiedmann
>            Priority: Minor
>             Fix For: 3.2.2
>
>         Attachments: patch.tar.gz
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> The constructor CaseInsensitiveMap(int initialCapacity) throws an IllegalArgumentException if "the initial capacity is less than one". This is inconsistent with the standard Java HashMap constructor HashMap(int initialCapacity), which throws an if IllegalArgumentException if "the initial capacity is negative".
> Thus:
> new HashMap(0) ==> no exception
> new CaseInsensitiveMap(0) ==> IllegalArgumentException.
> This inconsistency is confusing.
> Actions:
> - Change Javadoc (this shouldn't be a problem in practice since surely there is no code around depending on the fact that the constructor throws an IllegalArgumentException :-))
> - Change code.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira