Quote from the rule description (SonarQube 4.5.5):
// Noncompliant - exception is lost (only message is preserved) try { /* ... */ } catch (Exception e) { LOGGER.info(e.getMessage()); }
By providing an exception class to the log, the stack trace is written to the logs.
The problem in our code base is this: Following Tell me, donโt ask for a principle, we use checked exceptions as part of what we are looking at, ordinary execution paths and donโt hope that they want them to lead to unreasonably large log messages.
A few examples: servers that respond with error codes are executed when querying the database with optimistic locking (concurrent users) ...
My suggestion: divide this case into two.
// Noncompliant - exception is lost (only message is preserved) try { /* ... */ } catch (Exception e) { LOGGER.info(e.getMessage()); }
and
// Compliant - exception is lost (only message is preserved) but there is business logic handling the situation try { /* ... */ } catch (Exception e) { LOGGER.info(e.getMessage()); */ exception handling */ }
Squid rule: S00108 (code blocks must not be empty) will not catch the problem, since there is a registration operator.
Isn't that wise? Did I miss something important?
Note. I rewrote the question to clarify my use case
Alix
source share