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:
-
magic number
-
Use "==" to perform this enum comparison instead of using "equals"
-
Access scope modifier, for example: protected ctor for abstract class
-
Use the primitive boolean expression here.
-
Add a private constructor to hide the implicit public one for Utility Class
for example: AzureStorageUtils.java
-
Either log this exception and handle it, or rethrow it with some contextual information.
-
Complete the task associated to this TODO comment.
For example: StorageFileResource.java(L220)
-
Code cleaning.
The following issues need discussion:
Sonar report critical issues for the following code smells:
- code complexity reduce.
- deprecation usage of API.
- This class has 6 parents.
- Usage of generic wildcard type in return type.
- Fields in a "Serializable" class should either be transient or serializable. (Security issue)
The following issues are ignored:
-
Define and throw a dedicated exception instead of using a generic one.
-
magic number 1000 used as 1000 milliseconds, or parameter in Duration.ofMinutes(5);
-
Add a constructor to the class, or provide default values.
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:
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:
magic number
Use "==" to perform this enum comparison instead of using "equals"
Access scope modifier, for example: protected ctor for abstract class
Use the primitive boolean expression here.
Add a private constructor to hide the implicit public one for Utility Class
for example: AzureStorageUtils.java
Either log this exception and handle it, or rethrow it with some contextual information.
Complete the task associated to this TODO comment.
For example: StorageFileResource.java(L220)
Code cleaning.
The following issues need discussion:
Sonar report critical issues for the following code smells:
The following issues are ignored:
Define and throw a dedicated exception instead of using a generic one.
magic number 1000 used as 1000 milliseconds, or parameter in Duration.ofMinutes(5);
Add a constructor to the class, or provide default values.