Affects PMD Version:
6.22.0
Rule:
AvoidDecimalLiteralsInBigDecimalConstructor
Description:
AvoidDecimalLiteralsInBigDecimalConstructor can not detect the case new BigDecimal(Expression)
//AllocationExpression
[ClassOrInterfaceType[@Image="BigDecimal"]]
[Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix
[
Literal[(not(ends-with(@Image,'"'))) and contains(@Image,".")]
or
Name[ancestor::Block/BlockStatement/LocalVariableDeclaration
[Type[PrimitiveType[@Image='double' or @Image='float']
or ReferenceType/ClassOrInterfaceType[@Image='Double' or @Image='Float']]]
/VariableDeclarator/VariableDeclaratorId/@Image = @Image
]
or
Name[ancestor::MethodDeclaration/MethodDeclarator/FormalParameters/FormalParameter
[Type[PrimitiveType[@Image='double' or @Image='float']
or ReferenceType/ClassOrInterfaceType[@Image='Double' or @Image='Float']]]
/VariableDeclaratorId/@Image = @Image
]
]
]
This rule doesn't consider using Expression(for example: foo * bar
) to create BigDecimal
Code Sample demonstrating the issue:
new BigDecimal(remaining * 60)
Expected outcome:
false-negative
Running PMD through:
CLI
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4