Kotlin non-const property used as Java constant
Reports Kotlin properties that are not const
and used as Java annotation arguments.
For example, a property with the @JvmField
annotation has an initializer that can be evaluated at compile-time, and it has a primitive or String
type.
Such properties have a ConstantValue
attribute in bytecode in Kotlin 1.1-1.2. This attribute allows javac to fold usages of the corresponding field and use that field in annotations. This can lead to incorrect behavior in the case of separate or incremental compilation in mixed Java/Kotlin code. This behavior is subject to change in Kotlin 1.3 (no ConstantValue
attribute any more).
Example:
Kotlin code in foo.kt file:
Java code:
To fix the problem replace the @JvmField
annotation with the const
modifier on a relevant Kotlin property or inline it.
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
FakeJvmFieldConstant- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Kotlin, 243.23126-IJ |