Comparison between a Wrapper class and and its corresponding primitive type can produce a NullPointerException
// Noncompliant Code Example
Long wrapper = null;
long baseType = 100;
// Unboxing of ‘wrapper’ may produce ‘NullPointerException’
if (wrapper == baseType) {
…
}
// Compliant Code Example
Long wrapper = null;
long baseType = 100;
if (wrapper == Long.valueOf(baseType)) {
…
}
Don’t hesitate to share rule ideas. Even when they don’t match our guidelines it might make somebody else think of an alternative rule.