From 910efb36eb89d9d4c87ebaeef6f1742ac33e5282 Mon Sep 17 00:00:00 2001 From: Vu Tuan Minh Date: Fri, 28 Nov 2025 08:54:24 +0100 Subject: [PATCH] question 2 en anglais --- exercises/using-pmd.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/exercises/using-pmd.md b/exercises/using-pmd.md index 833278a..91de432 100644 --- a/exercises/using-pmd.md +++ b/exercises/using-pmd.md @@ -4,3 +4,33 @@ Pick a Java project from Github (see the [instructions](../sujet.md) for suggest ## Answer +We clone the project `commons-math` +https://github.com/apache/commons-math +We found a problem that it's not worth to change +`./commons-math/commons-math-core/src/main/java/org/apache/commons/math4/core/jdkmath/AccurateMath.java:396: UselessParentheses: Useless parentheses around `0.5 * t`.` +And here is the code that PMD a indiqué: +``` + if (x >= LOG_MAX_VALUE) { + // Avoid overflow (MATH-905). + final double t = exp(0.5 * x); + return (0.5 * t) * t; +``` + +As we can see the parentheses didn't cause any harm here but it is a true positive + +For a false positive, we found this one: +`./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); + } + +``` + +Because the purpose of the test is to trigger the bug when create object. \ No newline at end of file