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

ExceptionRaisedInUnexpectedLocation in constructer #537

Closed
melashkov opened this issue Nov 10, 2017 · 5 comments
Closed

ExceptionRaisedInUnexpectedLocation in constructer #537

melashkov opened this issue Nov 10, 2017 · 5 comments

Comments

@melashkov
Copy link

melashkov commented Nov 10, 2017

Hi, I have found another issue, I am rising en exception when class being constructed
example:

class FooBar(isValid: Boolean) {

    init {
        if (!isValid) {
            throw IllegalArgumentException()
        }
    }
}

The detekt tells me "This method is not expected to throw exceptions. This can cause weird behavior.", is that expected that you should not rise exceptions in init?

@arturbosch
Copy link
Member

arturbosch commented Nov 10, 2017

This is a good question. Init is often used to validate state in Kotlin. Should we remove this case/make it optional @Mauin @schalkms ?

@schalkms
Copy link
Member

I think an exception thrown in an init block is ok. I wouldn’t call it a bug. I’ll take a look at it tomorrow.

@arturbosch
Copy link
Member

Yeah. how about a new label false-positive? So make init optionally detected or just remove this case?

@schalkms
Copy link
Member

Sounds good to me!

@lock
Copy link

lock bot commented Jun 20, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants