Special Cases

Warnings

  • Do not ignore compiler/IDE warnings

  • Each warning is a potential/existing bug

  • Do not suppress warnings - Find the correct solution instead

  • Use the capabilities of your IDE - Turn on most of the possible warnings

  • Do not add new code with warnings!

  • Use code checkers - CheckStyle, FindBugs, PMD, Sonar, etc.

Example: Bad: Suppressed warnings

// Many tricks for one unused parameter

// CHECKSTYLE:OFF
@SuppressWarnings("unused")
private void addDescription(Type type, Contract contract, String comment) { // NOSONAR
    contract.setDescription(createDescription(contract.getType(), comment));
}
// CHECKSTYLE:ON

Example: Good: Fixed problems

private void addDescription(Contract contract, String comment) {
    contract.setDescription(createDescription(contract.getType(), comment));
}

Logging

  • Use correct logging levels

  • Log stack trace only for unexpected program errors

  • Create (concatenate) expensive message only if logged - see SLF4J capabilities

Java

  • Never use raw types - always use generics correctly

  • Avoid using reflection

  • Know you API - use utility methods

Last updated