Skip to content

[BUG] Fix problems in azure-spring-boot-service reported by sonar #23577

Description

@chenrujun

Context

We use sonar to check the code quality for all Spring Cloud Azure codes.

Goal

We should fix the issues in the report and finally make this report success.
Here is the summary report:
https://sonarcloud.io/summary/new_code?id=stliu_azure-sdk-for-java

Our goal is to achieve the following goals:

Sonar quality check Goal Current
Reliability 0 bugs 4 bugs
Security 0 vulnerabilities 0 vulnerabilities
Coverage 80% 67.4%
Maintainability A A
Security Review 0 security hotspots 1 security hotspots
Duplication 3% 5.6%

Solution

Sonar scan from the above report give us some hints of the code smells and bug issues. Upon the report, we list the issues that must-fix, can be ignored, and need discussion in the following.

The following issues are must-fix:

  1. magic number

  2. Use "==" to perform this enum comparison instead of using "equals"

  3. Access scope modifier, for example: protected ctor for abstract class

  4. Use the primitive boolean expression here.

  5. Add a private constructor to hide the implicit public one for Utility Class
    for example: AzureStorageUtils.java

  6. Either log this exception and handle it, or rethrow it with some contextual information.

  7. Complete the task associated to this TODO comment.
    For example: StorageFileResource.java(L220)

  8. Code cleaning.

The following issues need discussion:

Sonar report critical issues for the following code smells:

  1. code complexity reduce.
  2. deprecation usage of API.
  3. This class has 6 parents.
  4. Usage of generic wildcard type in return type.
  5. Fields in a "Serializable" class should either be transient or serializable. (Security issue)

The following issues are ignored:

  1. Define and throw a dedicated exception instead of using a generic one.

  2. magic number 1000 used as 1000 milliseconds, or parameter in Duration.ofMinutes(5);

  3. Add a constructor to the class, or provide default values.

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.azure-springAll azure-spring related issuesbugThis issue requires a change to an existing behavior in the product in order to be resolved.

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions