一句话:提出神经方法自动预测 try 块位置并生成完整 catch 块,实现 Java 异常处理的自动化。
异常处理是 Java 等语言的内置特性,但开发者常忽视或难以正确实现,现有推荐工具仅提供代码示例和异常类型,仍需人工定位 try 块并改写 catch 代码。本文提出一种神经方法实现自动化异常处理:从 GitHub 收集大量 Java 方法,训练模型预测 try 块插入位置并生成完整的 catch 块代码。实验包括定量指标与人工评估,结果表明该方法显著优于所有基线,向自动化异常处理迈进一步。
Exception handling is an important built-in feature of many modern programming languages such as Java. It allows developers to deal with abnormal or unexpected conditions that may occur at runtime in advance by using try-catch blocks. Missing or improper implementation of exception handling can cause catastrophic consequences such as system crash. However, previous studies reveal that developers are unwilling or feel it hard to adopt exception handling mechanism, and tend to ignore it until a system failure forces them to do so. To help developers with exception handling, existing work produces recommendations such as code examples and exception types, which still requires developers to localize the try blocks and modify the catch block code to fit the context. In this paper, we propose a novel neural approach to automated exception handling, which can predict locations of try blocks and automatically generate the complete catch blocks. We collect a large number of Java methods from GitHub and conduct experiments to evaluate our approach. The evaluation results, including quantitative measurement and human evaluation, show that our approach is highly effective and outperforms all baselines. Our work makes one step further towards automated exception handling.
DOI 原文 ·
@inproceedings{paperbot5893,
title = {Learning to handle exceptions},
author = {Jian Zhang and Xu Wang and Hongyu Zhang and Hailong Sun and Yanjun Pu and Xudong Liu},
booktitle = {ASE},
year = {2020},
doi = {10.1145/3324884.3416568}
}