A Defect Detection Method Based on Code Defect Knowledge Graph
He Yang, Wei Le, Yumin Li · 2023
To address the limitations of existing code defect detection methods, which only analyze code defects from a single perspective and produce uninterpretable results, we introduce a new approach known as Defect Detection Method based on code defect knowledge Graph (DDMB). This method involves several steps. First, we clean and organize defect-related knowledge, defining concepts of defect entities, attributes, and relationships to establish a code defect knowledge graph. Next, using abstract syntax trees, we extract various information from the code, including control flow diagrams, control dependency graphs, data dependency graphs, program dependency graphs, and code attribute graphs, to capture relevant details about nodes and edges. Based on the structural and logical information represented by node-edge associations, we employ the Deepwalk algorithm to construct a directed graph of the code and generate random walk sequences. These sequences serve as a foundation for learning and vector representation. Finally, we compare the vector similarities between the generated representations and a candidate code list from the defect knowledge graph, which has undergone initial semantic threshold filtering. By querying the defect labels of the most similar code in the defect code knowledge graph, we determine whether the code under inspection contains defects. Experimental results reveal that DDMB improves defect detection accuracy by 2.02% compared to existing methods. Additionally, it enhances the interpretability and reliability of defect detection while facilitating multi-dimensional analysis of code defects, thus providing better support for practical applications.