Learning to Reduce False Positives in Analytic Bug Detectors

Anant Kharkar, Roshanak Zilouchian Moghaddam, Matthew Jin, Xiaoyu Liu, Xin Shi, Colin B. Clement, Neel Sundaresan · DOI

Abstract

Static analysis tools are essential for identifying software vulnerabilities but often suffer from high false positive rates, causing "alert fatigue" among developers. This research investigates the use of Transformer-based models as post-processor filters to validate bug reports from the Infer static analyzer. By employing both supervised fine-tuning and a novel zero-shot generative approach, the authors demonstrate significant precision improvements for null dereference warnings across multiple open-source and proprietary projects.

Introduction

Static analysis tools like Facebook’s Infer are critical for modern software development, yet they face a fundamental trade-off between recall and precision. To ensure no critical bugs are missed, these tools frequently report "potential" issues that are not actual errors. High false positive rates—often exceeding 50%—lead to developer frustration and the eventual abandonment of the tools. Traditional refinement of analysis rules is manually intensive and difficult to scale. This paper proposes using Large Language Models (LLMs) to "double-check" static analysis reports by recognizing coding patterns and idioms that rule-based engines might miss.

Methodology

The researchers evaluated three distinct filtering approaches:

  1. Feature-Based Model: A baseline logistic regression classifier utilizing handcrafted features, such as the proximity of null-check methods or variable scope.
  2. DeepInferEnhance (Supervised): An encoder-only Transformer based on CodeBERTa. It was pretrained on 2 million Java and C# functions and fine-tuned on a manually labeled dataset of true and false positive bug reports.
  3. GPT-C (Zero-Shot): A generative approach using a model similar to GPT-2. Instead of direct classification, the model is prompted at the site of a reported bug (e.g., a Null Dereference). If the model predicts a safety check (like if (x == null)) as the most likely next line, it serves as a signal that the warning is legitimate. This method leverages the model's inherent knowledge of coding conventions without requiring labeled training data.

To improve accuracy, the models were provided with non-local context, such as the body of a called function, allowing them to verify if a return value could indeed be null.

Experimental Setup

The study utilized a dataset of 539 null dereference warnings generated by Infer across seven Java repositories, including open-source projects (Ambry, Azure SDK, Nacos, Playwright) and two proprietary Microsoft projects.

Summary of the null dereference warning dataset across seven projects.

Each warning was manually labeled by developers to establish a ground truth. Additionally, 108 resource leak warnings were collected to test the generalizability of the proposed methods.

Results and Discussion

The experimental results demonstrate that ML-based filtering significantly enhances the precision of static analysis.

Performance comparison of different filtering approaches on null dereference warnings.

Key Findings

  • Precision vs. Recall: The GPT-C (Zero-Shot) model achieved the highest precision, reaching 85.4% (a 17.5% relative improvement over the baseline). However, the supervised DeepInferEnhance model maintained better recall (88.3%), suggesting it is more conservative in filtering out potential bugs.
  • Generative Validation: Using code completion as a proxy for bug validation proved highly effective. The model's ability to recognize that a safety check "belongs" in a specific context provides a robust signal for the static analyzer.
  • Generalizability: The GPT-C model showed immediate utility on different bug types, such as resource leaks, improving precision by 5.5% without any retraining.

Conclusion

This work highlights the potential of augmenting rule-based static analyzers with machine learning. By using ML for pattern recognition and rule-based engines for logical analysis, developers can significantly reduce false positives. Future research will focus on expanding context windows to handle complex call chains and improving prompting techniques to further reduce the reliance on labeled data.

Summary updated

BibTeX
@inproceedings{kharkar2022learning,
  author = {Anant Kharkar and Roshanak Zilouchian Moghaddam and Matthew Jin and Xiaoyu Liu and Xin Shi and Colin B. Clement and Neel Sundaresan},
  title = {{Learning to Reduce False Positives in Analytic Bug Detectors}},
  booktitle = {ICSE},
  year = {2022},
  doi = {10.1145/3510003.3510153},
}
Figure