Java code quality notes from the trenches.

Overview

Whether you are a newbie or an old hat Java programmer, you can save yourself some embarrassment by avoiding the below most common programming errors.

  1. Not serializing objects (and nested objects within) that are stored in HttpSession.
    • See Effective Java Second Edition (EJ2), Item 74
  2. Throwing generic exception instead of application specific exception.
    • See EJ2, Item 61
  3. Ignoring or swallowing a thrown Exception while re-throwing.
    • See EJ2, Item 63, 65
  4. Not overriding hashcode() when equals() is overridden.
    • See EJ2, Item 9
  5. Mutating static member via an instance member.
    • See EJ2, Item 15 and Item 66

Epilogue

All of these will be caught by any good code quality scanner. Please use one.