40 lines
1.7 KiB
Markdown
40 lines
1.7 KiB
Markdown
# Using PMD
|
||
|
||
Pick a Java project from Github (see the [instructions](../sujet.md) for suggestions). Run PMD on its source code using any ruleset (see the [pmd install instruction](./pmd-help.md)). Describe below an issue found by PMD that you think should be solved (true positive) and include below the changes you would add to the source code. Describe below an issue found by PMD that is not worth solving (false positive). Explain why you would not solve this issue.
|
||
|
||
## Answer
|
||
|
||
Nous avons cloné le projet `commons-math`
|
||
https://github.com/apache/commons-math
|
||
|
||
On a trouvé un problème qu’il ne vaut pas la peine de changer :
|
||
`./commons-math/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMath.java:396: UselessParentheses: Useless parentheses around `0.5 * t`.`
|
||
|
||
Et voici le code que PMD a indiqué:
|
||
```
|
||
if (x >= LOG_MAX_VALUE) {
|
||
// Avoid overflow (MATH-905).
|
||
final double t = exp(0.5 * x);
|
||
return (0.5 * t) * t;
|
||
```
|
||
|
||
Comme on peut le voir, les parenthèses ne causent aucun problème ici, mais c’est un vrai positif.
|
||
|
||
Pour un faux positif, nous avons trouvé celui-ci:
|
||
`./commons-math/commons-math-legacy-core/src/test/java/org/apache/commons/math4/legacy/core/IntegerSequenceTest.java:255: UnusedLocalVariable: Avoid unused local variables such as 'inc'.`
|
||
|
||
```
|
||
@Test(expected = ZeroException.class)
|
||
public void testIncrementZeroStep() {
|
||
final int step = 0;
|
||
|
||
final IntegerSequence.Incrementor inc
|
||
= IntegerSequence.Incrementor.create()
|
||
.withIncrement(step);
|
||
}
|
||
|
||
```
|
||
|
||
|
||
|
||
Parce que le but du test est de déclencher le bug lors de la création de l’objet. |