|
Julien's patch keeps an internal map of given keys to keys in lower case. So you call put("Foo", value), and the lowerCaseMap maps "foo" to "Foo", and then the "real" HashMap stores ("Foo", value).
I'm concerned about this patch, because every change has to happen in two phases: first you update lowerCaseMap, and THEN you update the real map; I strongly suspect that it's not thread-safe as a result. (I think the two maps can get out of sync, resulting in corruption.) More generally, I don't understand the point of this bug. Why do you need to retrieve the keys yourself? Fabio originally wrote "I had to map the database fields to a bean and the 'case' made it impossible" ... but we already have a system for mapping database fields to bean properties. It works fine (right?); it's clearly not "impossible." Liam helped me understand the point of this on the commons-dev list. Checked into "bugfixing" branch in revision 743269.
CaseInsensitiveHashMap ISN'T thread-safe, but then, neither is HashMap! So, uh, never mind. Hello, thanks for applying the patch!
I'd like to add some minor modifications: and for the putAll method, I should have used the entrySet instead of the keySet: public void putAll(Map m) { Iterator iter = m.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object key = entry.getKey(); Object value = entry.getValue(); this.put(key, value); } } Done in bugfixing branch revision 743292.
svn ci -m "Merging in Dab Fabulich's work on https://svn.apache.org/repos/asf/commons/sandbox/dbutils/bugfixing
Sending pom.xml |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Instead of converting the key to lower case before putting it into the map, I chose to keep the key as it was given, and maintain an internal mapping from lower case keys to real keys.
I join the whole BasicRowProcessor class, and the patch. (Some of the comments can be removed, it's just for the clarity of the code).