Files
VV-ISTIC-TP2/exercises/using-pmd.md
2025-12-12 12:58:32 +01:00

1.7 KiB
Raw Blame History

Using PMD

Pick a Java project from Github (see the instructions for suggestions). Run PMD on its source code using any ruleset (see the pmd install instruction). 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 quil 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 cest 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 lobjet.