Java – why is anyvalue% 1 “stupid math” double anyvalue in sonar?
•
Java
Sony math should not be performed Explanation
In my case, anyvalue is a double This is as intended for me The following is the actual code:
double v = Double.parseDouble(Utils.formatDouble(Double.valueOf(value.getValue()),accuracy.intValue())); boolean negative = v < 0; v = Math.abs(v); long deg = (long) Math.floor(v); v = (v % 1) * 60;
The analyzer assumes that my variable is an int (this is their error)? Or am I missing something else?
Solution
This is indeed a mistake, so thank you very much for your report
Here is the problem code: https://github.com/SonarSource/sonar-java/blob/3.9/java-checks/src/main/java/org/sonar/java/checks/ConstantMathCheck.java#L117
There is absolutely no checking the type of the left operand of the% operator
I just submitted the following error to handle: https://jira.sonarsource.com/browse/SONARJAVA-1457
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码