Optional.ofNullable should not be used on a primitive type

Optional.ofNullable should only be used with non-null arguments. As primitive types can not hold a null-value, it makes sense to use Optional.of instead.
The rule should validate that the argument is not a primitive type or a method returning a primitive type.

Noncompliant Code Example

Compliant Solution

Hi @TomVanWemmel and Welcome to the community !

Also thank you for taking the time to suggest this rule. :slight_smile:
As said on Twitter, it makes complete sense to me. I’ll specify it and copy the link in this thread so that you can have a look.