Kotlin 1.4 -Xuse-ir marks lateinit fields as Nullable forcing NullAway to flag calls as unsafe
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.1k
- Forks
- 370
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 68
Description
It's more of a heads-up issue for now.
We're trying Kotlin 1.4 with -Xuse-ir to use JetPack Compose, however we found that it generates different bytecode for lateinit backing fields.
Kotlin code:
internal lateinit var textView: TextView
-Xuse-ir produces following bytecode:
public android.widget.TextView textView;
descriptor: Landroid/widget/TextView;
flags: (0x0001) ACC_PUBLIC
RuntimeInvisibleAnnotations:
0: #13()
org.jetbrains.annotations.Nullable
Regular compiler backend produces following:
public android.widget.TextView textView;
descriptor: Landroid/widget/TextView;
flags: (0x0001) ACC_PUBLIC
RuntimeInvisibleAnnotations:
0: #7()
org.jetbrains.annotations.NotNull
As you can see, regular backend marks the field as @NotNull, while ir backend marks it as @Nullable.
Which in turn breaks NullAway, it starts flagging Java calls to lateinit fields as unsafe.
For now, I think it's an issue for Kotlin team to figure out, because it's a breakage of public API, but technically, they're not wrong marking lateinit as Nullable…
Potential solution in NullAway would be to parse Kotlin metadata annotations to figure out if it's a lateinit field, but that sounds like a Kotlin specific solution which is not great.
Upstream Kotlin issue: https://youtrack.jetbrains.com/issue/KT-43177
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Kotlin example and compare the regular-backend and -Xuse-ir bytecode shown in the issue, then review upstream Kotlin issue KT-43177. Check how NullAway handles the generated @Nullable annotation on lateinit fields. The issue does not define a NullAway-side change or a clear completion condition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100