S1162: Checked Exception should not be thrown -- interfaces with declared exceptions

774 views
Skip to first unread message

Brian Sperlongano

unread,
Jan 21, 2016, 11:29:30 AM1/21/16
to SonarQube
Hello,

squid S1162 reports a finding on any method that throws a new checked exception.  I would like to suggest that this may be a false positive in the specific case dealing with implementing an interface.  For example:

public interface SomeInterface {
   boolean isSomeMethod() throws CheckedException
}

and implementor:

@Override
public boolean isSomeMethod() throws CheckedException {
    throw new CheckedException("some message");
}

...reports a finding.  By converting the checked exception into an unchecked exception, you would be fundamentally altering the contract of the interface/method, which expects one of 3 results: true, false, or a CheckedException.  I am wondering whether this finding should be suppressed when a method implements an interface that declares the checked exception.

Michael Gumowski

unread,
Jan 26, 2016, 3:36:02 AM1/26/16
to Brian Sperlongano, SonarQube
Hello Brian,

First, thank you for your feedback! Indeed, in such case, raising an issue is wrong as the contract of the interface explicitly allows it, and we shouldn't raise an issue.
I created the following JIRA ticket to handle it: https://jira.sonarsource.com/browse/SONARJAVA-1498

Cheers,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/51502f99-8a63-4730-a275-362ab9ff7afb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages