一句话:提出深度学习方法 IICR-Finder,检测 if 条件与抛出异常不一致的语句,在 Python 中发现 30 个新缺陷。
开发者常用条件守卫的异常在意外状态时终止程序,但条件与抛出的异常可能暗示不同的停止原因,形成不一致的 if-条件-raise 语句。不一致可能源于条件或异常消息的错误。本文提出 IICR-Finder,一种基于深度学习的方法,同时推理条件的逻辑与异常消息的自然语言,并在不一致时发出警告。为训练二元分类和三重损失两个神经模型,作者提出六种自动生成大量不一致语句的技术。该方法应用于从 4200 万行 Python 代码中提取的 21 万个 if-条件-raise 语句,在历史缺陷修复数据集上以 60% 召回率取得 72% 精确率。在开源项目上运行发现 30 个此前未知的缺陷,报告 10 个,其中 8 个被开发者确认。
Developers use exceptions guarded by conditions to abort the execution when a program reaches an unexpected state. However, sometimes the condition and the raised exception do not imply the same stopping reason, in which case, we call them inconsistent if-condition-raise statements. The inconsistency can originate from a mistake in the condition or the exception message. This paper presents IICR-Finder, a deep learning-based approach to detect inconsistent if-condition-raise statements. The approach reasons both about the condition’s logic and the natural language of the exception message and raises a warning in case of inconsistency. We present six techniques to automatically generate large numbers of inconsistent statements to train two neural models based on binary classification and triplet loss. We apply the approach to 210K if-condition-raise statements extracted from 42 million lines of Python code. It achieves a precision of 72% at a recall of 60% on a dataset of past bug fixes. Running IICR-Finder on open-source projects reveals 30 previously unknown bugs, ten of which we reported, with eight confirmed by the developers.