Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for special handling in RethrowCaughtException #907

Merged
merged 6 commits into from
May 21, 2018
Merged

Added support for special handling in RethrowCaughtException #907

merged 6 commits into from
May 21, 2018

Conversation

schalkms
Copy link
Member

reference #906

It does not report caught exception that are rethrown if there is work
done before that.
reference #906
@arturbosch
Copy link
Member

Please add test cases for just logging a message and not using the exception.
And maybe all the others from sonarqubes example :)

fun x() {
try {
} catch (e: IllegalStateException) {
print("log")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to sonar this should get reported, should't it? (https://sbforge.org/sonar/rules/show/squid:S1166?modal=true&layout=false)

// Noncompliant - exception is lost (only message is preserved)
try { /* ... */ } catch (Exception e) { LOGGER.info(e.getMessage()); }

The exception name must be used in any statement to not lose the exception?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we make the rule stricter? @arturbosch
So this gets reported

try {
} catch (e: Exception) {
  log()
  log(e.message)
  throw e
}

and this does not

try {
} catch (e: Exception) {
  log(e) // e is used here
  throw e
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say yes, lets how I interpret sonarqube's doc.

@arturbosch arturbosch merged commit 9caa63e into detekt:master May 21, 2018
@arturbosch arturbosch added this to the RC7-2 milestone Jun 1, 2018
@schalkms schalkms deleted the #906-RethrowCaughtException branch June 2, 2018 09:07
@schalkms schalkms restored the #906-RethrowCaughtException branch July 26, 2018 20:55
@schalkms schalkms deleted the #906-RethrowCaughtException branch September 3, 2018 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants