Improving the detection of technical debt in Java source code with an enriched dataset

Nam Le Hai, Anh M. T. Bui, Phuong T. Nguyen, Davide Di Ruscio, Rick KazmanarXiv 2024 · OpenReview

TL;DR

This paper introduces TESORO, a novel dataset that links technical debt (TD) comments directly to their corresponding Java source code. By leveraging this enriched data, they demonstrate that incorporating source code significantly improves the accuracy of detecting TD, paving the way for more robust and context-aware TD identification tools.

What Problem Does This Paper Address?

Technical debt (TD) is a common issue in software development, representing the cost of choosing a quick-and-dirty solution over a better, more time-consuming one. Self-Admitted Technical Debts (SATDs), often documented in code comments, are a key indicator. However, existing methods for detecting SATDs primarily rely on analyzing these textual comments, often neglecting the rich context provided by the actual source code. This can lead to missed detections, especially when comments are outdated or inconsistent with the code. The authors aim to bridge this gap by developing methods and a dataset that integrate source code information for more accurate and comprehensive TD detection.

Methods

The authors propose a pipeline for creating their TESORO dataset, which involves:

  1. Data Collection: Utilizing "The Stack" dataset, a large collection of permissively licensed source code.
  2. Code Parsing: Employing a "Code Parser Tool" (leveraging Tree-sitter) to extract functions and comments from Java files.
  3. SATD Detection: Developing a binary classifier (based on RoBERTa) to identify comments likely containing TD.
  4. Sampling Strategy: Using an "uncertainty score" (entropy) to select challenging and informative comments for manual annotation, ensuring a high-quality dataset.
  5. Annotation Process: A team of seven computer science students manually labeled comments and their associated code snippets, categorizing TD into five types (design, defect, documentation, implementation, testing) or marking them as non-SATD.
  6. Dataset Creation: Two datasets were created: TESOROcode (focusing on TD within code functions, excluding comments) and TESOROcomment (linking SATD comments with their code context).

For evaluating their approach, they experimented with various pre-trained language models (PLMs), including encoder-based (e.g., BERT, RoBERTa, CodeBERT), encoder-decoder-based, and decoder-based (LLMs) architectures. They explored different integration techniques for combining comments and code, such as string concatenation (StrConcat) and a novel "Code Attention" (CodeAtt) mechanism.

Datasets

  • The Stack: Used as the primary source for raw Java source code.
  • Maldonado-62K: A benchmark dataset for SATD detection, reused to train an initial SATD classifier.
  • TESOROcode: A newly curated dataset containing Java functions labeled with technical debt types (design, implementation, defect, test), excluding comments. This dataset addresses the challenge of detecting TD directly within code.
  • TESOROcomment: A newly curated dataset that links SATD comments with their corresponding source code context. This dataset is designed to improve SATD detection by providing richer contextual information.

Key Insights and Ideas

  • Source Code is Crucial: The most significant insight is that incorporating source code context dramatically improves the accuracy of technical debt detection, often outperforming comment-only approaches. This suggests that TD is not solely a textual phenomenon but is deeply embedded in the code's structure and logic.
  • Beyond Comments: Relying solely on comments for TD detection creates a blind spot, as comments can be outdated or misleading. The TESORO datasets and methodology offer a path to overcome this limitation.
  • Context Matters: The study highlights that even a small amount of surrounding code (e.g., 2 lines) can significantly boost detection performance, aligning with human intuition. However, an ensemble approach combining various context scopes (from a few lines to the entire function) yields the best results.
  • Code-Based PLMs Shine: For detecting TD directly in source code, models pre-trained on code (e.g., DeepSeek-Coder, GraphCodeBERT) generally outperform those trained only on natural language.
  • TESORO's Value: The TESORO dataset, by linking comments to code, not only enhances existing SATD detection but also provides a foundation for new research into code-based TD detection.

