Introduction
Software defect prediction is a critical component of the modern development lifecycle, aimed at identifying vulnerabilities before deployment. However, current deep learning approaches face two significant challenges. First is a lack of granularity: most tools provide only binary "bug or no bug" predictions at the method level, which offers limited guidance for remediation. Second is the "cold start" problem: new projects often lack sufficient labeled data for training, and transferring knowledge from established projects is difficult due to "domain shift"—variations in coding styles, libraries, and logic.
To address these gaps, this research introduces COPILOT, a framework that reformulates defect prediction as a multi-label classification task using fine-grained labels from the Common Weakness Enumeration (CWE). COPILOT leverages multi-source domain adaptation to facilitate effective knowledge transfer across disparate software projects.
Methodology: The COPILOT Framework
The COPILOT framework is designed to extract robust, transferable features through three primary components:
- Backbone Feature Extraction: The model utilizes CodeT5, a pre-trained Transformer specifically optimized for code understanding, to capture deep semantic representations of source code.
- Adversarial Domain Adaptation: To mitigate domain shift, COPILOT employs a Gradient Reversal Layer (GRL) and a domain discriminator. This adversarial setup forces the encoder to learn domain-invariant features—patterns that remain consistent across different software projects.
- Weighted Attention Mechanism (WMMD): Recognizing that not all source projects are equally relevant to a target project, the framework uses Weighted Maximum Mean Discrepancy (WMMD). This module calculates the distribution distance between the target and various source projects, assigning higher weights to more similar domains to prioritize relevant knowledge transfer.
Experimental Setup
The researchers evaluated COPILOT using a dataset of 8 real-world open-source Java projects from the NIST STONESOUP plan. These projects represent diverse functional domains, including search engines (Elasticsearch, Lucene), utility libraries (Apache POI), and game engines (CoffeeMUD). The dataset encompasses 44 distinct CWE categories, which were aggregated into six major types for comprehensive analysis, such as Input Validation, Code Injection, and Buffer Issues.
Results and Discussion
COPILOT was benchmarked against five state-of-the-art models, including specialized vulnerability detectors like $\mu$VulDeePecker and general domain adaptation frameworks like M3SDA.
- Performance Metrics: COPILOT achieved an average Accuracy of 0.947, significantly outperforming the best baseline (M3SDA) by 2.1% and the deep learning baseline ($\mu$VulDeePecker) by 23.6%. High scores in MCC (0.946) and Kappa (0.945) further demonstrate the model's reliability and consistency across imbalanced classes.
- Ablation Study: Removing either the adversarial training or the WMMD module resulted in a performance decline. This confirms that both domain-invariant feature learning and source-specific attention are vital for effective cross-project transfer.
Conclusion
COPILOT demonstrates that multi-source domain adaptation, combined with adversarial training and weighted attention, can effectively solve the cold-start problem in fine-grained defect prediction. Future work will focus on addressing class imbalance in rare CWE categories, extending support to additional programming languages like C++ and Python, and increasing localization granularity to the statement or token level.
Summary updated