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

Nested SwallowedException are not detected #4153

Closed
TWiStErRob opened this issue Oct 3, 2021 · 2 comments · Fixed by #4404
Closed

Nested SwallowedException are not detected #4153

TWiStErRob opened this issue Oct 3, 2021 · 2 comments · Fixed by #4404

Comments

@TWiStErRob
Copy link
Member

Expected Behavior

> Task :detekt FAILED
exceptions - 20min debt
        SwallowedException - [f] at src\main\kotlin\test.kt:4:4
        SwallowedException - [f] at src\main\kotlin\test.kt:7:4

Observed Behavior

> Task :detekt FAILED
exceptions - 20min debt
        SwallowedException - [f] at src\main\kotlin\test.kt:4:4

Steps to Reproduce

fun f() {
	try {
		println("verifySomething")
	} catch (ex: AssertionError) {
		try {
			println("verifySomethingElse")
		} catch (ex2: AssertionError) {
			throw ex.initCause(ex2)
		}
	}
}

Context

No context, just noticed it. See usage at https://github.com/TWiStErRob/net.twisterrob.cinema/blob/master/Heroku/backend/network/src/test/kotlin/net/twisterrob/ktor/client/ConfigureLoggingTest.kt#L212-L220
The nested AssertionError is guaranteed after "noMore" throwing.

Your Environment

@TWiStErRob TWiStErRob added the bug label Oct 3, 2021
@chao2zhang
Copy link
Member

Since throw ex.initCause(ex2) refers ex2, I think the observed behavior is correct because ex2 is not swallowed.

@BraisGabin
Copy link
Member

BraisGabin commented Oct 4, 2021

I agree with chao that this doesn't seem a ShallowedException. But I think that we are missing a super call in this rule. And it could generate the described problem. I just notice it reading #4158. We could add a test to ensure this.

schalkms added a commit that referenced this issue Dec 27, 2021
schalkms added a commit that referenced this issue Dec 27, 2021
* Add test for nested SwallowedException

Closes #4153

* Remove trailing spaces in test code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants