[go: up one dir, main page]
More Web Proxy on the site http://driver.im/ skip to main content
10.1145/3597503.3639188acmconferencesArticle/Chapter ViewAbstractPublication PagesicseConference Proceedingsconference-collections
research-article
Open access

Programming Assistant for Exception Handling with CodeBERT

Published: 12 April 2024 Publication History

Abstract

With practical code reuse, the code fragments from developers' forums often migrate to applications. Owing to the incomplete nature of such fragments, they often lack the details on exception handling. The adaptation for exception handling to the codebase is not trivial as developers must learn and memorize what API methods could cause exceptions and what exceptions need to be handled. We propose Neurex, an exception handling recommender that learns from complete code, and accepts a given Java code snippet and recommends 1) if a try-catch block is needed, 2) what statements need to be placed in a try block, and 3) what exception types need to be caught in the catch clause. Inspired by the sequence chunking techniques in natural language processing, we design Neurex via a multi-tasking model with the fine-tuning of the large language model CodeBERT for these three exception handling recommendation tasks. Via the large language model, Neurex can learn the surrounding context, leading to better learning the dependencies among the API elements, and the relations between the statements and the corresponding exception types needed to be handled.
Our empirical evaluation shows that Neurex correctly performs all three exception handling recommendation tasks in 71.5% of the cases with a F1-score of 70.2%, which is a relative improvement of 166% over the baseline. It achieves high F1-score from 98.2%-99.7% in try-catch block necessity checking (a relative improvement of up to 55.9% over the baselines). It also correctly decides both the need for try-catch block(s) and the statements to be placed in try blocks with the F1-scores of 74.7% and 87.1% at the instance and statement levels, an improvement of 129.1% and 44.9% over the baseline, respectively. Our extrinsic evaluation shows that Neurex relatively improves over the baseline by 56.5% in F1-score for detecting exception-related bugs in incomplete Android code snippets.

References

[1]
Mithun Acharya and Tao Xie. 2009. Mining API Error-Handling Specifications from Source Code. In Proceedings of the 12th International Conference on Fundamental Approaches to Software Engineering: Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2009 (York, UK) (FASE '09). Springer-Verlag, Berlin, Heidelberg, 370--384.
[2]
Sven Amann, Sarah Nadi, Hoan A. Nguyen, Tien N. Nguyen, and Mira Mezini. 2016. MUBench: A Benchmark for API-Misuse Detectors. In Proceedings of the 13th Working Conference on Mining Software Repositories (MSR '16). ACM Press.
[3]
Eiji Adachi Barbosa and Alessandro Garcia. 2018. Global-Aware Recommendations for Repairing Violations in Exception Handling. IEEE Transactions on Software Engineering 44, 9 (2018), 855--873.
[4]
Eiji Adachi Barbosa, Alessandro Garcia, and Mira Mezini. 2012. Heuristic Strategies for Recommendation of Exception Handling Code. In Proceedings of the 26th Brazilian Symposium on Software Engineering. 171--180.
[5]
Eiji Adachi Barbosa, Alessandro Garcia, Martin P. Robillard, and Benjamin Jakobus. 2016. Enforcing Exception Handling Policies with a Domain-Specific Language. IEEE Transactions on Software Engineering 42, 6 (2016), 559--584.
[6]
BERT Viz [n.d.]. BERT Viz. https://github.com/jessevig/bertviz.
[7]
Raymond P L Buse and Westley R Weimer. 2008. Automatic Documentation Inference for Exceptions. In Proceedings of the International Symposium on Software Testing and Analysis (ISSTA'08). ACM Press.
[8]
ChatGPT [n. d.]. OpenAI. https://openai.com/.
[9]
codeBERT [n.d.]. CodeBERTMLM. https://github.com/microsoft/CodeXGLUE.
[10]
Barthélémy Dagenais and Martin P. Robillard. 2010. Creating and evolving developer documentation: understanding the decisions of open source contributors. In Proceedings of the Eighteenth ACM SIGSOFT International Symposium on Foundations of Software Engineering (Santa Fe, New Mexico, USA) (FSE '10). Association for Computing Machinery, New York, NY, USA, 127--136.
[11]
Zhangyin Feng, Daya Guo, Duyu Tang, Nan Duan, Xiaocheng Feng, Ming Gong, Linjun Shou, Bing Qin, Ting Liu, Daxin Jiang, and Ming Zhou. 2020. CodeBERT: A Pre-Trained Model for Programming and Natural Languages. In Findings of the Association for Computational Linguistics: EMNLP 2020, Online Event, 16--20 November 2020 (Findings of ACL, Vol. EMNLP 2020), Trevor Cohn, Yulan He, and Yang Liu (Eds.). Association for Computational Linguistics, 1536--1547.
[12]
FuzzyCatch bugs [n. d.]. FuzzyCatch bugs. ebrand.ly/ExDataset.
[13]
IOB2 [n. d.]. Inside-outside-beginning. https://en.wikipedia.org/wiki/Inside-outside-beginning_(tagging).
[14]
Xiangyang Jia, Songqiang Chen, Xingqi Zhou, Xintong Li, Run Yu, Xu Chen, and Jifeng Xuan. 2021. Where to Handle an Exception? Recommending Exception Handling Locations from a Global Perspective. In Proceedings of the 29th IEEE/ACM International Conference on Program Comprehension (ICPC). 369--380.
[15]
Maria Kechagia and Diomidis Spinellis. 2014. Undocumented and Unchecked: Exceptions That Spell Trouble. In Proceedings of the 11th Working Conference on Mining Software Repositories (Hyderabad, India) (MSR 2014). Association for Computing Machinery, New York, NY, USA, 312--315.
[16]
Owolabi Legunsen, Wajih Ul Hassan, Xinyue Xu, Grigore Roşu, and Darko Marinov. 2016. How Good Are the Specs? A Study of the Bug-finding Effectiveness of Existing Java API Specifications. In Proceedings of the 31st IEEE/ACM International Conference on Automated Software Engineering (Singapore, Singapore) (ASE '16). ACM Press, 602--613.
[17]
Yuhang Li, Shi Ying, Xiangyang Jia, Yisen Xu, Lily Zhao, Guoli Cheng, Bingming Wang, and Jifeng Xuan. 2018. EH-Recommender: Recommending Exception Handling Strategies Based on Program Context. In Proceedings of the 23rd International Conference on Engineering of Complex Computer Systems (ICECCS). 104--114.
[18]
Kai Lin, Chuanqi Tao, and Zhiqiu Huang. 2021. Exception Handling Recommendation Based on Self-Attention Network. In Proceedings of the IEEE International Symposium on Software Reliability Engineering Workshops (ISSREW). 282--283.
[19]
Martin Monperrus and Mira Mezini. 2013. Detecting missing method calls as violations of the majority rule. ACM Trans. Softw. Eng. Methodol. 22, 1, Article 7 (mar 2013), 25 pages.
[20]
Taiza Montenegro, Hugo Melo, Roberta Coelho, and Eiji Barbosa. 2018. Improving developers awareness of the exception handling policy. In Proceedings of the 25th IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER). 413--422.
[21]
Vijayaraghavan Murali, Swarat Chaudhuri, and Chris Jermaine. 2017. Bayesian Specification Learning for Finding API Usage Errors. In Proceedings of the 11th ACM Joint Meeting of the European Software Engineering Conference and the ACM SIGSOFT Symposium on The Foundations of Software Engineering (ESEC/FSE '17). ACM Press, 151--162.
[22]
Neurex [n.d.]. Neurex Website. https://github.com/anonymous-000000/neurex.
[23]
Anh Tuan Nguyen, Michael Hilton, Mihai Codoban, Hoan Anh Nguyen, Lily Mast, Eli Rademacher, Tien N. Nguyen, and Danny Dig. 2016. API Code Recommendation Using Statistical Learning from Fine-Grained Changes. In Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering (FSE 2016). Association for Computing Machinery, New York, NY, USA, 511--522.
[24]
Anh Tuan Nguyen, Tung Thanh Nguyen, Hoan Anh Nguyen, Ahmed Tamrawi, Hung Viet Nguyen, Jafar Al-Kofahi, and Tien N. Nguyen. 2012. Graph-based Pattern-oriented, Context-sensitive Source Code Completion. In Proceedings of the 34th International Conference on Software Engineering (Zurich, Switzerland) (ICSE '12). IEEE Computer Society Press, 69--79.
[25]
Tam Nguyen, Phong Vu, and Tung Nguyen. 2020. Code Recommendation for Exception Handling. In Proceedings of the 28th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering (Virtual Event, USA) (ESEC/FSE 2020). Association for Computing Machinery, New York, NY, USA, 1027--1038.
[26]
Tung Thanh Nguyen, Hoan Anh Nguyen, Nam H. Pham, Jafar M. Al-Kofahi, and Tien N. Nguyen. 2009. Graph-based Mining of Multiple Object Usage Patterns. In Proceedings of the 7th ACM Joint Meeting of the European Software Engineering Conference and the ACM SIGSOFT Symposium on The Foundations of Software Engineering (Amsterdam, The Netherlands) (ESEC/FSE '09). ACM Press, 383--392.
[27]
Tam The Nguyen, Hung V. Pham, Phong M. Vu, and Tunh Thanh Nguyen. 2015. Recommending API Usages for Mobile Apps with Hidden Markov Model. In Proceedings of the 30th ACM/IEEE International Conference on Automated Software Engineering (ASE '15). IEEE Computer Society Press, 795--800.
[28]
Tam The Nguyen, Hung Viet Pham, Phong Minh Vu, and Tung Thanh Nguyen. 2016. Learning API Usages from Bytecode: A Statistical Approach. In 2016 IEEE/ACM 38th International Conference on Software Engineering (ICSE). IEEE CS, 416--427.
[29]
Hung Phan, Hoan Anh Nguyen, Ngoc M. Tran, Linh H. Truong, Anh Tuan Nguyen, and Tien N. Nguyen. 2018. Statistical Learning of API Fully Qualified Names in Code Snippets of Online Forums. In Proceedings of the 40th International Conference on Software Engineering (ICSE '18). Association for Computing Machinery, New York, NY, USA, 632--642.
[30]
Michael Pradel and Thomas R. Gross. 2009. Automatic Generation of Object Usage Specifications from Large Method Traces. In Proceedings of the 24th IEEE/ACM International Conference on Automated Software Engineering (ASE '09). IEEE Computer Society Press, 371--382.
[31]
Michael Pradel, Ciera Jaspan, Jonathan Aldrich, and Thomas R. Gross. 2012. Statically Checking API Protocol Conformance with Mined Multi-object Specifications. In Proceedings of the 34th International Conference on Software Engineering (ICSE '12). IEEE Computer Society Press, 925--935.
[32]
Mohammad Masudur Rahman and Chanchal K. Roy. 2014. On the Use of Context in Recommending Exception Handling Code Examples. In Proceedings of the 14th IEEE International Working Conference on Source Code Analysis and Manipulation. 285--294.
[33]
Martin P. Robillard, Eric Bodden, David Kawrykow, Mira Mezini, and Tristan Ratchford. 2013. Automated API Property Inference Techniques. IEEE Transactions on Software Engineering 39, 5 (2013), 613--637.
[34]
M. A. Saied, O. Benomar, H. Abdeen, and H. Sahraoui. 2015. Mining Multi-level API Usage Patterns. In Proceedings of the 22nd IEEE International Conference on Software Analysis, Evolution, and Reengineering (SANER '15). IEEE Computer Society Press, 23--32.
[35]
Siddharth Subramanian, Laura Inozemtseva, and Reid Holmes. 2014. Live API Documentation. In Proceedings of the 36th International Conference on Software Engineering (Hyderabad, India) (ICSE '14). ACM, 643--652.
[36]
Suresh Thummalapenta and Tao Xie. 2009. Mining Exception-Handling Rules as Sequence Association Rules. In Proceedings of the 31st International Conference on Software Engineering (ICSE '09). IEEE Computer Society, USA, 496--506.
[37]
Transformers Interpret [n. d.]. Transformers Interpret. https://github.com/cdpierse/transformers-interpret.
[38]
Christoph Treude and Martin P. Robillard. 2016. Augmenting API Documentation with Insights from Stack Overflow. In Proceedings of the 38th International Conference on Software Engineering (Austin, Texas) (ICSE '16). ACM Press, 392--403.
[39]
Qian Wu, Guangtai Liang, Qianxiang Wang, Tao Xie, and Hong Mei. 2011. Iterative Mining of Resource-releasing Specifications. In Proceedings of the 26th IEEE/ACM International Conference on Automated Software Engineering (ASE '11). IEEE Computer Society Press, 233--242.
[40]
Feifei Zhai, Saloni Potdar, Bing Xiang, and Bowen Zhou. 2017. Neural Models for Sequence Chunking. In Proceedings of the Thirty-First AAAI Conference on Artificial Intelligence (San Francisco, California, USA) (AAAI'17). AAAI Press, 3365--3371.
[41]
Tianyi Zhang, Di Yang, Crista Lopes, and Miryung Kim. 2019. Analyzing and Supporting Adaptation of Online Code Examples. In Proceedings of the 41st International Conference on Software Engineering (ICSE '19). IEEE Press, 316--327.
[42]
Hao Zhong. 2023. Which Exception Shall We Throw?. In Proceedings of the 37th IEEE/ACM International Conference on Automated Software Engineering (ASE '22). Association for Computing Machinery, New York, NY, USA, Article 116, 12 pages.
[43]
Hao Zhong and Hong Mei. 2018. Mining Repair Model for Exception-related Bug. Journal of Systems and Software 141 (2018), 16--31.
[44]
Yu Zhou, Ruihang Gu, Taolue Chen, Zhiqiu Huang, Sebastiano Panichella, and Harald Gall. 2017. Analyzing APIs Documentation and Code to Detect Directive Defects. In Proceedings of the 39th IEEE/ACM International Conference on Software Engineering (ICSE '17). IEEE Computer Society Press, 27--37.

Cited By

View all
  • (2024)iSMELL: Assembling LLMs with Expert Toolsets for Code Smell Detection and RefactoringProceedings of the 39th IEEE/ACM International Conference on Automated Software Engineering10.1145/3691620.3695508(1345-1357)Online publication date: 27-Oct-2024

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image ACM Conferences
ICSE '24: Proceedings of the IEEE/ACM 46th International Conference on Software Engineering
May 2024
2942 pages
ISBN:9798400702174
DOI:10.1145/3597503
This work is licensed under a Creative Commons Attribution International 4.0 License.

Sponsors

In-Cooperation

  • Faculty of Engineering of University of Porto

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 12 April 2024

Check for updates

Author Tags

  1. AI4SE
  2. large language models
  3. automated exception handling

Qualifiers

  • Research-article

Funding Sources

Conference

ICSE '24
Sponsor:

Acceptance Rates

Overall Acceptance Rate 248 of 1,701 submissions, 15%

Upcoming Conference

ICSE 2025

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)345
  • Downloads (Last 6 weeks)52
Reflects downloads up to 13 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2024)iSMELL: Assembling LLMs with Expert Toolsets for Code Smell Detection and RefactoringProceedings of the 39th IEEE/ACM International Conference on Automated Software Engineering10.1145/3691620.3695508(1345-1357)Online publication date: 27-Oct-2024

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media