Hi,
I'm not sure if this is the appropriate place to report this, but I believe I've found a small false positive.
With the following implementation of an Iterator's next method:
public SomeType next() {
return getOptionalForNext().orElseThrow(NoSuchElementException::new);
}
... where getOptionalForNext returns an Optional<SomeType>, Sonar complains:
Add a "NoSuchElementException" for iteration beyond the end of the collection.
Not exactly sure how Sonar tracks which methods can throw runtime exceptions, and I know determining if any method called within next() throws a NoSuchElementException is probably impossible. But there should probably be support for Java-native methods that can throw those exceptions.
Manually checking if the Optional is present (with isPresent()) and then throwing a NoSuchElementException removes the warning.
Tested with the most recent Eclipse and SonarLint from the marketplace.
Thanks,
Ryan Marcus