Retrofitting null-safety onto Java at Meta
Nullsafe is a static analyzer built at Meta to catch NullPointerExceptions in Java, implemented as an extra compiler pass via the JSR-199 compiler API. It runs flow-sensitive nullness type inference over a control flow graph, then type checks the AST against those results, with added support for nullness in generics despite complications from Java's target typing. A three-tier model (Nullsafe-compliant, optimistically checked first-party code, pessimistically checked third-party code) allowed gradual adoption across millions of lines of legacy code. On Instagram, production NPE crashes fell 27% over 18 months of code transformation.
Related posts
- Translating Java to Kotlin at Scale
Meta Engineering mediumAdeptMeta is translating roughly ten million lines of Android Java to Kotlin using the Kotlinator, an automated pipeline built around a headless version of JetBrains' J2K. It runs six phases: a deep build, about 50 preprocessing steps, headless J2K, about 150 postprocessing steps, linters with autofixes, and fixes driven by compiler errors. A daily cron system produces the conversion diffs for human review. Null safety comes first, because Kotlin inserts runtime null checks at the Java interop boundary, so the Kotlinator errs toward nullable types to avoid introducing new NPEs. Meta is also working with JetBrains to add extension hooks to J2K for better symbol resolution and to open-source some of its steps.
- How we migrated our static analyzer from Java to Rust
Datadog Engineering mediumAdeptDatadog rewrote the Codiga static analyzer from Java to Rust after switching its parser from ANTLR to Tree-sitter, whose Java bindings lacked features like pattern matching. The rewrite ran analysis about 3x faster with roughly 10x less memory, which matters on small CI runners. Shipping a single binary also removed the JVM dependency, so the same analyzer now runs inside the IDE. The team replaced GraalVM with deno-core as a sandboxed JavaScript rule runtime and mapped Java libraries to serde_yaml, reqwest and rayon. Learning Rust and migrating took about a month, helped by parity tests, clippy and rustfmt.
- Open-sourcing Mariana Trench: Analyzing Android and Java app security in depth
Meta Engineering easyNoviceMariana Trench is Meta's open-sourced static taint-analysis tool for Android and Java apps that finds security and privacy bugs by tracing data flows from sources (e.g., Intent.getData) to sinks (e.g., Log.w, Runtime.exec). It computes per-method models via abstract interpretation and lets security engineers write rules such as user-controlled input reaching an intent-redirection sink. Rules are refined until high-signal and then run on every pull request. Meta deliberately tolerates more false positives to catch rare exploitable edge cases, and triages results with SAPP, a post-processor that groups similar traces and visualizes source-to-sink paths. Mobile apps get this extra pre-release scrutiny because fixes depend on users installing updates.
- An open source compositional deadlock detector for Android Java
Meta Engineering hardMasterMeta built a compositional static analyzer, now part of the open source Infer framework, that detects deadlocks in Android Java code without running it. Using abstract interpretation, it summarizes each method once in terms of "critical pairs": which lock it acquires while already holding a given set of locks, plus whether it runs on the main or a background thread. To scale to codebases with hundreds of millions of lines, it analyzes only the methods in a revision's modified files, then uses a heuristic to find outside methods that could deadlock with them. Deployed in CI on every commit to Meta's Android apps, it has led to over 200 fixes at about a 54% fix rate, and the analysis is proven sound and complete for an abstract language with non-deterministic control.
- Hakana: Taking Hack Seriously
Slack Engineering mediumAdeptSlack has open-sourced Hakana, a Rust-based type checker and static analyzer for Hack, built on Psalm's design and reusing the Hack parser bundled with HHVM. Slack runs it in CI to catch unused code, impossible or redundant type checks, misuse of internal APIs, and security flaws. Security checks use interprocedural taint analysis similar to Facebook's internal Zoncolan, plus a literal-string type that blocks SQL injection at function boundaries. Plugin hooks support custom type inference and fast codebase-wide migrations, and on Slack's roughly 5 million lines it runs about 5x faster than Psalm and on par with the official Hack typechecker.