In my code I get the above warning. Here is the part of the code where I get it,
@Data
@Builder
public class Employee {
private String email;
@Data
@Builder
public static class Department{
@Singular(value = "department")
private final Set<String> set;
}
}
Variable set may be null at this access as suggested by null guard.
need to resolve 'set' is not added null value which is not give Code Scanning Alerts "Dereferenced variable may be null"
You used final.
The final is used that >>value<< or >>ref to the object<< cannot be changed.
To fix your problem init in >>all constructors<< or >>spot<< or delete final.
Option 1
Option 2
Option 3 ... you still need to call init (set = new HashSet<>())
This link might helps you find more about final: https://en.wikipedia.org/wiki/Final_(Java)