Search code examples
androidannotationslint

Android Studio and Lint don't generate an error when an IntDef field is assigned a wrong value


Here is my code:

Const.kt

package sample.com.sample_app

object Const {
    const val NAVIGATION_MODE_STANDARD = 1
    const val NAVIGATION_MODE_LIST = 2
}

NavigationMode.kt

package sample.com.sample_app

import android.support.annotation.IntDef
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy.SOURCE

@Retention(SOURCE)
@IntDef(Const.NAVIGATION_MODE_LIST, Const.NAVIGATION_MODE_STANDARD)
annotation class NavigationMode

OtherAct.kt

package sample.com.sample_app

import android.os.Bundle
import android.support.v7.app.AppCompatActivity

class OtherAct : AppCompatActivity() {

    @NavigationMode
    private var a: Int = 12

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        a = 34
    }
}

No error or warning from Android Studio or ./gradlew lint

My environment:

buildToolsVersion "28.0.2"
kotlin_version = '1.2.41'
implementation 'com.android.support:appcompat-v7:27.1.1'

Solution

  • Unfortunately, it works only for function's parameters and not for the property itself