diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 7241a17c40..3ab31ceace 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -34,6 +34,8 @@ This is a {{ site.pmd.release_type }} release. * [#4800](https://github.com/pmd/pmd/issues/4800): \[apex] ClassNamingConvention: Support naming convention for *inner* classes * apex-performance * [#635](https://github.com/pmd/pmd/issues/635): \[apex] New Rule: Avoid soql/sosl queries without a where clause or limit statement +* javascript-errorprone + * [#4716](https://github.com/pmd/pmd/issues/4716): \[javascript] InaccurateNumericLiteral with number 259200000 * plsql * [#5086](https://github.com/pmd/pmd/pull/5086): \[plsql] Fixed issue with missing optional table alias in MERGE usage * [#5087](https://github.com/pmd/pmd/pull/5087): \[plsql] Add support for SQL_MACRO diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java index 4fbef8e9ae..1b89b1766f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/XPathRule.java @@ -109,7 +109,7 @@ public final class XPathRule extends AbstractRule { // Nodes might already have been refactored to not use getImage anymore. // Therefore, try several other common names if (messageArg == null) { - messageArg = getFirstMessageArgFromNode(nodeWithViolation, "Name", "SimpleName", "MethodName"); + messageArg = getFirstMessageArgFromNode(nodeWithViolation, "Name", "SimpleName", "MethodName", "Value"); } ctx.addViolation(nodeWithViolation, messageArg); } diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNumberLiteral.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNumberLiteral.java index 19cc8a7bbc..607ad082b9 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNumberLiteral.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTNumberLiteral.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.ecmascript.ast; +import java.math.BigDecimal; + import org.mozilla.javascript.ast.NumberLiteral; public final class ASTNumberLiteral extends AbstractEcmascriptNode { @@ -57,4 +59,16 @@ public final class ASTNumberLiteral extends AbstractEcmascriptNode The numeric literal will have a different value at runtime, which can happen if you provide too much precision in a floating point number. This may result in numeric calculations being in error. + +[Numbers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) in JavaScript +are represented by 64bit double-precision floating point numbers internally and that's why there are some limits +to the available precision of the number. +See [Number.isSafeInteger()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger) +and [Number.EPSILON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON). 2 diff --git a/pmd-javascript/src/test/resources/net/sourceforge/pmd/lang/ecmascript/rule/errorprone/xml/InnaccurateNumericLiteral.xml b/pmd-javascript/src/test/resources/net/sourceforge/pmd/lang/ecmascript/rule/errorprone/xml/InnaccurateNumericLiteral.xml index fd304c19ae..f4cab44741 100644 --- a/pmd-javascript/src/test/resources/net/sourceforge/pmd/lang/ecmascript/rule/errorprone/xml/InnaccurateNumericLiteral.xml +++ b/pmd-javascript/src/test/resources/net/sourceforge/pmd/lang/ecmascript/rule/errorprone/xml/InnaccurateNumericLiteral.xml @@ -9,12 +9,17 @@ 0 Bad integer 1 + + The numeric literal '999999999999999999999999' will have at different value at runtime. + var x = 999999999999999999999999; @@ -45,6 +50,9 @@ var x = 1.12e-4; Bad float w/ exponent 1 + + The numeric literal '1.12345678901234567e-4' will have at different value at runtime. + @@ -69,6 +77,18 @@ const value2 = 0b1010_0001_1000_0101; // binary const value3 = 0xA0_B0; // hex const value4 = 9_223_372_036_854_775_807n; // big int const value5 = 0o1234_5670; // octal +]]> + + + + #4716 [javascript] InaccurateNumericLiteral with number 259200000 + 0 +