Headless J2K
An IntelliJ plugin starts the converter directly through an application starter class. It runs on a remote machine, so it does not block local IDEs. It converts many files in one batch and allows slow build-and-fix steps.
Android development at Meta has been Kotlin-first since 2020. A mixed codebase needs two toolchains, and compiling both languages together is slow. Meta chose to convert nearly all active code and central dependencies, tens of millions of lines.
Plain converter output mostly failed to build in this codebase with custom frameworks.
The Kotlinator first builds the code so the IDE resolves all symbols. About 50 preprocessing steps prepare Java for conversion. A headless J2K run on a remote server converts the files.
About 150 postprocessing steps fix Android specifics, null handling and style. Linters run with autofixes. A last phase parses compiler errors and applies fixes.
A daily job builds diffs, picks reviewers, checks tests and ships after human approval.
An IntelliJ plugin starts the converter directly through an application starter class. It runs on a remote machine, so it does not block local IDEs. It converts many files in one batch and allows slow build-and-fix steps.
Custom steps use JetBrains PSI libraries, not compiler plugins. They work on code that does not build. When type data from third-party code is missing, a step stops instead of guessing.
The compiler adds runtime null checks at the Java and Kotlin boundary. When context is unclear, the tool makes parameters and return types more nullable. Added not-null assertions get close review. Over a dozen codemods find missing nullable markers, and a compiler plugin collects runtime data on null values.
The pipeline reads compiler messages and applies the fix a person would apply. Examples are adding an import or inserting an assertion. This avoids copying complex Kotlin compiler logic.
| No. | Chose | Instead of | Why |
|---|---|---|---|
| D1 | Convert nearly all active code | Only new code in Kotlin, or only the most important files | A mixed codebase keeps two toolchains and slows builds. |
| D2 | Run J2K headless on a server | Run it in a test-like IDE environment | This design avoids blocking developers and supports batches. |
| D3 | Fix compiler errors after conversion | Rebuild compiler logic in postprocessing | Reading errors is simpler and works like a human fix. |
| J2K | The IntelliJ Java to Kotlin converter. |
|---|---|
| PSI | JetBrains syntax tree library that works on code that does not build. |
| Codemod | A script that edits code across many files. |