一句话:提出 NullAway,一个构建开销低、注解负担小的 Java 空安全类型检查器,可在每次构建中运行。
NullPointerException 是现代 Java 程序崩溃的主要来源之一。已有工作表明可通过代码注解与可插拔类型检查在编译期预防此类错误,但这类系统因构建期开销大或注解负担重,难以在大型项目中落地。本文提出 NullAway,一个面向 Java 的基于类型的空安全检查器:它经过精心工程化以实现低开销,可作为每次构建的一部分运行;同时通过有针对性的非可靠假设(unsound assumptions)降低注解负担,目标是在被检查代码上不产生漏报。评估显示,NullAway 的构建时间开销仅为 1.15×,远低于同类工具的 2.8–5.1×。在若干广泛使用且已采用 NullAway 的 Android 应用的生产崩溃数据语料上,残余 NPE 分别来自未检查的第三方库(64%)、人为错误抑制(17%)、反射及其他检查后代码修改(17%),没有一例源于 NullAway 对被检查代码的非可靠假设。
NullPointerExceptions (NPEs) are a key source of crashes in modern Java programs. Previous work has shown how such errors can be prevented at compile time via code annotations and pluggable type checking. However, such systems have been difficult to deploy on large-scale software projects, due to significant build-time overhead and / or a high annotation burden. This paper presents NullAway, a new type-based null safety checker for Java that overcomes these issues. NullAway has been carefully engineered for low overhead, so it can run as part of every build. Further, NullAway reduces annotation burden through targeted unsound assumptions, aiming for no false negatives in practice on checked code. Our evaluation shows that NullAway has significantly lower build-time overhead (1.15×) than comparable tools (2.8-5.1×). Further, on a corpus of production crash data for widely-used Android apps built with NullAway, remaining NPEs were due to unchecked third-party libraries (64%), deliberate error suppressions (17%), or reflection and other forms of post-checking code modification (17%), never due to NullAway’s unsound assumptions for checked code.