#228 New Detector: Static HashMaps and HashSets

Take_a_look
open
Keith Lea
detectors (11)
5
2014-02-07
2010-04-28
Anonymous
No

Analogous to the Static Calendar Detector I created a static HashMap and HashSet Detector. Just today we (again) were hit by http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6423457 (causing 100% CPU in HashMap.get()). We needed to restart the whole app-server to get it working again.

I did not know how to detect assignments of HashMap to Map references, maybe someone could either add that or tell me how to do it.

Discussion


  • Anonymous
    2010-04-28

    New Detector class, patches for messages.xml, findbugs.xml and a test case file

     
    Attachments
  • Keith Lea
    Keith Lea
    2010-06-04

    Could you give us more context? There are definitely situations where you might want to have a static map/set. Was your code in a servlet?

     
  • Keith Lea
    Keith Lea
    2010-06-04

    • assigned_to: nobody --> kano
    • status: open --> closed-out-of-date
     
  • Keith Lea
    Keith Lea
    2010-06-04

    oops! accidentally marked "out of date."

     
  • Keith Lea
    Keith Lea
    2010-06-04

    • status: closed-out-of-date --> open
     
  • David Harkness
    David Harkness
    2014-02-07

    Given that the original problem has been declared "pilot error," we should probably close this. From the end of the linked bug report:

    EVALUATION

    Doug Lea writes:

    "This is a classic symptom of an incorrectly synchronized use of HashMap. Clearly, the submitters need to use a thread-safe HashMap. If they upgraded to Java 5, they could just use ConcurrentHashMap. If they can't do this yet, they can use either the pre-JSR166 version, or better, the unofficial backport as mentioned by Martin. If they can't do any of these, they can use Hashtable or synchhronizedMap wrappers, and live with poorer performance. In any case, it's not a JDK or JVM bug."

    I agree that the presence of a corrupted data structure alone does not indicate a bug in the JDK.