Key Results

  • RQ1 (Source Code Inclusion): Incorporating source code context improved F1-scores for SATD detection across all evaluated models (RoBERTa, CodeBERT, UniXCoder, GraphCodeBERT). For example, CodeBERT achieved an F1-score of 76.55% when using comments plus code context, compared to 72.75% with comments alone. The StrConcat integration technique generally outperformed CodeAtt. An ensemble approach combining different code context lengths yielded the highest performance.
  • RQ2 (Code-Only Detection): When detecting TD solely from source code using TESOROcode, DeepSeek-Coder achieved the highest F1-score of 46.19%. However, performance for all models remained below 50%, indicating room for improvement. Encoder-based models offered a good balance of performance and parameter efficiency.
  • RQ3 (TESORO Contribution): Augmenting the Maldonado-62K dataset with TESOROcomment consistently improved SATD detection performance across all tasks (identification, classification, detection) for various PLMs. For instance, training with TESORO improved BERT's performance by 7.94% in SATD detection. CodeBERT and GraphCodeBERT showed superior performance across all scenarios.

Limitations and Future Work

  • Internal Validity: The authors acknowledge that the initial SATD classifier might produce false positives if not properly curated. They mitigated this by using a pre-existing, well-classified dataset (Maldonado-62K) and employing a rigorous manual evaluation process with double-checking by annotators.
  • External Validity: The current study focused on Java source code. While the approach is assumed to be generalizable to other programming languages, this has not been empirically validated. Future work is needed to confirm this generalizability.
  • Future Work: The authors suggest incorporating additional information like execution outputs, test coverage, and runtime metrics to further enhance TD detection accuracy. They also anticipate that Large Language Models (LLMs) hold significant potential for improved source code-based TD detection, though further refinement and empirical evidence are needed. The TESORO dataset is expected to catalyze future research in this domain.

Summary updated

Abstract

Technical debt (TD) describes the additional costs that emerge when developers have opted for a quick and easy solution to a problem, rather than a more effective and well-designed, but time-consuming approach. Self-Admitted Technical Debts (SATDs) are a specific type of technical debts that developers intentionally document and acknowledge, typically via textual comments. While these comments are a useful tool for identifying TD, most of the existing approaches focus on capturing tokens associated with various categories of TD, neglecting the rich information embedded within the source code. Recent research has focused on detecting SATDs by analyzing comments, and there has been little work dealing with TD contained in the source code. In this study, through the analysis of comments and their source code from 974 Java projects, we curated the first ever dataset of TD identified by code comments, coupled with its code. We found that including the classified code significantly improves the accuracy in predicting various types of technical debt. We believe that our dataset will catalyze future work in the domain, inspiring various research related to the recognition of technical debt; The proposed classifiers may serve as baselines for studies on the detection of TD.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
Maldonado-62K · test set; Tesoro added to training dataCodeBERT (Maldonado-62K + Tesoro training)F1-score63.70+6.2 vs baselineTechnical Debt Classification · split: test · cross-project · model=CodeBERT · classes=five TD categories · training-data=Maldonado-62K + Tesoro
Source quote
L625: CodeBERT │ 88.74 │ 90.06 ({\color{darkgreen} \uparrow1.49%}) │ 57.50 │ 63.70 ({\color{darkgreen} \uparrow10.78%}) │ 53.79 │ 55.60 ({\color{darkgreen} \uparrow3.36%})
Reported baseline / comparator measurements (1)
BenchmarkMethodMetricScoreProtocol / Evidence
Maldonado-62KCodeBERT (Maldonado-62K training only) baselineF1-score57.50Technical Debt Classification · split: test · cross-project · model=CodeBERT · classes=five TD categories · training-data=Maldonado-62K
Source quote
L625: CodeBERT │ 88.74 │ 90.06 ({\color{darkgreen} \uparrow1.49%}) │ 57.50 │ 63.70 ({\color{darkgreen} \uparrow10.78%}) │ 53.79 │ 55.60 ({\color{darkgreen} \uparrow3.36%})
BibTeX
@misc{hai2024improving,
  author = {Nam Le Hai and Anh M. T. Bui and Phuong T. Nguyen and Davide Di Ruscio and Rick Kazman},
  title = {{Improving the detection of technical debt in Java source code with an enriched dataset}},
  year = {2024},
  eprint = {2411.05457},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.05457},
}
Figure