Record some common or typical problems, some old code problems, some you are not aware of.

bug

  • NullPointerException

    A lot of it is because of the use of tool class judgment, sonar did not scan out the misjudgment, this situation can be new rules

    Refer to the official website, not verified

  • The random number

public void doSomethingCommon(a) {
  Random rand = new Random();  // Noncompliant; new instance created with each invocation
  int rValue = rand.nextInt();
  / /...
Copy the code
private Random rand = SecureRandom.getInstanceStrong();  // SecureRandom is preferred to Random

public void doSomethingCommon(a) {
  int rValue = this.rand.nextInt();
  / /...
Copy the code

vulnerability

security

SSLContext. GetInstance (” TLSv1.2 “)

TLS — — > TLSv1.2

log

e.printStackTrace()

System.out.print()

Change to –> Slf4j write file log format

The smell

Non-analytic comments, such as unwanted code comments, should be removed and can be recorded in Git if you want to retrieve the previous code.

repeat

Separate duplicate lines of code

coverage

Unit testing