Affects PMD Version:
7.10.0
Rule:
UnnecessaryCast
Description:
Division (or multiplication) of primitive integer and boxed integer in floating-point context is detected as unnecessary cast.
Code Sample demonstrating the issue:
Code:
class Scratch {
public static void main(String[] args) {
long x = 100;
Integer y = 75;
System.out.println(Math.ceil((double) x / y)); // <-- Unnecessary cast (double).
System.out.println(Math.ceil(x / y));
}
}
Output (the cast in question makes a difference and is therefore not unnecessary):
Expected outcome:
PMD reports a violation at line ..., but that's wrong. That's a false positive.
Running PMD through:
Maven