squid:S2221: False Positives for constructors

559 views
Skip to first unread message

poseurhs...@gmail.com

unread,
Feb 6, 2018, 1:14:42 PM2/6/18
to SonarQube
squid:S2221 ("Catch a list of specific exception subtypes instead.") raises an issue if a method is surrounded by a try-catch-block that catches Exceptions excessively.
This works fine for methods, but it produces false-positives for constructors.

Assume the following class:
class ExceptionThrower {
   
ExceptionThrower() throws Exception {
        throw new Exception("");
    }
}

Now, that class could be instantiated like this:
try {
    new ExceptionThrower();
} catch(Exception e) {
}

This raises the aforementioned issue.
Since it is necessary to catch "Exception" because the constructor throws it, this should NOT produce the issue "Catch a list of specific exception subtypes instead."

Only constructors seem to be affected by this behaviour.

Nicolas Peru

unread,
Feb 7, 2018, 3:34:40 AM2/7/18
to poseurhs...@gmail.com, SonarQube
Hi, 

Thanks a lot for the feedback and reproducer (we always appreciate a nice and concise reproducer!) . This is indeed a FP and should be fixed in next release of SonarJava. 
Ticket created to handle the issue : https://jira.sonarsource.com/browse/SONARJAVA-2641

Cheers,

--
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/2cbe25c6-f1f8-44c4-b3df-68b5e552718e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource
Reply all
Reply to author
Forward
0 new messages