The java.util.HashMap sets the initial capacity to the smallest power of 2 greater than or equal to the supplied initialCapacity. Thus if an initialCapacity of 0 is provided, then the initial capacity will be 1.

Therefore, it is consistent with java.util.HashMap to accept an argument of zero for initialCapacity but in fact have an initial capacity of one.

Paul Wolfgang


On 3/12/2011 1:30 PM, Jochen Wiedmann (JIRA) wrote:
     [ 
https://issues.apache.org/jira/browse/COLLECTIONS-323?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13006073#comment-13006073
 ]

Jochen Wiedmann commented on COLLECTIONS-323:
---------------------------------------------

Quoting from the initial bug report: "This is inconsistent with the standard Java 
HashMap constructor HashMap(int initialCapacity),"

I had to choose between consistency (incrementing the size by one) and the 
current behaviour. The latter made much more sense to me and I can think of no 
reason why one would intentionally create an LRUMap of size 0. The 
IllegalArgumentException makes perfect sense to me.


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

Reply via email to