Using Graph Neural Network to Analyse and Detect Annotation Misuse in Java Code
Jingbo Yang,Xin Ji,Wenjun Wu,Jian Ren,Kui Zhang,Wenya Zhang,Qingliang Wang,Tingting Dong
DOI: https://doi.org/10.1007/978-981-97-5663-6_11
2024-01-01
Abstract:Annotations have been widely applied in Java projects to support agile development, expecially in software enterprises. Developers make full use of annotations to conveniently implement special functions such as creating objects, operating database and providing URL links for network requests and so on. However, analyzing the usage of annotations in Java code data is not easy for developers, and the misuse of annotations can sometimes cause serious problems for their Java programs. Traditional statistic analysis method usually relies on the frequency of code and may not perform well in low frequent data. In this paper, we focus on leveraging graph neural network (GNN) to analyse and grasp Java annotation usage knowledge and detect misused annotations. Firstly, to better represent the project structure and the annotation usage knowledge, a novel annotation usage project structure graph (AUPSG) is designed. Secondly, using AUPSG, a structure-aware GNN based model is proposed to analyze and acquire knowledge of annotation usage during the training stage. This is achieved by categorizing code nodes at the class, method, field, and parameter levels into suitable annotations. With the learnt knowledge, the proposed model can more accurately detect annotation misuse. Finally, two annotation misuse datasets, each of which includes 150 independent Java projects/files, are curated to evaluate different annotation misuse detection methods. The performance evaluation results demonstrate that our method can achieve better performance than state-of-the-art baseline models in terms of precision, recall, and F1.