Posts tagged code smell
Case insensitive Map key – code smell
Sep 23rd
Here’s the bug that had me working today (a Sukot holiday):
_myMap.put(key.toLowerCase())
...
_myMap.get(key) // without lower casing the key.
At first you might think of this as a common human error, but I claim that it’s no less of a code smell:
Why trust yourself to always remember to lower/upper case all of the interactions with the map? What about trusting others?
So, instead of using a HashMap, use an Apache CaseInsensitiveMap that nicely and safely encapsulates this key’s case concern.
P.S.
I would expect CaseInsensitiveMap to become a part of the Java SDK.

Via e-mail