Menu

AntiPattern

Oliver Boehm

Overview

You can classify anti-pattern in different categories. They do not only exist for software development but also e.g. for project management. Because PatternTesting is a framework for developer we look only at those anti-pattern where PatternTesting can help you. But we will also take a look into other detectors which are common in many Java projects and helps you to find such code smells.

  1. Design Anti-Pattern
    • These are architecturally anti-pattern where PatternTesting cannot do much for you. This is mainly the operation area of code metrics tool like jdepend or Sonar/ comes in.
  2. Code Smells
    • PatternTesting is a framework which helps you to write better code. This chapter lists some antipattern which are recognized by PatternTesting or where PatternTesting helps you to avoid them.
  3. Methodological
    • These are anti-pattern like copy-and-paste programming which happens often if you have lazy or unexperienced programmers.

For a detailed description of the antipatterns follow the link in the tables.

Design Anti-Pattern

Anti-Pattern Short Description Detectors
Spaghetti Code compact code with missing structures, hard to read JDepend, Sonar, ...

Code Smells

Exception Handling

Anti-Pattern Short Description Detectors
[PrintStackTrace Logging] inside the execpion handler there is only a e.printStackTrace() statement patterntesting-check-ct, PMD
[Throwing Exception] a meaningless exception is thrown instead of a checked exception patterntesting-check-ct, PMD
[Log & Throw] an exception is logged and thrown -
[Destructive wrapping] in the exception handler another exception is thrown without the original exception as cause] PMD
[Catch & Ignore] an exception handler which does nothing -
Illegal IllegalArgumentException an construtor or method with no arguments but which can throw an IllegalArgumentException -

Logging and Debugging

Anti-Pattern Short Description Detectors
[System.out-Logging] logging is done using System.out or System.err patterntesting-check-ct, PMD
[Not overriding toString()] the Object.toString() method is not overwitten patterntesting-rt

Others

Anti-Pattern Short Description Detectors
Broken Initialization (NoClassDefFoundError) instantiation of class fails during initialization patterntesting-rt
Faulty Default Generation generated code is wrong patterntesting-rt
Lava Flow also known as Dead Code patterntesting-rt
[Not Yet Implemented] implementation of a method is not yet finished patterntesting-rt
[incorrect equals() and hashCode()] the hashCode contract was violated, equals() and hashCode() should only rely on the internal state of an object and other errors patterntesting-rt, FindBugs
[Untested Serializable] the class implements Serializable but there is no test to verify it patterntesting-rt, FindBugs, PMD
Transient Trap there are some traps if you define transient attributes patterntesting-check-ct, FindBugs
Null Flag null values are used as flags for exceptional conditions patterntesting-check-rt
[System.out-Logging] logging is done using System.out or System.err patterntesting-check-ct, PMD
[Undefined Encoding] the encoding is not defined and depends on the used OS or environment patterntesting-check-ct, FindBugs,
[Underscores] don't use underscores in Java names patterntesting-check-ct

Methodological

Anti-Pattern Short Description Detectors
[Copy and Paste Programming] Copying (and modifying) code instead of creating a more generic solution CPD
[Reinventing the Wheel] ignoring libraries and solutions which already exists -

Detectors

Not only PatternTesting can detect code smells. There are other tools available which does static code analysis to find possible errors:

The strength of PatternTesting is the support of dynamic code analysis. To do that there are several sub projects:

  • PatternTesting Runtime (patterntesting-rt)
  • PatternTesting Check-Runtime (patterntesting-check-rt)
  • PatternTesting Check-Compile-Time (patterntesting-check-ct)
  • PatternTesting Exception (patterntesting-exception)

Related

Wiki: MainPage

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.