Add inspection to detect non-const vals used as Java annotation args

So #KT-20615 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-12-14 12:51:19 +03:00
parent 70b7e5eb68
commit 7358980cbc
16 changed files with 215 additions and 24 deletions
@@ -0,0 +1,17 @@
<html>
<body>
<p>
This inspection reports non-const Kotlin properties used as Java annotation arguments.
It's possible for property which is annotated by <code>@JvmField</code>,
has initializer that can be evaluated in compile-time, has primitive or String type.
Such properties have 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 cause incorrect behavior in case of separate or incremental compilation in mixed Java/Kotlin code.
</p>
<p>
This behaviour is subject to change in Kotlin 1.3 (no ConstantValue attribute more).
Recommended action: replace <code>JvmField</code> annotation with <code>const</code> modifier on relevant Kotlin property or inline it.
</p>
</body>
</html>