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

potential-bugs UnsafeCallOnNullableType UnsafeCast do not work #2043

Closed
kepocnhh opened this issue Oct 19, 2019 · 2 comments
Closed

potential-bugs UnsafeCallOnNullableType UnsafeCast do not work #2043

kepocnhh opened this issue Oct 19, 2019 · 2 comments

Comments

@kepocnhh
Copy link

kepocnhh commented Oct 19, 2019

private fun unsafeCallOnNullableType() {
    val someEnum: SomeEnum? = SomeEnum.values().firstOrNull()
    println(someEnum!!.name)
}

private fun unsafeCast() {
    val someEnum: Any = SomeEnum.values().first().ordinal
    println(someEnum as String)
    println(someEnum as SomeEnum)
}

Expected Behavior

The rule will work and the detekt will report an error.

Observed Behavior

Detekt does not report an error.

Steps to Reproduce

I use my task:

task<Detekt>("verifyQuality") {
    source = files(subprojects.withPlugin("kotlin").srcDirs("main")).asFileTree
    config = files(
        "buildSrc/src/main/resources/detekt/config/potential_bugs.yml"
    )
    reports {
        html {
            enabled = true
            destination = File(analysisQualityHtmlPath)
        }
        xml.enabled = false
        txt.enabled = false
    }
}

File potential_bugs.yml contains:

build:
  maxIssues: 0

potential-bugs:
  active: true
  UnsafeCallOnNullableType:
    active: true
  UnsafeCast:
    active: true

processors:
  active: false

Context

Detekt definitely works on other rule sets (for example, DuplicateCaseInWhenExpression). That is, the problem should not be in the source of the source code or the path to detekt configuration file. For some reason I can’t turn on this particular rule (Deprecation).

Environment

java 1.8.0_221
kotlin 1.3.50
detekt 1.1.1
Gradle 5.5.1
macOS Mojave Version 10.14.6 (18G87)

@dive5617
Copy link

I also find this rule doesn't work now. It looks like there're some wrong in the configuration file refer to #2036. I still confused what it should be.

@arturbosch
Copy link
Member

Same as #2038..

@lock lock bot locked as resolved and limited conversation to collaborators Feb 10, 2020
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