diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 195418159e..8421462853 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -1407,8 +1407,12 @@ public class ClassInDefaultPackage { [ some $num in tokenize(@Image, "[dDfFlLeE+\-]") satisfies not( - string-length($num) <= $acceptableDecimalLength - and not(contains($num,"_")) + ( contains($num, ".") + and string-length(substring-before($num, ".")) <= $acceptableDecimalLength + and string-length(substring-after($num, ".")) <= $acceptableDecimalLength + or string-length($num) <= $acceptableDecimalLength + ) + and not(contains($num,"_")) or matches($num, "^[0-9]{1,3}(_[0-9]{3})*(\.([0-9]{3}_)*[0-9]{1,3})?$") ) ] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UseUnderscoresInNumericLiterals.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UseUnderscoresInNumericLiterals.xml index 0c19095512..bd1af8d293 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UseUnderscoresInNumericLiterals.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UseUnderscoresInNumericLiterals.xml @@ -327,6 +327,9 @@ public class Foo { double value3 = -0.1; double value4 = -0.123_456; double value5 = +0.123_456; + + double valid1 = 0.3936; + double valid2 = 1000.0; } ]]>