The rule says that this:
Optional<String> value = this.getOptionalValue(); // ... String stringValue = value.get(); // Noncompliant
Is not compliant. My question is: why? I’ve read the discussion on previous forum, that this is due to multithreading. But Optional is immutable, so it is thread safe. Why rule expects to check if value is present before every call to get? Besides even if optional wouldn’t have been immutable it still makes no sense as doing such check is not atomic, thus still:
if (opt.isPresent) opt.get();
could throw an exception.
Isn’t this rule based on erroneous assumptions?